strftime() function returns incorrect result for month

strftime() function returns incorrect result for month

book

Article ID: KB0082342

calendar_today

Updated On:

Products Versions
TIBCO Streaming 7.x, 10.x

Description

The strftime() function converts a timestamp field to a string, formatted according to a specified formatstring pattern, for the local time zone. The timestamp field can then be displayed and manipulated as a string instead of a timestamp.

However a defect relating to this function can cause incorrect results in some cases.  For example, the correct output month from strftime() for an input timestamp of "2018-02-01 00:00:00.000-0500" should be 'Feb'.  However, strftime() will incorrectly return 'Mar' instead:
sbd --eval "from_localtime(2018,2,1,0,0,0)"
(timestamp) 2018-02-01 00:00:00.000-0500

sbd --eval "strftime("""%b""", from_localtime(2018,2,1,0,0,0))"
(string) Mar

For reference, %b in the above expression specifies the locale's abbreviated month name, as noted in the strftime library documentation.

Issue/Introduction

The strftime() function can return incorrect result for month.

Resolution

To work around this defect, you can instead use a combination of the split() and format_time() functions.  The split() function parses a string into tokens delimited by a specified character and returns a list of strings with the tokens as elements.  The format_time() function (similar to strftime()) converts a timestamp field to a string using a specified pattern, as noted in the StreamBase Help under StreamBase Home > StreamBase References > StreamBase Expression Language Functions > (sub-heading) Timestamp Functions: Absolute Timestamps.  For example:
 
sbd --eval "split(split(format_time(from_localtime(2018,2,1,0,0,0), 'EEEE, MMM d, yyyy HH:mm zzzz'),',')[1],' ')[1]"
(string) Feb

This expression returns the correct month for the same input timestamp.