In this section: |
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 in ISO 8601 format. It uses the following format:
_tstamp()
This is a standard time function that is commonly used in many XML and web applications. The accuracy is to seconds. This function has no options.
The _ftstamp() function returns a time stamp to milliseconds in ISO 8601 format. It uses the following format:
_ftstamp(['compress'])
compress | literal | Format instruction |
For example:
_ftstamp() yields 2006-07-21T19:42:44:609Z
The special pattern of the word compress eliminates the separator characters, yielding 20060721194244609Z. The compress option simplifies using the output in file names and in other situations in which the separator characters would be inappropriate.
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.
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.
iWay Software |