Allow specifying TimeZone with ToText([Date])

The documentation for ToTtext() does not mention what Timezone is used when converting a Date to Text.

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.

Weā€™re actually just about to post a help page explaining about how timezones work in Fiberyā€¦keep your eyes peeled :slight_smile:

TLDR: everything is stored internally in UTC.

2 Likes
1 Like

Thanks for the docs - very helpful!

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.

Could we maybe get a Fibery extension to interface with this service, or something similar?
http://worldclockapi.com/

1 Like

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!

As always, thanks for listening!

1 Like

Dates are hard.

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 certainly wasnā€™t implying that dates arenā€™t hard. Could we just be rid of DST and am/pm to take a couple of the complications out of this? :smiley:

Iā€™ll detail my needs and get back to you. Hoping it is simpler than how I see it currently. I appreciate the offer!

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 });
}

Thanks again.

1 Like

Also, I canā€™t get entity[Date Range.Start()] or entity[Date Range.Start] to work in a script. Do you have the secret to that?

1 Like

I think you should be using

entity[ā€˜Date Rangeā€™].Start

assuming your field is called Date Range

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 ", " ") });
}

And the outputā€¦

1 Like