Class: DateTimeService

DateTimeService


new DateTimeService()

This service class provides validation, parsing, and formatting for date/time values.

Methods


convertFMtoISO(fmDate)

Turns a Fileman number into an ISO 8601 date (ie XSD date) equivalent, or null if the date input was invalid

Parameters:
Name Type Description
fmDate String

A Fileman formatted date-time input, or null if 'fmDate' was invalid

Returns:

convertedISODate An ISO 8601 date to convert

Type
String
Examples
'3170505.062721'
'2017-05-05T06:27:21-10:00'

convertGmvDate(dateTimeStr)

Convert a user-supplied date/time into VA FileMan's internal and external date format.

Parameters:
Name Type Description
dateTimeStr String

A date-time value to convert.

Returns:

res A Fileman formatted date-time value, or empty string if conversion fails

Type
String
Examples
'08/04/2016@9:57PM'
'3160804.2157^AUG 04, 2016@21:57:00'

convertISOtoFM(dateTimeStr, options)

Turn an ISO 8601 date (ie XSD date) into Fileman equivalent, or null if the date string was invalid

Parameters:
Name Type Description
dateTimeStr String

An ISO 8601 date to convert

options Object

Formatting options

Properties
Name Type Description
time Boolean

(default true: return value has time component)

Returns:

fmDate A Fileman formatted date-time string, or null if 'dateTime' was invalid

Type
String
Examples
'2016-08-04T21:57:00-10:00'
'3160804.2157'

lookupCurrentFMDate()

Get the current date in Fileman format

Returns:

An FM-formatted date

Type
Number
Example
'3160804'

lookupCurrentFMTime()

Get the current date/time in Fileman format

Returns:

An FM-formatted date/time

Type
Number
Example
'3160804.2157'

parseDateTime(dateTimeStr, opts)

Validate a time string and return internal vista form of a date

Parameters:
Name Type Description
dateTimeStr String

Allowable inputs: N[OW] [+/- xxx] xxx may be H, M, ' (plus or minus a number of hours, months or minutes) NOV 1, 2015 NOV 1, 2015@... MID Note: Midnight = 24:00:00, not 00:00:00 NOON Noon = 12:00:00 11/01/2015 Note: if 'I' 11 Jan, if not 'I' 1 Nov 11/01/2015@... 11/01@... mm/dd or dd/mm, year is determined based on 'F' or 'P', this year if neither specified 110115 ddmmyy or mmddyy (depends on 'I') 3151101 fileman format 11012015 ddmmyyyy or mmddyyyy (depends on 'I') 2015 imprecise date, year only NOV 2015 imprecise date, year and month T[ODAY] [+/- xxx] Note: today@00:00:00 is entered as yesterday@24:00:00 xxx may be D, W, M (plus or minus a number of days, weeks or months) T[ODAY] [+/- xxx]@... ...@12:34 ...@12:34:56 ...@10:13 AM leading space optional ...@10:13:45 AM AM, A.M, A, A.M. are acceptable ...@10:13 PM PM, P.P, P, P.M. are acceptable ...@10:13:45 PM %DT accepts 13:15 AM (=01:15) and 13:15 PM 1234567.123456 fileman format

opts String

String containing one or more of the following: A = prompt user for date input -- not implemented E = echo the user's response -- not implemented F = future date assumed I = international (dd/mm/yyyy) M = only month and year N = numeric only input is not allowed O = time only allowed P = past date assumed R = time part required S = include seconds T = time optional X = date must be exact


validateDate(dateTimeStr, options)

Validate a date and return internal vista form of a date

Parameters:
Name Type Description
dateTimeStr String

A date-time value to validate

options String

Optional value to set format of result

Returns:

result A date in vista form (YYYY-MM-DDTHH:mm:ssZ) or -1 if the input could not be validated/parsed

Type
Number
Examples
'Aug 4,2016@21:57'
'TS'
'3160804.2157'

xsdToFMDateTime(dateTime)

Turn a VDM date (ie XSD date) into FM equivalent

Parameters:
Name Type Description
dateTime String

A VDM date to convert

Returns:

fmDate A Fileman formatted date-time string (YYYY-MM-DDTHH:mm:ssZ)

Type
String
Examples
'2016-08-04T21:57:00-10:00'
'3160804.2157'