-- -*- Mode: rpl; -*-
--
-- ts.rpl timestamps
--
-- © Copyright IBM Corporation 2017.
-- LICENSE: MIT License (https://opensource.org/licenses/mit-license.html)
-- AUTHOR: Jamie A. Jennings
package ts
import date, time
-- RFC3339 date-time = full-date [Tt ] full-time
-- RFC2822 / RFC5322 date-time = [ day-of-week "," ] date FWS time [CFWS]
local alias slashed_date = date.us_slashed / date.slashed
local alias dashed_date = date.us_dashed / date.dashed
local alias common_times = time.simple / time.rfc2822_frac / time.rfc3339
rfc3339 = { date.rfc3339 [Tt ] time.rfc3339_strict}
rfc2822 = { date.rfc2822 time.rfc2822 }
slashed_colon = { slashed_date ":" time.rfc2822 }
us_long = date.us_long common_times
us_short = date.us_short common_times
slashed = slashed_date common_times time.rfc2822_zone?
dashed = dashed_date common_times time.rfc2822_zone?
spaced = date.spaced common_times time.rfc2822_zone?
spaced_en = date.spaced_en common_times time.rfc2822_zone?
websphere = slashed_date time.websphere -- seen in WebSphere logs
db2 = { date.rfc3339 "-" time.db2 } -- seen in db2 logs
mixed1 = (date.day_name ","?)? date.month_name date.day ","? time.rfc2822_frac time.rfc2822_zone? date.year?
mixed2 = (date.us_dashed / date.slashed / date.us_slashed / date.slashed)
time.rfc2822_frac
time.rfc2822_zone?
date.year?
any = dashed / slashed /
rfc3339 /
mixed1 / mixed2 /
us_long / us_short /
rfc2822 /
websphere / db2 /
spaced_en / spaced
--
-- Pattern Example Format
--
-- test us_short accepts "23 Apr 2015 11:42:35.883" dd MMM yyyy HH:mm:ss.sss
-- test us_long accepts "Dec 2, 2010 2:39:58 AM" MMM dd, yyyy hh:mm:ss am/pm
-- test us_long accepts "Jun 09 2011 15:28:14" MMM dd yyyy HH:mm:ss
-- test mixed1 accepts "Apr 20 00:00:35 2010" MMM dd HH:mm:ss yyyy
-- test mixed1 accepts "Feb 07 15:22:31 -0700 2016" MMM dd HH:mm:ss ZZZZ yyyy
-- test mixed1 accepts "Sep 28 19:00:00 +0000" MMM dd HH:mm:ss ZZZZ
-- test mixed1 accepts "Mar 16 08:12:04" MMM dd HH:mm:ss
-- test dashed accepts "11-02-11 16:47:35,985 +0000" yy-MM-dd HH:mm:ss,sss ZZZZ
-- test dashed accepts "10-06-26 02:31:29,573" yy-MM-dd HH:mm:ss,sss
-- test dashed accepts "10-04-19 12:00:17" yy-MM-dd HH:mm:ss
-- test slashed accepts "06/01/22 04:09:05" yy/MM/dd HH:mm:ss
-- test spaced_en accepts "2017 Jun 19 13:16:49.194 EST" yyyy MMM dd HH:mm:ss.sss zzz
-- test dashed accepts "2011-02-11 16:47:35,985 +0000" yyyy-MM-dd HH:mm:ss,sss ZZZZ
-- test rfc3339 accepts "2015-10-02T23:59:59.573+02:00" yyyy-MM-dd'T'HH:mm:ss,sssZZZZ
-- test rfc3339 accepts "2015-10-14T22:11:20+00:00" yyyy-MM-dd'T'HH:mm:ssZZZZ
-- test rfc3339 accepts "2014-07-01T14:59:55.711Z" yyyy-MM-dd'T'HH:mm:ss.sssZ
-- test dashed accepts "2011-08-19 12:17:55 -0400" yyyy-MM-dd HH:mm:ss ZZZZ
-- test dashed accepts "2011-08-19 12:17:55-0400" yyyy-MM-dd HH:mm:ssZZZZ
-- test dashed accepts "2016-09-06 10:51:18 PDT" yyyy-MM-dd HH:mm:ss zzz
-- test dashed accepts "2010-06-26 02:31:29,573" yyyy-MM-dd HH:mm:ss,sss
-- test dashed accepts "2010-04-19 12:00:17" yyyy-MM-dd HH:mm:ss
-- test dashed accepts "2010-04-19 12:00:17:552" yyyy-MM-dd HH:mm:ss:sss
-- test slashed accepts "2006/01/22 04:11:05" yyyy/MM/dd HH:mm:ss
-- test slashed accepts "04/23/15 11:42:35" MM/dd/yy HH:mm:ss
-- test slashed accepts "04/23/2015 11:42:35" MM/dd/yyyy HH:mm:ss
-- test slashed accepts "04/23/2015 11:42:35.883" MM/dd/yyyy HH:mm:ss.sss
-- test slashed accepts "9/28/2009 2:23:15 PM" MM/dd/yyyy hh:mm:ss am/pm