Mixin that provides time formatting/coversion functions.

Instance Properties
PropertyTypeDefault ValueDescription
DATETIME_FORMAT_TZString yyyy-MM-dd HH:mm:ssZ

Datetime format used if the default fails. This format includes timezone info.

DATETIME_TWO_YEAR_FORMATString 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_FORMATString yyyy-MM-dd HH:mm:ss

Default datetime format

DEFAULT_DATE_FORMATString yyyy-MM-dd

default date format.

DEFAULT_TIMESTAMP_FORMATString yyyy-MM-dd HH:mm:ss

Default timestamp format

DEFAULT_TIME_FORMATString HH:mm:ss

Default time format

DEFAULT_YEAR_FORMATString yyyy

Default year format

ISO_8601String yyyy-MM-ddTHH:mm:ssZ

ISO-8601 format

ISO_8601_TWO_YEARString yy-MM-ddTHH:mm:ssZ

Two year ISO-8601 format

TIMESTAMP_FORMAT_TZString yyyy-MM-dd HH:mm:ssZ

Timestamp format used if the default fails. This format includes timezone info.

TIMESTAMP_TWO_YEAR_FORMATString 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_FORMATString 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.

convertTwoDigitYearsBoolean true

By default patio will try to covert all two digit years. To turn this off:

dateFormatString patio.Time#DEFAULT_DATE_FORMAT

the format to use to formatting/converting dates.

dateTimeFormatString patio.Time#DEFAULT_DATETIME_FORMAT

the format to use to formatting/converting dates.

timeFormatString patio.Time#DEFAULT_TIME_FORMAT

the format to use to formatting/converting dates.

timeStampFormatString patio.Time#DEFAULT_TIMESTAMP_FORMAT

the format to use to formatting/converting dates.

yearFormatString patio.Time#DEFAULT_YEAR_FORMAT

the format to use to formatting/converting dates.

Constructor

Defined time.js

dateTimeToString Function Public


Defined time.js

Converts a @link{patio.sql.DateTime} to a string. The format used is patio.Time#dateTimeFormat, which defaults to patio.Time#DEFAULT_DATETIME_FORMAT

Example
  1. var date = new Date(2004, 1, 1, 12, 12, 12),
  2. dateTime = new sql.DateTime(2004, 1, 1, 12, 12, 12),
  3. offset = "-0600";
  4. patio.dateTimeToString(date); //=> '2004-02-01 12:12:12'
  5. patio.dateTimeToString(dateTime); //=> '2004-02-01 12:12:12'
  6.  
  7. patio.dateTimeFormat = patio.DATETIME_TWO_YEAR_FORMAT;
  8. patio.dateTimeToString(date); //=> '04-02-01 12:12:12'
  9. patio.dateTimeToString(dateTime); //=> '04-02-01 12:12:12'
  10.  
  11. patio.dateTimeFormat = patio.DATETIME_FORMAT_TZ;
  12. patio.dateTimeToString(date); //=> '2004-02-01 12:12:12-0600'
  13. patio.dateTimeToString(dateTime); //=> '2004-02-01 12:12:12-0600'
  14.  
  15. patio.dateTimeFormat = patio.ISO_8601;
  16. patio.dateTimeToString(date); //=> '2004-02-01T12:12:12-0600'
  17. patio.dateTimeToString(dateTime); //=> '2004-02-01T12:12:12-0600'
  18.  
  19. patio.dateTimeFormat = patio.ISO_8601_TWO_YEAR;
  20. patio.dateTimeToString(date); //=> '04-02-01T12:12:12-0600'
  21. patio.dateTimeToString(dateTime); //=> '04-02-01T12:12:12-0600'
Arguments Returns Source
  1. function (dt,format){
  2. return dateFormat(isInstanceOf(dt, SQL.DateTime) ? dt.date : dt, format || this.dateTimeFormat);
  3. }

dateToString Function Public


Defined time.js

Converts a date to a string.

Example
  1. var date = new Date(2004, 1, 1),
  2. timeStamp = new sql.TimeStamp(2004, 1, 1, 12, 12, 12),
  3. dateTime = new sql.DateTime(2004, 1, 1, 12, 12, 12),
  4. year = new sql.Year(2004),
  5. time = new sql.Time(12,12,12),
  6.  
  7. //convert years
  8. patio.dateToString(year); //=> '2004'
  9. patio.yearFormat = "yy";
  10. patio.dateToString(year); //=> '04'
  11. patio.yearFormat = patio.DEFAULT_YEAR_FORMAT;
  12. patio.dateToString(year); //=> '2004'
  13.  
  14. //convert times
  15. patio.dateToString(time); //=> '12:12:12'
  16.  
  17. //convert dates
  18. patio.dateToString(date); //=> '2004-02-01'
  19. patio.dateFormat = patio.TWO_YEAR_DATE_FORMAT;
  20. patio.dateToString(date); //=> '04-02-01'
  21. patio.dateFormat = patio.DEFAULT_DATE_FORMAT;
  22. patio.dateToString(date); //=> '2004-02-01'
  23.  
  24. //convert dateTime
  25. patio.dateToString(dateTime); //=> '2004-02-01 12:12:12'
  26. patio.dateTimeFormat = patio.DATETIME_TWO_YEAR_FORMAT;
  27. patio.dateToString(dateTime); //=> '04-02-01 12:12:12'
  28. patio.dateTimeFormat = patio.DATETIME_FORMAT_TZ;
  29. patio.dateToString(dateTime); //=> '2004-02-01 12:12:12-0600'
  30. patio.dateTimeFormat = patio.ISO_8601;
  31. patio.dateToString(dateTime); //=> '2004-02-01T12:12:12-0600'
  32. patio.dateTimeFormat = patio.ISO_8601_TWO_YEAR;
  33. patio.dateToString(dateTime); //=> '04-02-01T12:12:12-0600'
  34. patio.dateTimeFormat = patio.DEFAULT_DATETIME_FORMAT;
  35. patio.dateToString(dateTime); //=> '2004-02-01 12:12:12'
  36.  
  37. //convert timestamps
  38. patio.dateToString(timeStamp); //=> '2004-02-01 12:12:12'
  39. patio.timeStampFormat = patio.TIMESTAMP_TWO_YEAR_FORMAT;
  40. patio.dateToString(timeStamp); //=> '04-02-01 12:12:12'
  41. patio.timeStampFormat = patio.TIMESTAMP_FORMAT_TZ;
  42. patio.dateToString(timeStamp); //=> '2004-02-01 12:12:12-0600'
  43. patio.timeStampFormat = patio.ISO_8601;
  44. patio.dateToString(timeStamp); //=> '2004-02-01T12:12:12-0600'
  45. patio.timeStampFormat = patio.ISO_8601_TWO_YEAR;
  46. patio.dateToString(timeStamp); //=> '04-02-01T12:12:12-0600'
  47. patio.timeStampFormat = patio.DEFAULT_TIMESTAMP_FORMAT;
  48. patio.dateToString(timeStamp); //=> '2004-02-01 12:12:12'
Arguments Returns Source
  1. function (dt,format){
  2. var ret = "";
  3. if (isInstanceOf(dt, SQL.Time)) {
  4. ret = this.timeToString(dt, format);
  5. } else if (isInstanceOf(dt, SQL.Year)) {
  6. ret = this.yearToString(dt, format);
  7. } else if (isInstanceOf(dt, SQL.DateTime)) {
  8. ret = this.dateTimeToString(dt, format);
  9. } else if (isInstanceOf(dt, SQL.TimeStamp)) {
  10. ret = this.timeStampToString(dt, format);
  11. } else if (isDate(dt)) {
  12. ret = dateFormat(dt, format || this.dateFormat);
  13. }
  14. return ret;
  15. }

stringToDate Function Public


Defined time.js

Converts a date string to a Date

Example
  1. var date = new Date(2004, 1,1,0,0,0);
  2. patio.stringToDate('2004-02-01'); //=> date
  3.  
  4. patio.dateFormat = patio.TWO_YEAR_DATE_FORMAT;
  5. patio.stringToDate('04-02-01'); //=> date
Arguments Returns Throws Source
  1. function (dt,format){
  2. var ret;
  3. if (this.convertTwoDigitYears) {
  4. ret = date.parse(dt, this.TWO_YEAR_DATE_FORMAT);
  5. }
  6. if (!ret) {
  7. ret = date.parse(dt, format || this.dateFormat);
  8. }
  9. if (!ret) {
  10. throw new PatioError("Unable to convert date: " + dt);
  11. }
  12. return ret;
  13. }

stringToDateTime Function Public


Defined time.js

Converts a datetime date string to a patio.sql.DateTime

