User Guide and Reference

Dates

Hide Navigation Pane

Dates

Previous topic Next topic No directory for this topic  

Dates

Previous topic Next topic Topic directory requires JavaScript JavaScript is required for the print function  

Date Formats and Patterns

There are a number of different ways in which data is stored, displayed, edited and validated in Composer forms. These are mostly useful for dates and numeric values, which can be represented in different ways. When you are using Composer, you can specify these different formats by using data patterns, such as DD/MM/YYYY or $#,###.##.

 

The different formats are:

 

Format

Description

Edit Format

This is the format that is used when the user types into the field. For example, 3/27/2012, or 49.99. It is possible to have multiple alternate edit formats - for example, allowing either 2 or 4 digit years.

Display Format

This is the format that is displayed when the user exits the field. It can be more readable than the edit format, and clarifies the interpretation. For example, 27th March 2012 or $49.99

Raw Format

This is the value that is actually stored within the form at runtime. It's the value you get from calling the getRawValue(). This is standardized to make programming easier - it doesn't matter what your  formats are used for the form users, you always get a consistent value in any code you write. For dates, this is ISO format, such as 2012-03-27.

XML Format

This is the format that is used to actually store the data in the XML file. Composer will use this format for pre-population data, and will convert to this format on submission.

Validation Pattern

PDF forms allow a separate validation pattern that is used to ensure that the data is valid. In Composer, the Validation Pattern is always identical to the Edit Pattern.

 

Usually, you don't need to be aware of these patterns because they are specified in your organizational stylesheets. However, you may need to occasionally override these patterns for particular fields.

 

In most cases, users will enter dates using pop-up date editors, and so date edit format patterns are not so important. However, some users, especially "power" users and visually impaired users may prefer to enter dates using the keyboard.

 

Recommendation for Dates

For dates, we recommend that the most useful Data Format is:

 

North America: date{M/D/YYYY}|date{M/D/YY}
 

Elsewhere: date{D/M/YYYY}|date{D/M/YY}

 

These format will:

accept single digit days and months with or without a leading zero (flexible)
 

accept 2 digit or 4 digit years (flexible)
 

for editing, will always display days and years without leading zeros (simpler)
 

for editing, will always display years including the century (no ambiguity)

 

Working with Dates

 

Composer uses the Java library moment.js (freely distributable under the terms of the MIT license) to handle dates.

 

The date clases in the Avoka Composer Framework are:

 

sfc.formatDate(dateObject, dateFormat)
where "dateObject" is is the raw value of the form element, sfc.getRawValue(someFormElement)
 

sfc.getDaysDifference(startDate, endDate)
Where the startDate and endDate are raw values.
 

sfc.getTodaysDate()
Returns today's date as YYYY-MM-DD
This is not the generation date of the form (which you access in scripts with the property formula $GENERATION{DATE} instead)
This call returns only the calendar date. To get the time of day and timezone as well, use this native JavaScript call instead, where "x" will be your date object.
 
var x = new Date();
 

sfc.isLeapYear(year)
Where "year" is a 4-digit value. Returns true or false.
 

sfc.isPastDate(date)
Where "date" is the raw value. Returns true or false
 

sfc.isToday(date)
Where "date" is the raw value.
 

sfc.parseDate(dateString, dateFormat)
Parses a date according to the given date format. Both parameters are strings. Returns a raw value.

 

Advanced Date Output Formats

The sfc methods for date handling depend on the Moment.js library. This JavaScript library can output dates in various formats, as specified by this table:

 

Input

Output

M, MM

Month Number (1 - 12)

MMM, MMMM

Month Name

Q

Quarter (1 - 4) -- sets the month to the first month in that quarter

D, DD

Day of month

Do

Ordinal day of month (from 2.6.0)

DDD, DDDD

Day of year

d, dd, ddd, dddd

Day of week (NOTE: these formats only make sense when combined with "ww")

e

Day of week (locale) (NOTE: these formats only make sense when combined with "ww")

E

Day of week (ISO) (NOTE: this format only make sense when combined with "WW")

w, ww

Week of the year (NOTE: combine this format with "gg" or "gggg" instead of "YY" or "YYYY")

W, WW

Week of the year (NOTE: combine this format with "GG" or "GGGG" instead of "YY" or "YYYY")

YY

2 digit year (see below)

YYYY

4 digit year

gg

2 digit week year (if greater than 68 will return 1900's, otherwise 2000's)

gggg

4 digit week year

GG

2 digit week year (ISO) (if greater than 68 will return 1900's, otherwise 2000's)

GGGG

4 digit week year (ISO)

a, A

AM/PM

H, HH

24 hour time

h, hh

12 hour time (use in conjunction with a or A)

m, mm

Minutes

s, ss

Seconds

S

Deciseconds (1/10th of a second)

SS

Centiseconds (1/100th of a second)

SSS

Milliseconds (1/1000th of a second)

Z, ZZ

Timezone offset as +07:00 or +0700

X

Unix timestamp

LT, L, LL, LLL, LLLL

Locale dependent date and time representation

 

You parse an input date with sfc.parseDate (dateString, dateFormat), using the formats in the Input column of the table immediately below. The output of this call gives you a properly formatted raw date format.

 

You can use these to build the full input format specification, using other characters as punctuation. For example: YYYY-MM-DD or YYYY/MM/DD or DD/MM/YYYY or MM/DD/YYYY. Internally, Composer's raw date format is YYYY-MM-DD, or for more precision to include time of day, timezones along with the date, it uses the ISO Date Format.

 

You also can control how a date object displays using sfc.formatDate(dateObject, dateFormat), using the formats displayed in the right-hand "Output" column. As with inputs, you can concatenate these together using characters as punctuation. For example: "MMMM Do, YYYY, HH:mm a, timezone Z" formats as "May 19th, 2014, 13:27 pm, timezone +10:00", where the Z specifies the timezone as the timezone offset from GMT.

 

To return the precise time and timezone, use

 

var x= new Date;

 

and get the formatted time with our sample format with the call

 

sfc.formatDate(x, "MMMM Do, YYYY, HH:mm a, timezone Z")