Git Product home page Git Product logo

vba-utc's Introduction

VBA-UTC

UTC and ISO 8601 date conversion and parsing for VBA (Windows and Mac Excel, Access, and other Office applications).

Tested in Excel 2016 for Windows and Mac, but should apply to Windows Excel 2007+.

Donate

Example

' Timezone: EST (UTC-5:00), DST: True (+1:00) -> UTC-4:00
Dim LocalDate As Date
Dim UtcDate As Date
Dim Iso As String

LocalDate = DateValue("Jan. 2, 2003") + TimeValue("4:05:06 PM")
UtcDate = UtcConverter.ConvertToUtc(LocalDate)

Debug.Print VBA.Format$(UtcDate, "yyyy-mm-ddTHH:mm:ss.000Z")
' -> "2003-01-02T20:05:06.000Z"

Iso = UtcConverter.ConvertToIso(LocalDate)
Debug.Print Iso
' -> "2003-01-02T20:05:06.000Z"

LocalDate = UtcConverter.ParseUtc(UtcDate)
LocalDate = UtcConverter.ParseIso(Iso)

Debug.Print VBA.Format$(LocalDate, "m/d/yyyy h:mm:ss AM/PM")
' -> "1/2/2003 4:05:06 PM"

vba-utc's People

Contributors

timhall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vba-utc's Issues

Error when parsing iso with non period decimal separator

When parsing on a system where the decimal separator is not a period, the ParseIso method fails.

need to modify (for example) :
VBA.CInt(utc_TimeParts(2))
to:
VBA.CInt(Strings.Replace(utc_TimeParts(2), ".", Strings.Mid(Strings.Format(1.1, "#.#"), 2, 1)))

Formatting with \

I am having issue with VBA.Format$ - this could be related to my regional settings (finnish)

For some reason function ConvertToIso(utc_LocalDate As Date) As String with parameter "27.4.2020 17.00.00":
VBA.Format$(ConvertToUtc(utc_LocalDate), "yyyy-mm-ddTHH:mm:ss.000Z")
->converts to "2020-04-27T14.00.00.000Z" (not correct)
If I modify it to
VBA.Format$(ConvertToUtc(utc_LocalDate), "yyyy-mm-ddTHH:mm:ss.000Z")
->converts to "2020-04-27T14:00.00.000Z" (not correct but one . is : as it shuold be)
So correct one would be:
VBA.Format$(ConvertToUtc(utc_LocalDate), "yyyy-mm-ddTHH:mm:ss.000Z")

See at bottom for ():
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/format-function-visual-basic-for-applications

ParseIso fails if region settings have date order of DD/MM/YYYY

Sorry: had to edit this a lot as I had the wrong cause orginally.

The ParseIso method gets the wrong date if there is no : between the hours and minutes in the timezone

e.g. ParseIso("2024-03-11T17:40:00.000+0800") gives 07/02/2024 09:00:40

ParseIso("2024-03-11T17:40:00.000+08:00") gives the correct value 11/03/2024 09:40:00

Issue parsing ISO date strings with offsets

From VBA-tools/VBA-Web#233

The ParseIso() function in the WebHelpers module doesn't seem to handle offsets correctly.

JSON ISO String with 0 offset: "2016-06-01T01:08:20.9333502+00:00" Is not treated as being UTC and doesn't get the local timezone added to it... It simply gets shown as is.

JSON ISO String with 12 hour offset:"2016-06-01T13:08:20.9333502+12:00" Gets its 12 hour offset added to it again which sets it 12 hours into the future...

Correct me if I'm wrong here but I believe that with ISO 8601 the offset specifies how far away the stated date/time is from UTC.

So to get the second example's JSON ISO String in your local time you would first subtract 12 hours to get it to a UTC time and then add your local timezone offset to get it in local time.

Add: Issue parsing ISO date strings with offsets

Problem still seems not solved.
I corrected it by using:
ParseIso = ParseIso - utc_Offset
instead of
ParseIso = ParseIso + utc_Offset

2017-12-29T23:12:48.813+01:00 should be 2017-12-29 23:12:48 in my timezone +01:00 Vienna.
The Offset is not added - it must be inverted (as i saw on wiki).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.