Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the time zone format omits a colon, ParseIso returns an incorrect result #8

Open
mattybrown1985 opened this issue Jun 20, 2023 · 1 comment

Comments

@mattybrown1985
Copy link

Input Output Expected Output
ParseIso("2022-11-29T14:52:41.689+01:00") 29/11/2022 13:52:41 29/11/2022 13:52:41
ParseIso("2022-11-29T14:52:41.689+0100") 25/11/2022 10:52:41 29/11/2022 13:52:41
@Nick-vanGemeren
Copy link

Since ParseIso does pattern matching on the cheap, it has several 'features' and bugs. One feature is that it only supports ISO8601 strings in 'extended format' (with all separators).

In this case, the offset is taken as 100 hours and so the output is the local time in zone UTC+1, 4 days 3 hours behind.

It's possible to support most of the various flavours of ISO 8601 strings using regular expressions, but this would be significant rewrite of ParseIso including a new library reference.

If you just want to support 'basic' offsets: in utcConverter or JsonConverter, find the ParseIso function. Change the last line of

                Select Case UBound(utc_OffsetParts)
                Case 0
                    utc_offset = TimeSerial(VBA.CInt(utc_OffsetParts(0)), 0, 0)

to

                    Dim OffsetHours As Long, OffsetMins As Long
                    Dim OffsetStr As String: OffsetStr = utc_OffsetParts(0)
                    If Len(OffsetStr) <= 2 Then OffsetStr = OffsetStr & "00"
                    OffsetMins = VBA.CInt(VBA.Right$(OffsetStr, 2))
                    OffsetHours = (VBA.CInt(OffsetStr) - OffsetMins) / 100
                    utc_Offset = TimeSerial(OffsetHours, OffsetMins, 0)

If this solves your problem, please close this issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants