datetimetimezonedataweavemulesoftcloudhub

Getting user timezone on an api deployed to Cloudhub


I'm trying to dynamically get the user timezone and apply it to the dateTime values in my payload.

I'm currently using this function in dataweave:

var dateTimeZone = now() as TimeZone

fun formatDate(dtValue :String, dateTimeZone: TimeZone) : DateTime =  
  dtValue as DateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"} as DateTime {"format" : "dd/MM/yyyy HH:mm", timezone: dateTimeZone}

When I run this code locally it works as expected. When I deploy my API to CloudHub I found out it uses UTC (which I suppose is the server's timezone)

I however need to get the user timezone wherever they are, so if the user is in California for example I need it to format it to "PST".

Is there a workaround to this problem that I can implement in code without adding query parameters or changing anything but this function?


Solution

  • Timezone of the client of an API is not something your API implementation knows, whatever the technology. You need to receive it from the request, as a query parameter or from a the body of the request.