Time services are used to enter parameters requiring time of day operations or to test for values relating to the current time. For example, a process flow can be configured to perform one operation on Friday and another operation on every other day.
Time services are provided by three functions that all provide formatted access to the current time. This section lists and describes the various time service functions that you can use in iWay Service Manager.
The _now() function returns the current time based on a provided pattern. It uses the following format:
_now([pattern])
pattern |
string |
Format pattern |
The default pattern (MM/dd/yyyy) returns the date in month/day/year format. So, for example, the date might return as 06/15/2006 if the function _now() is entered with no pattern.
Pattern characters can be assembled to provide the desired return. The following table lists the characters and the expected result. Characters are case-sensitive. All examples are based on a time of June 15, 2006 at 13:02:08 PM.
Character |
Use |
Return type |
Example |
---|---|---|---|
y |
year |
Digit |
yyyy=2006, yy=06 |
M |
Month of year |
Depends on length |
MM=06, MMM=Jun, MMMM=June |
w |
Week in year |
Digit |
26 |
W |
Week in month |
Digit |
2 |
D |
Day in year (Julian) |
Digit |
175 |
d |
Day in month |
Digit |
25 |
E |
Day of week |
Text |
Sun |
F |
Day of week in month |
Digit |
0 |
a |
Division of day |
Text |
pm |
H |
Hour (24 hr clock, 0-23) |
Digit |
12 |
h |
Hour (12 hr clock 1-12) |
Digit |
01 |
K |
Hour (24 hr clock, 1-24) |
Digit |
13 |
k |
Hour (12 hr clock, 0-11) |
Digit |
00 |
m |
Minute in hour |
Digit |
02 |
s |
Second in minute |
Digit |
08 |
S |
Milliseconds |
Digit |
HH:mm:ss.SSS |
z |
Time zone |
Text |
EDT. The local time zone. |
u |
Day number of week (1 = Monday, ..., 7 = Sunday) |
Number |
3 (Wednesday) |
Z |
RFC-822 time zone |
Number |
-0500 (EST) |
The function call must provide sufficient pattern characters to fill the field for those where length is specified. The following table provides a few examples:
cond(_now('E'),eqc,'Tue') |
Does work on Tuesday only. |
_now('hh:mm') |
The current time. For example, 3:37 is expressed as 03:37. |
_now('D') |
For example, for July 21, 2006, the day of year is 202. |
_now('dd/MM/yy') |
European date format. For example: 25/06/06 |
_now('z') |
EDT |
_now("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") |
RFC 3339 (ISO 8601) time. For example: 2012-02-23T11:41:34.793Z |
Note: Special characters can be included in the pattern by using an apostrophe (‘) character. To avoid compiler confusion, surround the pattern string using double quote (“) characters.
In releases running under Java Version 1.6, the pattern character 'u' was used by iWay for advanced timing capabilities, and will continue to provide that service. The special iWay pattern characters are now supported in the _timer() function.
The _timer() function returns time values based on the request. It uses the following format:
_timer(type)
The _timer() function replaces the use of the _now() function with special iWay-specific patterns.
type |
keyword |
Control |
The supported types are listed and described in the following table.
Keyword |
Use |
Example |
Note |
Alias* |
---|---|---|---|---|
seconds |
Unix epoch time in seconds. |
1377179943046 |
Accurate |
u |
milliseconds |
Unix epoch time in milliseconds. |
1377179943046678 |
Accurate |
U |
nanoseconds |
Unix epoch time in nanoseconds. |
1377179943046678945 |
To the best resolution available in the system clocks. This will depend on the hardware and JVM being used. |
Un |
If no type value is specified for the _timer() function, then the U (milliseconds) pattern character is used by default.
Note: Aliases are provided for the keywords, which reflect prior support for iWay pattern characters in the _now() function. iWay strongly discourages their use, and cannot guarantee that they will continue to be supported beyond iSM Version 7.0.
The pattern character ‘Un’ represents the best time available for the system at the nanosecond level. This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary. This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change.
The _tstamp() function returns a timestamp (accuracy to seconds) in ISO 8601 format.
This is a standard time function that is commonly used in many XML and web applications.
The _tstamp() function uses the following format:
_tstamp([locale])
locale |
Determines the time zone used for the returned timestamp, which can be set to one of the following values:
|
The _ftstamp() function returns a fine timestamp (accuracy to milliseconds) in ISO 8601 format. This function uses the following format:
_ftstamp([compression] [locale])
compression |
Determines the format of the returned timestamp, which can be set to one of the following values:
|
locale |
Determines the time zone used for the returned timestamp, which can be set to one of the following values:
|
For example:
_ftstamp() yields 2017-07-21T19:42:44:609Z
The special pattern of the word compressed eliminates the separator characters, yielding:
20170721194244609Z
The compressed option simplifies using the output in file names.
Users are cautioned that applications that employ local time may encounter issues across time zones or around time changes, such as daylight saving time (DST).
The _fmtdate() function formats a date according to a pattern when a date is provided in milliseconds since January 1, 1970, 00:00:00 GMT. It uses the following format:
_fmtdate(pattern,value [,language, [,country]])
pattern |
literal |
A type as described for the _timer() function. The specified type controls the formatting of the input value. |
value |
date/time |
A date/time in a format to be formatted based on the pattern. |
language |
literal |
The language code. By default, the language code is set according to the locale setting of the system where iSM is installed. |
country |
literal |
The country code. By default, the country code is set according to the locale setting of the system where iSM is installed. |
For example:
_fmtdate('yyyy.MM.dd', _dateof('MM/dd/yyyy','06/25/2009')) yields the following:
2009.06.25
It is sometimes desirable to obtain the date for some moment in relation to the current moment. For example, you may want the current date/time for a date one week in the past:
_fmtdate('yyyy/MM/dd hh:mm:ss',_imul(_isub(_timer(),_imul(86400,7)),1000))
Replace the 7 in this example with the number of days desired. 86400 is the number of seconds in a day.
For example, to return local time:
_fmtdate('dd-MMM-yyyy HH:mm:ss.SSS z',_timer(milliseconds))
The language argument is a valid ISO Language Code. These codes are the lowercase, two-letter codes as defined by ISO-639. You can find a full list of these codes at a number of websites, such as http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt.
The country argument is a valid ISO Country Code. These codes are the upper case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of websites, such as http://www.iso.org/iso/country_codes.htm.
The language and country codes affect the language of the result, not the time zone offset specified by the pattern. The country code is required only in cases in which the language code is ambiguous.
For example, one hour from this moment:
_fmtdate('EEE, dd-MMM-yyyy HH:mm:ss zzz', _iadd(_timer(),3600000), 'en')
yields the following:
Wed, 31-Dec-2012 19:04:00 EST
For example:
_fmtdate('EEE, dd-MMM-yyyy HH:mm:ss zzz', _iadd(_timer(),3600000), 'fr')
yields the following:
mer., 31-déc.-2012 19:04:00 EST
Note: Date operations can be performed by doing arithmetic on the values with appropriate patterns. The _timer() function returns the current time for this function.
The _dateof() function parses a date and returns the corresponding number of milliseconds since January 1, 1970, 00:00:00 GMT. It uses the following format:
dateof(pattern, value [,zone][,default])
pattern |
literal |
A type as described for the _timer() function. The specified type controls the formatting of the input value. |
value |
date/time |
A date and time in a format to be formatted based on the pattern. |
zone |
literal |
A time zone, such as Zulu. |
default |
string |
Value to be returned if the date and time value (operand 2) is not successfully parsed as a date. Failure to enter this operand will result in an error if a bad date value is detected. |
For example:
_dateof('MM/dd/yyyy', '06/25/2009') yields the following:
1245902400000
To create a duration suitable for date arithmetic, use the Zulu zone. This avoids any offset, so that a pattern, such as ss will give absolute seconds.
Note: The _iadd() and _isub() functions are preferred for date arithmetic because they operate on long integers with more precision than _add() and _sub().
Compute and display the time ten minutes ago. This example was run at 09/08/27 05:13:54.
_fmtdate('yy/MM/dd hh:mm:ss',_isub(_timer(),_dateof('mm',10,gmt)))
Results in 09/08/27 05:03:54.
The _dateadd() function adds the offset parameter to the date parameter. If the date and time is not provided, then the current date/time of iWay Service Manager (iSM) is used. This function uses the following format:
_dateadd(offset [,date])
offset |
literal |
A number pattern. This pattern describes the number of days, hours, minutes, seconds, or microseconds to add to the date. This pattern has the following definition: [xxd][xxh][xxm]xx[s] The value of xx represents a numeric value and the suffix is defined as follows:
Note: If the value of the offset parameter is entered without the d, h, m, or s suffix, then the offset is assumed to be milliseconds. For example:
|
date |
date/time |
Optional date timestamp. If this value is not provided, then the current date and time of iSM is used. |
For example, _dateadd(1d) yields the following:
1477627200000
Note: This is assuming that the date and time of iSM is 10/27/2016 12:00:00 AM.
You may have a use case where you need to perform and display a date calculation on a fixed date (for example, adding a week to 10/27/2016). This may be accomplished by using several iSM functions. For example:
_fmtdate('yyyy-MM-dd hh:mm:ss a',_dateadd(7d,_dateof('MM/dd/yyyy','10/27/2016')))
Results in:
2016-11-03 12:00:00 AM
The _datesub() function subtracts the offset parameter from the date parameter. If the date and time is not provided, then the current date/time of iWay Service Manager (iSM) is used. This function uses the following format:
_datesub(offset [,date])
offset |
literal |
A number pattern. This pattern describes the number of days, hours, minutes, seconds, or microseconds to subtract from the date. This pattern has the following definition: [xxd][xxh][xxm]xx[s] The value of xx represents a numeric value and the suffix is defined as follows:
Note: If the value of the offset parameter is entered without the d, h, m, or s suffix, then the offset is assumed to be milliseconds. For example:
|
date |
date/time |
Optional date timestamp. If this value is not provided, then the current date and time of iWay Service Manager (iSM) is used. |
For example, _datesub(1d) yields the following:
1477454400000
Note: This is assuming that the date and time of iSM is 10/27/2016 12:00:00 AM.
You may have a use case where you need to perform and display a date calculation on a fixed date (for example, subtracting a week from 10/04/2016). This may be accomplished by using several iSM functions. For example:
_fmtdate('yyyy-MM-dd hh:mm:ss a',_datesub(7d,_dateof('MM/dd/yyyy','10/04/2016')))
Results in:
2016-09-27 12:00:00 AM