Skip to main content
March 29, 2024
Question

Need help in Date Time conversion along with timezone and matching for Validation in an Interface

  • March 29, 2024
  • 3 replies
  • 0 views

Hi Experts,

Need your help in the following issue:

Here is a validation for a Date and Time(captured in text) field along with the Timezone as shown below.

/*Code -- Test_Rule_Timezone*/
/*We are getting Date and Time and the Timzezone selected by the user from the dropdown*/
/*Based on the Timezone selection(cons!CDM2_VAL_STANDARD_TIMEZONE) we are subtracting the hours 
that is stored in the constant(cons!TEST_CONS_TIMEZONE) from the date and time selected by the user*/
a!localVariables(
  local!hours: a!match(
    value: ri!timezone,
    equals: cons!CDM2_VAL_STANDARD_TIMEZONE[1],
    then: cons!TEST_CONS_TIMEZONE[1],
    equals: cons!CDM2_VAL_STANDARD_TIMEZONE[2],
    then: cons!TEST_CONS_TIMEZONE[2],
    equals: cons!CDM2_VAL_STANDARD_TIMEZONE[3],
    then: cons!TEST_CONS_TIMEZONE[3],
    equals: cons!CDM2_VAL_STANDARD_TIMEZONE[4],
    then: cons!TEST_CONS_TIMEZONE[4],
    equals: cons!CDM2_VAL_STANDARD_TIMEZONE[5],
    then: cons!TEST_CONS_TIMEZONE[5],
    equals: cons!CDM2_VAL_STANDARD_TIMEZONE[6],
    then: cons!TEST_CONS_TIMEZONE[6],
    equals: cons!CDM2_VAL_DAYLIGHT_TIMEZONE_DISPLAY[1],
    then: cons!TEST_CONS_TIMEZONE[8],
    equals: cons!CDM2_VAL_DAYLIGHT_TIMEZONE_DISPLAY[2],
    then: cons!TEST_CONS_TIMEZONE[9],
    equals: cons!CDM2_VAL_DAYLIGHT_TIMEZONE_DISPLAY[3],
    then: cons!TEST_CONS_TIMEZONE[10],
    equals: cons!CDM2_VAL_DAYLIGHT_TIMEZONE_DISPLAY[4],
    then: cons!TEST_CONS_TIMEZONE[11],
    equals: cons!CDM2_VAL_DAYLIGHT_TIMEZONE_DISPLAY[5],
    then: cons!TEST_CONS_TIMEZONE[12],
    equals: cons!CDM2_VAL_DAYLIGHT_TIMEZONE_DISPLAY[6],
    then: cons!TEST_CONS_TIMEZONE[13],
    default: 0
  ),
  local!minutes: tointeger(index(split(local!hours,":"),2,0)),
  if(
    a!isNullOrEmpty(ri!dateTime),
    null(),
    a!subtractDateTime(ri!dateTime,0,0,0,local!hours,local!minutes)
    )
)

I need to validate that the Search Start Date + Search Start Time + Timezone -----should be less than the current system timezone,

Search End Date + Search End Time + Timezone -----should be less than the current system timezone.

Also Search Start Date + Search Start Time + Timezone(UTC)  <  Search End Date + Search End Time + Timezone(like UTC-7).

I am attaching the code for the same, need your help as I am not able to get the desired output.

Thank you in advance for your help!

3 replies

March 29, 2024

/*Code for the Validation*/

if(rule!Test_Rule_Timezone(timezone: fv!item.timeZone, dateTime: fv!item.startSearchDateTime) > rule!CDM2_DateTime_Converter(     date: todate(split(now()," ")[1]),     time: text(gmt(local(now(),"GMT")), "mm/dd/yyyy hh:mm:ss")   ),
                        "Please select a Date Time on or before current Date Time.",
                        if(
                          and(
                            a!isNotNullOrEmpty(fv!item.startSearchDate),
                            a!isNotNullOrEmpty(fv!item.endSearchDate),
                            rule!Test_Rule_Timezone(timezone: fv!item.timeZone, dateTime: fv!item.startSearchDateTime) > rule!Test_Rule_Timezone(timezone: fv!item.timeZone, dateTime: fv!item.endSearchDateTime)
                          ),
                          "'Search Start Date Time' can not be after 'Search End Date Time'",
                          {}
                        )
                        ), 

shubhama926776
March 30, 2024

[mention:07fecfc9ac2942fcb65d4ac2b18a0037:e9ed411860ed4f2ba0265705b8793d05] 
I would suggest you to convert date and time text to datetime type using below expression.

a!localVariables(
local!dateAndTime: split("2024-03-30 07:21:55", " "),
local!date: split(local!dateAndTime[1], "-"),
local!time: split(local!dateAndTime[2], ":"),
datetime(
local!date[1],
local!date[2],
local!date[3],
local!time[1],
local!time[2],
local!time[3]
)
)

Then output for this you can convert to user time zone and compare.

April 2, 2024

Thank you for the help [mention:dea33493db6342c9a73dc108d45120c0:e9ed411860ed4f2ba0265705b8793d05] , I convert date and time text to datetime type but still I am unable to achieve the desired output.

I need to validate that the Search Start Date Time + Timezone -----should be less than the current system timezone,

Search End Date Time + Timezone -----should be less than the current system timezone.

Also Search Start Date Time + Timezone selected  <  Search End Date Time + Timezone selected

Could you please help me verify my code:

if(
                          and(
                            a!isNotNullOrEmpty(fv!item.startSearchDateTime),
                            a!isNotNullOrEmpty(fv!item.timeZone)
                            a!isNotNullOrEmpty(fv!item.endTimeZone),
                            a!isNotNullOrEmpty(fv!item.endSearchDateTime),
                          ),                        
                          {
                            if(
                            gmt(
                              fv!item.startSearchDateTime,
                              fv!item.timeZone
                            )
                          > gmt(now()),
                          "Please select a Date Time on or before current Date Time.",
                          {}
                          ),
                           if(
                                gmt(
                                  fv!item.startSearchDateTime,
                                  fv!item.timeZone
                                )
                               > 
                                gmt(
                                  fv!item.endSearchDateTime,
                                  fv!item.endTimeZone
                                ),
                            "'Search Start Date Time' can not be after 'Search End Date Time'",
                            {}
                          )
                          },
                         {}
                        )