Example
  1. var dateTime = new sql.DateTime(2004, 1, 1, 12, 12, 12),
  2. offset = getTimeZoneOffset();
  3. patio.stringToDateTime('2004-02-01 12:12:12'); //=> dateTime
  4.  
  5. patio.dateTimeFormat = patio.DATETIME_TWO_YEAR_FORMAT;
  6. patio.stringToDateTime('04-02-01 12:12:12-0600'); //=> dateTime
  7.  
  8. patio.dateTimeFormat = patio.DATETIME_FORMAT_TZ;
  9. patio.stringToDateTime('2004-02-01 12:12:12-0600'); //=> dateTime
  10.  
  11. patio.dateTimeFormat = patio.ISO_8601;
  12. patio.stringToDateTime('2004-02-01T12:12:12-0600'); //=> dateTime
  13.  
  14. patio.dateTimeFormat = patio.ISO_8601_TWO_YEAR;
  15. patio.stringToDateTime('04-02-01T12:12:12-0600'); //=> dateTime
Arguments Returns Throws Source
  1. function (dt,fmt){
  2. var useT = dt.indexOf("T") !== -1;
  3. //test if there is a T in the string so we can try to properly convert it
  4. var format = fmt ? fmt : useT ? this.ISO_8601 : this.DEFAULT_DATETIME_FORMAT;
  5. var ret = date.parse(dt, format);
  6. //if the coversion failed try it with a time zone
  7. !ret && (ret = date.parse(dt, this.DATETIME_FORMAT_TZ));
  8. if (!ret && this.convertTwoDigitYears) {
  9. //if we still fail and we need to convert two digit years try the twoYearFormat
  10. var twoYearFormat = fmt ? fmt : useT ? this.ISO_8601_TWO_YEAR : this.DATETIME_TWO_YEAR_FORMAT;
  11. ret = date.parse(dt, twoYearFormat);
  12. //try with time zone
  13. !ret && (ret = date.parse(dt, twoYearFormat + "Z"));
  14. }
  15. if (!ret) {
  16. throw new PatioError("Unable to convert datetime: " + dt);
  17. }
  18. return new SQL.DateTime(ret);
  19. }

stringToTime Function Public


Defined time.js

Converts a time date string to a patio.sql.Time

Example
  1. var time = new sql.Time(12,12,12);
  2. patio.stringToTime("12:12:12"); //=> time
Arguments Returns Throws Source
  1. function (dt,format){
  2. var ret = date.parse(dt, format || this.timeFormat);
  3. if (!ret) {
  4. throw new PatioError("Unable to convert time: " + dt);
  5. }
  6. return new SQL.Time(ret);
  7. }

stringToTimeStamp Function Public


Defined time.js

Converts a timestamp date string to a patio.sql.TimeStamp

Example
  1. var timeStamp = new sql.TimeStamp(2004, 1, 1, 12, 12, 12);
  2. patio.stringToTimeStamp('2004-02-01 12:12:12'); //=> timeStamp
  3.  
  4. patio.timeStampFormat = patio.TIMESTAMP_TWO_YEAR_FORMAT;
  5. patio.stringToTimeStamp('04-02-01 12:12:12-0600'); //=> timeStamp
  6.  
  7. patio.timeStampFormat = patio.TIMESTAMP_FORMAT_TZ;
  8. patio.stringToTimeStamp('2004-02-01 12:12:12-0600'); //=> timeStamp
  9.  
  10. patio.timeStampFormat = patio.ISO_8601;
  11. patio.stringToTimeStamp('2004-02-01T12:12:12-0600'); //=> timeStamp
  12.  
  13. patio.timeStampFormat = patio.ISO_8601_TWO_YEAR;
  14. patio.stringToTimeStamp('04-02-01T12:12:12-0600'); //=> timeStamp
Arguments Returns Throws Source
  1. function (dt,fmt){
  2. var useT = dt.indexOf("T") !== -1;
  3. //test if there is a T in the string so we can try to properly convert it
  4. var format = fmt ? fmt : useT ? this.ISO_8601 : this.DEFAULT_TIMESTAMP_FORMAT;
  5. var ret = date.parse(dt, format);
  6. //if the coversion failed try it with a time zone
  7. !ret && (ret = date.parse(dt, this.TIMESTAMP_FORMAT_TZ));
  8. if (!ret && this.convertTwoDigitYears) {
  9. //if we still fail and we need to convert two digit years try the twoYearFormat
  10. var twoYearFormat = fmt ? fmt : useT ? this.ISO_8601_TWO_YEAR : this.TIMESTAMP_TWO_YEAR_FORMAT;
  11. ret = date.parse(dt, twoYearFormat);
  12. //try with time zone
  13. !ret && (ret = date.parse(dt, twoYearFormat + "Z"));
  14. }
  15. if (!ret) {
  16. throw new PatioError("Unable to convert timestamp: " + dt);
  17. }
  18. return new SQL.TimeStamp(ret);
  19. }

