Working with Time in Appian

This is what the GPT chatbot thinks about time in software applications:

Ticking clock ticks on,

Code lines flow, time passes by.

Virtual moments gone.

And an image generated in a Salvador Dali – Cyberpunk style:

I will probably leave the writing of poems and painting of pictures to the AIs.

I think that time in Appian is as simple as it gets. This includes time across timezones, process time and user-local time. Do not try to implement any time and timezone calculations yourself. Let’s explore this together.

Internal Time

Appian uses the UTC (Universal Time Coordinated aka. GMT – Greenwich Mean Time) timezone, exclusively for any time-based value outside a time context. When Appian talks to any external system, API or database, time values will be in the UTC timezone.

Time Context

In Appian, time is always evaluated in a context. This is a user context or a process context. When evaluating time, Appian converts the internal time (UTC) into the timezone derived from this context, like PST or EST.

User-Facing Time

Whenever any logic or expression is evaluated in the context of a user interface, Appian converts time values into the timezone as configured in the user’s settings. And it converts time values entered by the user back to the internal UTC representation.

Process Time

The timezone of a process is configured in process model properties on the General tab.

By default, process timezone is overridden by the timezone configured in the initiator’s user settings. This can be changed to a static timezone. Consider this for a process used across multiple timezones. Any logic or expression evaluated in process context like script tasks, uses this context.

External Time

This is simple, Appian will always talk in the UTC timezone to the outside world. You might have to translate time values from or to a different timezone for external systems not using UTC.

Use the function gmt() to convert a time value into the UTC timezone, and then the local() function to convert it into the target timezone.

local(gmt(datetime(2023, 2, 2, 16, 8)), "PST")

Creating new Time Values

So, this was pretty simple, but there is one tricky spot in Appian which you need to know of. In a situation where you create a new time value, you need to decide whether you want that to evaluate in UTC or timezone context. There are two functions to choose from. Check my example below, tested in the expression editor.

/* Evaluated at February 2nd, 16:08 EST */
{
  /*
    1)
    This ignores my timezone, but then Appian adds my timezone offset as the value goes through the code that displays the test results.
  */
  datetime(2023, 2, 2, 16, 8),

  /*
    2)
    This respects my timezone and does not add it.
  */
  userdatetime(2023, 2, 2, 16, 8)
}

1)
  2/2/2023 5:08 PM GMT+01:00
2)
  2/2/2023 4:08 PM GMT+01:00

So, keep that in mind when creating new time-based values.

Expression Editor

There is one seemingly weird behaviour in the expression editor that might make you lose your mind. Any time value created by your expression is translated into your timezone when displayed in the test panel.

Durations

We have two types of time. I covered points in time above, but we still have to talk about durations. In general, a duration is a difference between two points is time, and Appian has a dedicated data type to store durations, called interval. You can create these using the intervalds() function, or by subtracting two time values. You can perform time-based calculations using a mix of times and intervals and the +, -, *, / operators.

now() + 5 * intervalds(3, 15, 42)

Printing an interval to screen, creates this format:

0::02:04:05.000

The values are

Days::hours:minutes:seconds.milliseconds

And before you ask, no, there is no elegant way to turn such a value into a pleasant form. You need to split it by the colon and format it yourself according to your requirements. This is a viable candidate for a reusable expression rule on an application level.

Time Values and Math

As I already mentioned, do not try to implement your own ways of calculating time values. Appian provides the two functions a!addDateTime() and a!subtractDateTime(). They perform the basic tasks, but can also use a process calendar to account for work times specified there.

Summary

I think that Appian implements a great way of handling time values. Most of the time <sic>, it will just work. When running into one of the above-mentioned scenarios, you are well-prepared now.

Thanks for taking your time 😉

One thought on “Working with Time in Appian

Leave a Reply