Skip to content

ConvertToIso should have from/to timezone capability #169

Open
@mohawk2

Description

@mohawk2

Current signature:

Public Function ConvertToIso(utc_LocalDate As Date) As String

The behaviour currently treat the parameter as being in the "local" timezone, and without being asked, converts it to UTC and returns the ISO 8601 with "Z" timezone. This is because VBA "dates" are (in Python terminology) "timezone-naive".

Proposed new signature:

Public Function ConvertToIso(utc_LocalDate As Date, Optional fromTZhours As Variant = Empty, Optional toTZhours As Double = 0) As String

This would be backwards-compatible in preserving the old behaviour by default. It would make the passed-in date be "timezone-aware", but defaulting to local.

The local TZ would be detected with an "empty" fromTZhours (using IsEmpty()), and converting the input date into a real UTC one, effectively timezone-aware. The fromTZhours value would be either "empty" (local), or a Double of hours.

It would then be converted to one in the toTZhours, by multiplying that quantity by 60 and applying that as a DateDiff in minutes (which catches offsets with non-integer number of hours, which do exist). The timezone string would be calculated appropriately, with "Z" as a special case for 0.

@timhall Want me to make a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions