The output of function hour(now()) is not the hour of now() but the hour of gmt. Is this right?

Certified Associate Developer

Hello,

If the function hour(now()) is used, the output value is the "gmt hour" instead of now() time.

Is this right? 

Then do I have to adjust the hour time by adding or subtracting time to make it match with my timezone?

https://docs.appian.com/suite/help/22.1/fnc_date_and_time_hour.html

Thank you.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Instead of adding or subtracting anything, you should be able to simply use the local() function.  This transforms the timestamp value in such a way that the time value (when extracted like with hour()) will reflect your local time zone's value instead of the GMT value.  It's confusing but it works.

    And of course as Stefan already mentioned, we can probably provide better help if you actually explain your use case somewhat.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Thank you all.

    I have solved the problem by using the local() function like hour(local(now(), "ROK")) .

    For example, I made an expression rule.

    When a specific task is currently performed, I want to delay until 12:00 AM the next day based on the current time.

    ( want the result to be like :  #/0#/2022 12:00 AM GMT+09:00 )

    In this case, if hour(now()) is used, only gmt time is subtracted.

    To calculate the time according to the timezone, I had to subtract 9 in addition.

    //------------------------------------------

    = now() + intervalds(
    23 - 9 - hour(now()),
    59 - minute(now()),
    60 - second(now())
    )

    //------------------------------------------

  • 0
    Certified Lead Developer
    in reply to dreamyoung

    Thanks for sharing your use case.  This is a good example of why that's important: in your case, it's probably better to have your expression rule just create the timestamp for the delay timer to fire, rather than doing all that math on the current time.  That's what I've been able to do in the past while creating a rule that does essentially the same thing, i.e. "set expiration time to 2 AM the next morning".  I'll see if I can find my old expression rule code for this and share it here.

    Edit: I was able to find what I had done before and it's fairly simple - basically just manually creating the timestamp like I said before; also I have it set up so that any time can be passed in as the "current" / "starting" time (allowing for better use case testing), and local variables abstract a lot of the initial functionality just for the sake of ease of understanding.

    a!localVariables(
      local!baseTime: a!defaultValue(ri!referenceTime, now()),
      
      local!newYear: year(local(local!baseTime) + 1), /* in case this rule is run on the last day of a year */
      local!newMonth: Month(local(local!baseTime) + 1), /* in case this rule is run on the last day of a month */
      local!newDay: Day(local(local!baseTime) + 1),
      
      local!targetHour: 00,
      local!targetMinute: 00,
      local!targetSecond: 01,
    
      
      userdatetime(
        local!newYear,
        local!newMonth,
        local!newDay,
        
        local!targetHour,
        local!targetMinute,
        local!targetSecond
      )
    )

    This example would return a value of 12:00:01 AM (12 am and 1 second) of the next day, in the user's local time.  I personally usually set it up to fire at something more like 2 AM, just to avoid other things that fire off at exactly midnight (causing a spike of traffic on the environment around then), but that's up to you.

Reply Children
No Data