The ability to accurately convert timestamps to the user's local time zone can greatly improve the usability and accessibility of many applications.
This transformation can be used to convert an ISO 8601 timestamp to a user's local date and time based on their time zone.
Purpose
Suppose you are building a social media platform that allows users to schedule posts to be published at a specific date and time. You want to display the scheduled post times in the user's local timezone so they can better manage their content. By using this transformation, you can convert the UTC timestamp of each scheduled post to the local date and time of the user, based on their timezone and locale settings. This makes it easier for users to schedule and manage their posts, and saves time and effort by avoiding having to manually convert the timestamp from Zulu time to the client's local time at the destination.
Example
George is a small business owner who uses Rudderstack to manage his social media accounts. Since his audience is spread across different time zones, George wants to publish posts at the optimal time for each audience. He plans to schedule two posts to be published at 9am local time in Italy (8 am UTC) and America (2 pm UTC).
Using this transformation, he can easily identify the correct time at which to publish his posts without performing any conversion on the destination and automating the process.
Approach
The function first extracts the event's timezone, original timestamp, and locale:
Then, it converts the original timestamp to a string in the user's local date and time format, based on their time zone and locale. The resulting local date and time string is then added to the event object as a new property, localTimestamp.
Besides, it offers great flexibility in representing the local date and time format:
The format of the produced date will depend on the locale value passed: for example, if "it-IT" is passed instead of "en-US", the format of the produced date will be different, as the Italian language has different names for months and days of the week than English. Therefore, if the function is called with event.context.locale set to it-IT, for example, the month name "January" will be translated to "Gennaio", while the day of the week name "Tuesday" will be translated to "Martedì"
The options constant can be modified to meet specific needs, allowing for a more personalized and accurate representation of the date and time for each user based on their specific time zone.
For example, considering the following input data:
Contact Details
p.giannone36@gmail.com
Language
Javascript
Category
Data Processing and Enrichment
Description
The ability to accurately convert timestamps to the user's local time zone can greatly improve the usability and accessibility of many applications. This transformation can be used to convert an ISO 8601 timestamp to a user's local date and time based on their time zone.
Purpose
Suppose you are building a social media platform that allows users to schedule posts to be published at a specific date and time. You want to display the scheduled post times in the user's local timezone so they can better manage their content. By using this transformation, you can convert the UTC timestamp of each scheduled post to the local date and time of the user, based on their timezone and locale settings. This makes it easier for users to schedule and manage their posts, and saves time and effort by avoiding having to manually convert the timestamp from Zulu time to the client's local time at the destination.
Example
George is a small business owner who uses Rudderstack to manage his social media accounts. Since his audience is spread across different time zones, George wants to publish posts at the optimal time for each audience. He plans to schedule two posts to be published at 9am local time in Italy (8 am UTC) and America (2 pm UTC). Using this transformation, he can easily identify the correct time at which to publish his posts without performing any conversion on the destination and automating the process.
Approach
The function first extracts the event's timezone, original timestamp, and locale:
Then, it converts the original timestamp to a string in the user's local date and time format, based on their time zone and locale. The resulting local date and time string is then added to the event object as a new property,
localTimestamp
.Besides, it offers great flexibility in representing the local date and time format:
The format of the produced date will depend on the locale value passed: for example, if "it-IT" is passed instead of "en-US", the format of the produced date will be different, as the Italian language has different names for months and days of the week than English. Therefore, if the function is called with
event.context.locale
set toit-IT
, for example, the month name "January" will be translated to "Gennaio", while the day of the week name "Tuesday" will be translated to "Martedì"The options constant can be modified to meet specific needs, allowing for a more personalized and accurate representation of the date and time for each user based on their specific time zone. For example, considering the following input data:
const options = { weekday: "long", year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit" }
const options = { year: "2-digit", month: "2-digit", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric" }
const options = { hour12: false, year: "2-digit", month: "2-digit", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric", timeZoneName: "long" }
const options = { hour12: true, dateStyle: "full", timeStyle: "full"}
const options = { hour12: true, year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric", timeZoneName: "short" }
const options = { year: "numeric", month: "2-digit", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric" }
Code Block
Input Payload for testing
License