stringToYear Function Public


Defined time.js

Converts a year date string to a patio.sql.Year

Example
  1. var year = new sql.Year(2004);
  2. patio.stringToYear("2004"); //=> year
  3. patio.yearFormat = "yy";
  4. patio.stringToYear("04"); //=> year
Arguments Returns Throws Source
  1. function (dt,format){
  2. var ret = date.parse(dt, format || this.yearFormat);
  3. if (!ret) {
  4. throw new PatioError("Unable to convert year: " + dt);
  5. }
  6. return new SQL.Year(ret);
  7. }

timeStampToString Function Public


Defined time.js

Converts a patio.sql.TimeStamp to a string. The format used is patio.Time#timeStampFormat, which defaults to patio.Time#DEFAULT_TIMESTAMP_FORMAT

Example
  1. var date = new Date(2004, 1, 1, 12, 12, 12),
  2. dateTime = new sql.TimeStamp(2004, 1, 1, 12, 12, 12),
  3. offset = "-0600";
  4. patio.timeStampToString(date); //=> '2004-02-01 12:12:12'
  5. patio.timeStampToString(dateTime); //=> '2004-02-01 12:12:12'
  6.  
  7. patio.timeStampFormat = patio.TIMESTAMP_TWO_YEAR_FORMAT;
  8. patio.timeStampToString(date); //=> '04-02-01 12:12:12'
  9. patio.timeStampToString(dateTime); //=> '04-02-01 12:12:12'
  10.  
  11. patio.timeStampFormat = patio.TIMESTAMP_FORMAT_TZ;
  12. patio.timeStampToString(date); //=> '2004-02-01 12:12:12-0600'
  13. patio.timeStampToString(dateTime); //=> '2004-02-01 12:12:12-0600'
  14.  
  15. patio.timeStamp = patio.ISO_8601;
  16. patio.timeStampToString(date); //=> '2004-02-01T12:12:12-0600'
  17. patio.timeStampToString(dateTime); //=> '2004-02-01T12:12:12-0600'
  18.  
  19. patio.timeStamp = patio.ISO_8601_TWO_YEAR;
  20. patio.timeStampToString(date); //=> '04-02-01T12:12:12-0600'
  21. patio.timeStampToString(dateTime); //=> '04-02-01T12:12:12-0600'
Arguments Returns Source
  1. function (dt,format){
  2. return dateFormat(isInstanceOf(dt, SQL.TimeStamp) ? dt.date : dt, format || this.timeStampFormat);
  3. }

timeToString Function Public


Defined time.js

Converts a sql.Time to a string. The format used is patio.Time#timeFormat, which defaults to patio.Time#DEFAULT_TIME_FORMAT

Example
  1. var date = new Date(null, null, null, 13, 12, 12),
  2. time = new sql.Time(13,12,12);
  3. patio.timeToString(date); //=> '13:12:12'
  4. patio.timeToString(time); //=> '13:12:12'
  5. patio.timeFormat = "hh:mm:ss";
  6. patio.timeToString(date); //=> '01:12:12'
  7. patio.timeToString(time); //=> '01:12:12'
Arguments Returns Source
  1. function (dt,format){
  2. return dateFormat(isInstanceOf(dt, SQL.Time) ? dt.date : dt, format || this.timeFormat);
  3. }

yearToString Function Public


Defined time.js

Converts a patio.sql.Year to a string. The format used is patio.Time#yearFormat, which defaults to patio.Time#DEFAULT_YEAR_FORMAT

Example
  1. var date = new Date(2004, 1, 1, 1, 1, 1),
  2. year = new sql.Year(2004);
  3. patio.yearToString(date); //=> '2004'
  4. patio.yearToString(year); //=> '2004'
  5. patio.yearFormat = "yy";
  6. patio.yearToString(date); //=> '04'
  7. patio.yearToString(year); //=> '04'
Arguments Returns Source
  1. function (dt,format){
  2. return dateFormat(isInstanceOf(dt, SQL.Year) ? dt.date : dt, format || this.yearFormat);
  3. }

Documentation generated using coddoc.