0

I am trying to convert a date in string format in UTC timezone into Australia/Sydney timezone. It seems to work for one value, but not the other, so I am a little confused

%dw 2.0
import * from dw::core::Strings
output application/json

var inputUtc1 = "2024-09-08T08:23:00Z"
var inputUtc2 = "2024-10-15T00:00:00Z"
fun format(d: DateTime) = d as String {format: "yyyy-MM-dd'T'HH:mm:ss"}
---
{
    "a1" : (format(inputUtc1) >> "Australia/Sydney") as String {format: 'yyyy-MM-dd\'T\'HH:mm:ss'},
    "a2" : (format(inputUtc2) >> "Australia/Sydney") as String {format: 'yyyy-MM-dd\'T\'HH:mm:ss'}
}

The output generated is:

{
  "a1": "2024-09-08T18:23:00",
  "a2": "2024-10-15T11:00:00"
}

The value against a1 seems to be correct, but it seems incorrect for a2 2024-10-15T00:00:00Z in UTC should convert into 2024-10-15T10:00:00

However it is converting it into 2024-10-15T11:00:00Z

I'm not sure why it works for one date and not the other? (I am trying this in playground.)

3
  • 2
    The value is correct, after 2024-10-05 16:00 UTC, DST is in effect for Australia/Sydney, so the offset on 2024-10-15 is 11 hours, not 10 hours. Commented Sep 11, 2024 at 10:30
  • 1
    Could the switch to DST at the beginning of October have any impact? Commented Sep 11, 2024 at 10:30
  • 1
    Unrelated to the problem, why are you converting to String before changing the timezone? use a datetime first. Commented Sep 11, 2024 at 12:13

1 Answer 1

1

The difference between the conversions is because the daylight savings change in Australia changes in October 6, 2024. Because the first date is before the change and the second date is after the change there is a one hour difference to be expected as normal behavior.

If you want to have a constant conversion you could use a fixed numeric timezone difference instead of the timezone of a location.

%dw 2.0
output application/json
---
{
    l1: |2024-09-08T08:23:00Z| >> "Australia/Sydney",
    l2: |2024-10-15T00:00:00Z| >> "Australia/Sydney",
    d1: |2024-09-08T08:23:00Z| >> "UTC+10",
    d2: |2024-10-15T00:00:00Z| >> "UTC+10"
}

Output

{
  "l1": "2024-09-08T18:23:00+10:00",
  "l2": "2024-10-15T11:00:00+11:00",
  "d1": "2024-09-08T18:23:00+10:00",
  "d2": "2024-10-15T10:00:00+10:00"
}

Unrelated to the issue, if you are going to do date time transformations is better to keep the type as date time instead of converting to String, to avoid doing extra implicit transformations. Example: "2024-09-08T08:23:00Z" as DateTime >> "Australia/Sydney" as String {format:...}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.