Neethu Raj
Neethu Raj

Reputation: 37

Dataweave date formatting to GMT timezone with daylight saving

I am trying to do date formatting with GMT timezone. But the offset is the same for summer and winter times. It works for CET timezone. Wondering why it is different for GMT?

Tried the following dataweave

Expecting

"GMT": 
    "date-GMT-Winter": "2019-12-15T13:00:00+00:00",
    "date-GMT-Summer": "2019-08-15T13:00:00+01:00"

But actual

"GMT": 
    "date-GMT-Winter": "2019-12-15T13:00:00Z",
    "date-GMT-Summer": "2019-08-15T13:00:00Z"
output application/json

var CET_timezone_winter = "2019-12-15T13:00:00" as DateTime >> "CET" as String {format: "xxx"}
var CET_timezone_summer = "2019-08-15T13:00:00" as DateTime >> "CET" as String {format: "xxx"}

var GMT_timezone_winter = "2019-12-15T13:00:00" as DateTime >> "GMT" as String {format: "xxx"}
var GMT_timezone_summer = "2019-08-15T13:00:00" as DateTime >> "GMT" as String {format: "xxx"}
---

{
 'date2': now(),
 "timeZoneOffset-xxx" : now() as String {format: "xxx"},


 'CET':
    {
    'date-CET-Winter': CET_timezone_winter,
    'date-CET-Summer': CET_timezone_summer
    },
'GMT':
    {
    'date-GMT-Winter': GMT_timezone_winter,
    'date-GMT-Summer': GMT_timezone_summer
    }
}

Upvotes: 0

Views: 3210

Answers (1)

Rafael Oltra
Rafael Oltra

Reputation: 1239

Day light savings does not apply to GMT (or UTC)

See https://www.timeanddate.com/time/gmt-utc-time.html

Neither UTC nor GMT ever change for Daylight Saving Time (DST). However, some of the countries that use GMT switch to different time zones during their DST period.

For example, the United Kingdom is not on GMT all year, it uses British Summer Time (BST), which is one hour ahead of GMT, during the summer months.

If you're trying to get UK/London time across the year (GMT and BST for DST) you can use the following Dataweave (I've added the new fields for comparison)

output application/json

var CET_timezone_winter = "2019-12-15T13:00:00" as DateTime >> "CET" as String {format: "xxx"}
var CET_timezone_summer = "2019-08-15T13:00:00" as DateTime >> "CET" as String {format: "xxx"}

var GMT_timezone_winter = "2019-12-15T13:00:00" as DateTime >> "GMT" as String {format: "xxx"}
var GMT_timezone_summer = "2019-08-15T13:00:00" as DateTime >> "GMT" as String {format: "xxx"}

var london_timezone_winter = "2019-12-15T13:00:00" as DateTime >> "Europe/London" as String {format: "xxx"}
var london_timezone_summer = "2019-08-15T13:00:00" as DateTime >> "Europe/London" as String {format: "xxx"}
---

{
 'date2': now(),
 "timeZoneOffset-xxx" : now() as String {format: "xxx"},


 'CET':
    {
    'date-CET-Winter': CET_timezone_winter,
    'date-CET-Summer': CET_timezone_summer
    },
'GMT':
    {
    'date-GMT-Winter': GMT_timezone_winter,
    'date-GMT-Summer': GMT_timezone_summer
    },
'London': {
    'date-London-Winter': london_timezone_winter,
    'data-London-Summer': london_timezone_summer

}   

}

output as JSON:

{
  "date2": "2019-09-24T15:25:17.574Z",
  "timeZoneOffset-xxx": "+00:00",
  "CET": {
    "date-CET-Winter": "2019-12-15T14:00:00+01:00",
    "date-CET-Summer": "2019-08-15T15:00:00+02:00"
  },
  "GMT": {
    "date-GMT-Winter": "2019-12-15T13:00:00Z",
    "date-GMT-Summer": "2019-08-15T13:00:00Z"
  },
  "London": {
    "date-London-Winter": "2019-12-15T13:00:00Z",
    "data-London-Summer": "2019-08-15T14:00:00+01:00"
  }
}

Upvotes: 5

Related Questions