Ideally we could specify that the Timezone either should be chosen automatically (use our current Timezone), or else specify a Timezone/offset that should be used for the conversion.
I guess the answer to my need is to use a formula to format the DateTime on the backend, which should allow me to convert it to a specific (constant) TImeZone. The only complication is keeping track of the current state of Daylight Savings Time.
It is becoming increasingly frustrating not being able to programmatically expose dates in the correct time zone or have a date field that knows and remembers what time zone an entry was made in. I canāt find a good way to create emails through automations that will always display the correct time of an event to a user. I also canāt be bothered to switch a formula date field to accommodate the daylight savings transition, not to mention that would incorrectly display the time of all events that were in the previous daylight savings period.
I know there are always priorities but making time a first-class citizen (12-hour time and time zones) in Fibery may help increase your user base in countries that come to expect this being a built-in feature of almost any platform that deals with date/times.
Not being able to display correct dates and times in automation emails and elsewhere is pushing me back to other products. Not that Iām a paying customer, but Iād really like to be some day!
It doesnāt make sense to implement any of this in Fibery unless it is done thoughtfully and thoroughly, which means being able to expose all assumptions and specify all conversion parameters.
Meanwhile, you can probably do what you need for a particular case with javascriptās built in Date functions. But youāll need to be careful with how the problem is defined - there are lots of gotchaās with Date/time processing (like, as you mentioned, Daylight Savings Time).
So you might want to, for example: take a Fibery DateTime field value and localize it to a particular timezone. Specifying a Timezone to use for such a conversion is not as simple as youād think; you might have to use official names like America/New_York instead of familiar ones like EST.
Itās also a good idea when rendering a localized time to include the Time zone name in the output, to avoid confusion.
If you can define your need rigorously I can probably provide an example script.
I decided to use timeapi.io to get the local time for the date of the event, and then take that and make it a text field with the date and time like this ā02/22/2023 @ 6:00pm MSTā that I can use in templates. If the event date gets updated, the script runs again to update the text field.
Iām sure itās one of many ways to solve it, but I thought it made sense for this application.
For anyone interested here is the script. I take the resulting DateTZ, HourTZ, MinuteTZ, and DST fields and concatenate them in a formula field to look like this: 02/17/2023 @ 6:00pm MST. This is hard coded to convert from UTC to America/Denver.
// Fibery API and HTTP services
const fibery = context.getService('fibery');
const http = context.getService('http');
for (const entity of args.currentEntities) {
//Use timeapi.io to convert from UTC to your local timezone
const timecall = await http.postAsync('https://www.timeapi.io/api/Conversion/ConvertTimeZone', {
headers: {
'Content-type': 'application/json'
},
body: {
fromTimeZone: "UTC",
dateTime: entity['Start Date UTC'],
toTimeZone: "America/Denver",
dstAmbiguity: ""
},
});
const result = JSON.parse(timecall)
// console.log(dmresult);
//Convert 0 to 00 when minute is 0
let min; switch (result.conversionResult.minute) { case 0: min = "00"; break; default: min = result.conversionResult.minute; };
//Determine if DST is active and set MST/MDT accordingly
let dst; switch (result.conversionResult.dstActive) { case false: dst = "MST"; break; default: dst = "MDT"; };
//Update fields in entity
await fibery.updateEntity("Event Management/Events", entity['ID'], { "MinuteTZ": min });
await fibery.updateEntity("Event Management/Events", entity['ID'], { "HourTZ": result.conversionResult.hour });
await fibery.updateEntity("Event Management/Events", entity['ID'], { "DateTZ": result.conversionResult.date });
await fibery.updateEntity("Event Management/Events", entity['ID'], { "DST": dst });
}
Thank you, that worked! I had to slice 5 characters from the end and replace the āTā with " " for timeapi.io to accept it, but Iām guessing that is on their end.
I made a few changes and utilized timeapi.ioās translate feature that will send it back in a more readable format. It reduced the number of fields and formulas, so I went with it.
// Fibery API and HTTP services
const fibery = context.getService('fibery');
const http = context.getService('http');
for (const entity of args.currentEntities) {
//Use timeapi.io to convert from UTC to your local timezone
const timecall = await http.postAsync('https://www.timeapi.io/api/Conversion/ConvertTimeZone', {
headers: {
'Content-type': 'application/json'
},
body: {
fromTimeZone: "UTC",
dateTime: String(entity['Date Range'].Start).slice(0, -5).replace("T", " "),
toTimeZone: "America/Denver",
dstAmbiguity: ""
},
});
const result = JSON.parse(timecall)
console.log(timecall, result);
//Use timeapi.io to convert to more readable date
const startdate = await http.postAsync('https://www.timeapi.io/api/Conversion/Translate', {
headers: {
'Content-type': 'application/json'
},
body: {
dateTime: result.conversionResult.dateTime.replace("T", " "),
languageCode: "en"
},
});
const startdatetz = JSON.parse(startdate)
//Update event StartDateTZ field with new date and strip seconds off
await fibery.updateEntity("Event Management/Events", entity['ID'], { "StartDateTZ": String(startdatetz.friendlyDateTime).replace(":00 ", " ") });
}