I'm planning to extend
ExpressionManager to support dates and date-related math. In addition to regular comparison operators (>,>=,<,<=,==,!=), I expect to support at least the following set of functions (since I have customers who used a Java-based survey system with those functions and need to port over to LimeSurvey).
Name | Syntax | Description |
formatDate | formatDate(X,PAT) | return the string value of date X formatted according to Java data format pattern PAT |
getNow | getNow() | returns the date corresponding to the current system time (if the computer clock is accurate) |
getStartTime | getStartTime() | returns the date corresponding to the system time when the interview was started |
isDate | isDate(X) | returns true if the answer happens to be a valid date |
newDate | newDate(W)
newDate(S,M)
newDate(Y,M,D) | returns a date corresponding to day of the week W (1 = Sunday, 2 = Monday, ...)
returns a date corresponding to string S as parsed by date mask M
returns a date corresponding to year Y, month M, and day D |
newTime | newTime(S,M)
newTime(H,M,S) | returns a date/time corresponding to string S as parsed by time mask M
returns a date/time corresponding to hour H, minutes M, and seconds S |
parseDate | parseDate(X,PAT) | returns the date value of string X parsed with Java date format pattern PAT |
toDate | toDate(X) | returns the answer for node X, as a date if possible, otherwise returns *INVALID* |
toDay | toDay(X) | returns the day components of X if possible, otherwise returns *INVALID* |
toDayNum | toDayNum(X) | returns the day number components of X (day of the year) if possible, otherwise returns *INVALID* |
toHour | toHour(X) | returns the hour component of X |
toMinute | toMinute(X) | returns the minute component of X if possible, otherwise returns *INVALID* |
toMonth | toMonth(X) | returns the month component of X if possible, otherwise returns *INVALID* |
toMonthNum | toMonthNum(X) | returns the month number (1-12) component of X if possible, otherwise returns *INVALID* |
toSecond | toSecond(X) | returns the seconds component of X if possible, otherwise returns *INVALID* |
toTime | toTime(X) | returns X as a time value (hh:mm:ss) if possible, otherwise returns *INVALID* |
toWeekday | toWeekday(X) | returns the weekday component of X if possible (e.g. 'Monday'), otherwise returns *INVALID* |
toYear | toYear(X) | returns the year component of X if possible, otherwise returns *INVALID* |
What other date-related functions has the community been asking for?
Also, do people have strong opinions on how to implement this technically?
The way I did this in the past was to support weak data typing, but store most answers in text fields. If the value happened to be a number, then numerical operators on it would make sense. Similarly, if the value happened to be a date, then you could do date-related functions.