Mixin that provides time formatting/coversion functions.
Instance PropertiesProperty | Type | Default Value | Description |
DATETIME_FORMAT_TZ | String |
yyyy-MM-dd HH:mm:ssZ
| Datetime format used if the default fails. This format includes timezone info. |
DATETIME_TWO_YEAR_FORMAT | String |
yy-MM-dd HH:mm:ss
| Two year datetime format. If convertTwoDigitYear is set to true and the timeStampFormat fails this format will be tried. |
DEFAULT_DATETIME_FORMAT | String |
yyyy-MM-dd HH:mm:ss
| Default datetime format |
DEFAULT_DATE_FORMAT | String |
yyyy-MM-dd
| default date format. |
DEFAULT_TIMESTAMP_FORMAT | String |
yyyy-MM-dd HH:mm:ss
| Default timestamp format |
DEFAULT_TIME_FORMAT | String |
HH:mm:ss
| Default time format |
DEFAULT_YEAR_FORMAT | String |
yyyy
| Default year format |
ISO_8601 | String |
yyyy-MM-ddTHH:mm:ssZ
| ISO-8601 format |
ISO_8601_TWO_YEAR | String |
yy-MM-ddTHH:mm:ssZ
| Two year ISO-8601 format |
TIMESTAMP_FORMAT_TZ | String |
yyyy-MM-dd HH:mm:ssZ
| Timestamp format used if the default fails. This format includes timezone info. |
TIMESTAMP_TWO_YEAR_FORMAT | String |
yy-MM-dd HH:mm:ss
| Two year timestamp format. If convertTwoDigitYear is set to true and the timeStampFormat fails this format will be tried. |
TWO_YEAR_DATE_FORMAT | String |
yy-MM-dd
| Two year date format This is used in date coversions when convertTwoDigitYears is used. If this format fails then dateFormat|DEFAULT_DATE_FORMAT is used. |
convertTwoDigitYears | Boolean |
true
| By default patio will try to covert all two digit years. To turn this off: |
dateFormat | String | patio.Time#DEFAULT_DATE_FORMAT | the format to use to formatting/converting dates. |
dateTimeFormat | String | patio.Time#DEFAULT_DATETIME_FORMAT | the format to use to formatting/converting dates. |
timeFormat | String | patio.Time#DEFAULT_TIME_FORMAT | the format to use to formatting/converting dates. |
timeStampFormat | String | patio.Time#DEFAULT_TIMESTAMP_FORMAT | the format to use to formatting/converting dates. |
yearFormat | String | patio.Time#DEFAULT_YEAR_FORMAT | the format to use to formatting/converting dates. |
Converts a @link{patio.sql.DateTime} to a string. The format used is patio.Time#dateTimeFormat, which defaults to patio.Time#DEFAULT_DATETIME_FORMAT
Examplevar date = new Date(2004, 1, 1, 12, 12, 12), dateTime = new sql.DateTime(2004, 1, 1, 12, 12, 12), offset = "-0600"; patio.dateTimeToString(date); //=> '2004-02-01 12:12:12' patio.dateTimeToString(dateTime); //=> '2004-02-01 12:12:12' patio.dateTimeFormat = patio.DATETIME_TWO_YEAR_FORMAT; patio.dateTimeToString(date); //=> '04-02-01 12:12:12' patio.dateTimeToString(dateTime); //=> '04-02-01 12:12:12' patio.dateTimeFormat = patio.DATETIME_FORMAT_TZ; patio.dateTimeToString(date); //=> '2004-02-01 12:12:12-0600' patio.dateTimeToString(dateTime); //=> '2004-02-01 12:12:12-0600' patio.dateTimeFormat = patio.ISO_8601; patio.dateTimeToString(date); //=> '2004-02-01T12:12:12-0600' patio.dateTimeToString(dateTime); //=> '2004-02-01T12:12:12-0600' patio.dateTimeFormat = patio.ISO_8601_TWO_YEAR; patio.dateTimeToString(date); //=> '04-02-01T12:12:12-0600' patio.dateTimeToString(dateTime); //=> '04-02-01T12:12:12-0600'Arguments
the datetime to covert to to a string.
String
the date string.
function (dt,format){ return dateFormat(isInstanceOf(dt, SQL.DateTime) ? dt.date : dt, format || this.dateTimeFormat); }
Converts a date to a string.
Examplevar date = new Date(2004, 1, 1), timeStamp = new sql.TimeStamp(2004, 1, 1, 12, 12, 12), dateTime = new sql.DateTime(2004, 1, 1, 12, 12, 12), year = new sql.Year(2004), time = new sql.Time(12,12,12), //convert years patio.dateToString(year); //=> '2004' patio.yearFormat = "yy"; patio.dateToString(year); //=> '04' patio.yearFormat = patio.DEFAULT_YEAR_FORMAT; patio.dateToString(year); //=> '2004' //convert times patio.dateToString(time); //=> '12:12:12' //convert dates patio.dateToString(date); //=> '2004-02-01' patio.dateFormat = patio.TWO_YEAR_DATE_FORMAT; patio.dateToString(date); //=> '04-02-01' patio.dateFormat = patio.DEFAULT_DATE_FORMAT; patio.dateToString(date); //=> '2004-02-01' //convert dateTime patio.dateToString(dateTime); //=> '2004-02-01 12:12:12' patio.dateTimeFormat = patio.DATETIME_TWO_YEAR_FORMAT; patio.dateToString(dateTime); //=> '04-02-01 12:12:12' patio.dateTimeFormat = patio.DATETIME_FORMAT_TZ; patio.dateToString(dateTime); //=> '2004-02-01 12:12:12-0600' patio.dateTimeFormat = patio.ISO_8601; patio.dateToString(dateTime); //=> '2004-02-01T12:12:12-0600' patio.dateTimeFormat = patio.ISO_8601_TWO_YEAR; patio.dateToString(dateTime); //=> '04-02-01T12:12:12-0600' patio.dateTimeFormat = patio.DEFAULT_DATETIME_FORMAT; patio.dateToString(dateTime); //=> '2004-02-01 12:12:12' //convert timestamps patio.dateToString(timeStamp); //=> '2004-02-01 12:12:12' patio.timeStampFormat = patio.TIMESTAMP_TWO_YEAR_FORMAT; patio.dateToString(timeStamp); //=> '04-02-01 12:12:12' patio.timeStampFormat = patio.TIMESTAMP_FORMAT_TZ; patio.dateToString(timeStamp); //=> '2004-02-01 12:12:12-0600' patio.timeStampFormat = patio.ISO_8601; patio.dateToString(timeStamp); //=> '2004-02-01T12:12:12-0600' patio.timeStampFormat = patio.ISO_8601_TWO_YEAR; patio.dateToString(timeStamp); //=> '04-02-01T12:12:12-0600' patio.timeStampFormat = patio.DEFAULT_TIMESTAMP_FORMAT; patio.dateToString(timeStamp); //=> '2004-02-01 12:12:12'Arguments
the date to covert to to a string.
String
the date string.
function (dt,format){ var ret = ""; if (isInstanceOf(dt, SQL.Time)) { ret = this.timeToString(dt, format); } else if (isInstanceOf(dt, SQL.Year)) { ret = this.yearToString(dt, format); } else if (isInstanceOf(dt, SQL.DateTime)) { ret = this.dateTimeToString(dt, format); } else if (isInstanceOf(dt, SQL.TimeStamp)) { ret = this.timeStampToString(dt, format); } else if (isDate(dt)) { ret = dateFormat(dt, format || this.dateFormat); } return ret; }
Converts a date string to a Date
Examplevar date = new Date(2004, 1,1,0,0,0); patio.stringToDate('2004-02-01'); //=> date patio.dateFormat = patio.TWO_YEAR_DATE_FORMAT; patio.stringToDate('04-02-01'); //=> dateArguments
the string to convert to a Date
patio.Time#dateFormat
] : the format to use when converting the date.
Date
the Date
PatioError
thrown if the conversion fails.
function (dt,format){ var ret; if (this.convertTwoDigitYears) { ret = date.parse(dt, this.TWO_YEAR_DATE_FORMAT); } if (!ret) { ret = date.parse(dt, format || this.dateFormat); } if (!ret) { throw new PatioError("Unable to convert date: " + dt); } return ret; }
Converts a datetime date string to a patio.sql.DateTime
Examplevar dateTime = new sql.DateTime(2004, 1, 1, 12, 12, 12), offset = getTimeZoneOffset(); patio.stringToDateTime('2004-02-01 12:12:12'); //=> dateTime patio.dateTimeFormat = patio.DATETIME_TWO_YEAR_FORMAT; patio.stringToDateTime('04-02-01 12:12:12-0600'); //=> dateTime patio.dateTimeFormat = patio.DATETIME_FORMAT_TZ; patio.stringToDateTime('2004-02-01 12:12:12-0600'); //=> dateTime patio.dateTimeFormat = patio.ISO_8601; patio.stringToDateTime('2004-02-01T12:12:12-0600'); //=> dateTime patio.dateTimeFormat = patio.ISO_8601_TWO_YEAR; patio.stringToDateTime('04-02-01T12:12:12-0600'); //=> dateTimeArguments
the string to convert to a patio.sql.DateTime
patio.Time#dateTimeFormat
] String
: the format to use when converting the date.
patio.sql.DateTime
PatioError
thrown if the conversion fails.
function (dt,fmt){ var useT = dt.indexOf("T") !== -1; //test if there is a T in the string so we can try to properly convert it var format = fmt ? fmt : useT ? this.ISO_8601 : this.DEFAULT_DATETIME_FORMAT; var ret = date.parse(dt, format); //if the coversion failed try it with a time zone !ret && (ret = date.parse(dt, this.DATETIME_FORMAT_TZ)); if (!ret && this.convertTwoDigitYears) { //if we still fail and we need to convert two digit years try the twoYearFormat var twoYearFormat = fmt ? fmt : useT ? this.ISO_8601_TWO_YEAR : this.DATETIME_TWO_YEAR_FORMAT; ret = date.parse(dt, twoYearFormat); //try with time zone !ret && (ret = date.parse(dt, twoYearFormat + "Z")); } if (!ret) { throw new PatioError("Unable to convert datetime: " + dt); } return new SQL.DateTime(ret); }
Converts a time date string to a patio.sql.Time
Examplevar time = new sql.Time(12,12,12); patio.stringToTime("12:12:12"); //=> timeArguments
the string to convert to a patio.sql.Time
patio.Time#timeFormat
] : the format to use when converting the date.
patio.sql.Time
the patio.sql.Time
PatioError
thrown if the conversion fails.
function (dt,format){ var ret = date.parse(dt, format || this.timeFormat); if (!ret) { throw new PatioError("Unable to convert time: " + dt); } return new SQL.Time(ret); }
Converts a timestamp date string to a patio.sql.TimeStamp
Examplevar timeStamp = new sql.TimeStamp(2004, 1, 1, 12, 12, 12); patio.stringToTimeStamp('2004-02-01 12:12:12'); //=> timeStamp patio.timeStampFormat = patio.TIMESTAMP_TWO_YEAR_FORMAT; patio.stringToTimeStamp('04-02-01 12:12:12-0600'); //=> timeStamp patio.timeStampFormat = patio.TIMESTAMP_FORMAT_TZ; patio.stringToTimeStamp('2004-02-01 12:12:12-0600'); //=> timeStamp patio.timeStampFormat = patio.ISO_8601; patio.stringToTimeStamp('2004-02-01T12:12:12-0600'); //=> timeStamp patio.timeStampFormat = patio.ISO_8601_TWO_YEAR; patio.stringToTimeStamp('04-02-01T12:12:12-0600'); //=> timeStampArguments
the string to convert to a patio.sql.TimeStamp
patio.Time#timeStampFormat
] String
: the format to use when converting the date.
patio.sql.TimeStamp
PatioError
thrown if the conversion fails.
function (dt,fmt){ var useT = dt.indexOf("T") !== -1; //test if there is a T in the string so we can try to properly convert it var format = fmt ? fmt : useT ? this.ISO_8601 : this.DEFAULT_TIMESTAMP_FORMAT; var ret = date.parse(dt, format); //if the coversion failed try it with a time zone !ret && (ret = date.parse(dt, this.TIMESTAMP_FORMAT_TZ)); if (!ret && this.convertTwoDigitYears) { //if we still fail and we need to convert two digit years try the twoYearFormat var twoYearFormat = fmt ? fmt : useT ? this.ISO_8601_TWO_YEAR : this.TIMESTAMP_TWO_YEAR_FORMAT; ret = date.parse(dt, twoYearFormat); //try with time zone !ret && (ret = date.parse(dt, twoYearFormat + "Z")); } if (!ret) { throw new PatioError("Unable to convert timestamp: " + dt); } return new SQL.TimeStamp(ret); }
Converts a year date string to a patio.sql.Year
Examplevar year = new sql.Year(2004); patio.stringToYear("2004"); //=> year patio.yearFormat = "yy"; patio.stringToYear("04"); //=> yearArguments
the string to covert to a patio.sql.Year
patio.Time#yearFormat
] : the format to use when converting the date.
patio.sql.Year
the patio.sql.Year
PatioError
thrown if the conversion fails.
function (dt,format){ var ret = date.parse(dt, format || this.yearFormat); if (!ret) { throw new PatioError("Unable to convert year: " + dt); } return new SQL.Year(ret); }
Converts a patio.sql.TimeStamp to a string. The format used is patio.Time#timeStampFormat, which defaults to patio.Time#DEFAULT_TIMESTAMP_FORMAT
Examplevar date = new Date(2004, 1, 1, 12, 12, 12), dateTime = new sql.TimeStamp(2004, 1, 1, 12, 12, 12), offset = "-0600"; patio.timeStampToString(date); //=> '2004-02-01 12:12:12' patio.timeStampToString(dateTime); //=> '2004-02-01 12:12:12' patio.timeStampFormat = patio.TIMESTAMP_TWO_YEAR_FORMAT; patio.timeStampToString(date); //=> '04-02-01 12:12:12' patio.timeStampToString(dateTime); //=> '04-02-01 12:12:12' patio.timeStampFormat = patio.TIMESTAMP_FORMAT_TZ; patio.timeStampToString(date); //=> '2004-02-01 12:12:12-0600' patio.timeStampToString(dateTime); //=> '2004-02-01 12:12:12-0600' patio.timeStamp = patio.ISO_8601; patio.timeStampToString(date); //=> '2004-02-01T12:12:12-0600' patio.timeStampToString(dateTime); //=> '2004-02-01T12:12:12-0600' patio.timeStamp = patio.ISO_8601_TWO_YEAR; patio.timeStampToString(date); //=> '04-02-01T12:12:12-0600' patio.timeStampToString(dateTime); //=> '04-02-01T12:12:12-0600'Arguments
the timestamp to convert to to a string.
String
the date string.
function (dt,format){ return dateFormat(isInstanceOf(dt, SQL.TimeStamp) ? dt.date : dt, format || this.timeStampFormat); }
Converts a sql.Time to a string. The format used is patio.Time#timeFormat, which defaults to patio.Time#DEFAULT_TIME_FORMAT
Examplevar date = new Date(null, null, null, 13, 12, 12), time = new sql.Time(13,12,12); patio.timeToString(date); //=> '13:12:12' patio.timeToString(time); //=> '13:12:12' patio.timeFormat = "hh:mm:ss"; patio.timeToString(date); //=> '01:12:12' patio.timeToString(time); //=> '01:12:12'Arguments
the time to covert to to a string.
String
the date string.
function (dt,format){ return dateFormat(isInstanceOf(dt, SQL.Time) ? dt.date : dt, format || this.timeFormat); }
Converts a patio.sql.Year to a string. The format used is patio.Time#yearFormat, which defaults to patio.Time#DEFAULT_YEAR_FORMAT
Examplevar date = new Date(2004, 1, 1, 1, 1, 1), year = new sql.Year(2004); patio.yearToString(date); //=> '2004' patio.yearToString(year); //=> '2004' patio.yearFormat = "yy"; patio.yearToString(date); //=> '04' patio.yearToString(year); //=> '04'Arguments
the year to covert to to a string.
String
the date string.
function (dt,format){ return dateFormat(isInstanceOf(dt, SQL.Year) ? dt.date : dt, format || this.yearFormat); }