This transform rule is designed to parse an incoming date or date-time string and convert it to a specific timezone. It intelligently handles two primary input formats:
- A full ISO 8601 date-time string (e.g.,
2023-10-27T14:30:00Z). - A simple date string in
yyyy-MM-ddformat (e.g.,2023-10-27).
The target timezone and, for simple dates, the desired hour of the day can be specified in the transform's attributes. The output is always a standardized ISO 8601 date-time string that includes the correct timezone offset.
- Ensuring date attributes from an HR source (like
hireDateorendDate) are correctly localized for a target application that requires a specific timezone. - Standardizing various incoming date formats into a single, timezone-aware format for an identity attribute.
- Converting a simple date (e.g., a user's birthday) into a full date-time at the beginning of the day in their local timezone.
To use this rule, create a transform with the rule type and reference the rule by name. You can provide optional attributes to control the conversion.
{
"type": "rule",
"attributes": {
"name": "Datetime to Timezone",
"timezone": "America/New_York",
"localHourToSet": "8"
}
}name(Required): Must beDatetime to Timezone.timezone(Optional):- Description: The target timezone for the conversion. This should be a valid Olson Time Zone ID (e.g.,
America/Los_Angeles,Europe/London,Australia/Sydney). - Default: If omitted, empty, or invalid, the rule defaults to
UTC.
- Description: The target timezone for the conversion. This should be a valid Olson Time Zone ID (e.g.,
localHourToSet(Optional):- Description: An integer from
0to23representing the hour of the day. This attribute is only used when the input is a simple date (yyyy-MM-dd). It allows you to set a specific time on that date (e.g., the start of the business day). - Default: If omitted, empty, or invalid, the rule defaults to
0(the start of the day, i.e., midnight).
- Description: An integer from
The rule first checks the format of the input string to decide how to process it.
- The rule identifies this format by checking for the presence of a
Tseparator. - It parses the input string as a UTC-based
Instant. It is critical that the input date-time is in UTC or includes a UTC offset (Z or +/-hh:mm). - It converts this
Instantinto aZonedDateTimeusing the specifiedtimezoneattribute. - The
localHourToSetattribute is ignored in this case. - The final result is formatted as an ISO 8601 string with the target timezone's offset.
- If the input does not look like a full date-time, the rule attempts to parse it as a
LocalDate(yyyy-MM-dd). - It creates a
ZonedDateTimeby taking the parsed date, setting the time to the beginning of the day (atStartOfDay), and applying the specifiedtimezone. - It then adjusts the hour of this
ZonedDateTimebased on thelocalHourToSetattribute. - The final result is formatted as an ISO 8601 string with the target timezone's offset.
Convert a UTC timestamp from an HR system to the employee's local time in New York.
- Input Value:
"2024-09-01T04:00:00Z" - Transform Configuration:
{ "type": "rule", "attributes": { "name": "Datetime to Timezone", "timezone": "America/New_York" } } - Output Value:
"2024-09-01T00:00:00-04:00"(The date becomes midnight on Sep 1st in EDT)
Take a hireDate and represent it as the start of the day in the London timezone.
- Input Value:
"2024-10-28" - Transform Configuration:
{ "type": "rule", "attributes": { "name": "Datetime to Timezone", "timezone": "Europe/London" } } - Output Value:
"2024-10-28T00:00:00Z"(In late October, London is on GMT, which is UTC+0)
Take an endDate and set the deactivation time to 5 PM (17:00) in the US Pacific timezone.
- Input Value:
"2025-01-15" - Transform Configuration:
{ "type": "rule", "attributes": { "name": "Datetime to Timezone", "timezone": "America/Los_Angeles", "localHourToSet": "17" } } - Output Value:
"2025-01-15T17:00:00-08:00"(The time is set to 5 PM PST)
An incorrect timezone is provided, so the rule gracefully defaults to UTC.
- Input Value:
"2024-07-04T12:00:00Z" - Transform Configuration:
{ "type": "rule", "attributes": { "name": "Datetime to Timezone", "timezone": "America/NewYork" } } - Note:
America/NewYorkis invalid; it should beAmerica/New_York. - Output Value:
"2024-07-04T12:00:00Z"(The output remains in UTC)
- If the input value is
nullor an empty string, the transform will returnnull. - If the input string cannot be parsed as either a valid ISO 8601 date-time or a
yyyy-MM-dddate, the rule will log an error and returnnull. - The rule is defensive: invalid values for
timezoneorlocalHourToSetwill cause it to fall back to safe defaults (UTCand0, respectively) rather than failing the transform.