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
var 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 Returns Source
function (dt,format){
   return dateFormat(isInstanceOf(dt, SQL.DateTime) ? dt.date : dt, format || this.dateTimeFormat);
           
}
    

dateToString Function Public


Defined time.js

Converts a date to a string.

Example
var 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 Returns Source
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;
           
}
    

stringToDate Function Public


Defined time.js

Converts a date string to a Date

Example
var 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'); //=> date
        
Arguments Returns Throws Source
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;
           
}
    

stringToDateTime Function Public


Defined time.js

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

Example
var 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'); //=> dateTime
        
Arguments Returns Throws Source
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);
           
}
    

stringToTime Function Public


Defined time.js

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

Example
var time = new sql.Time(12,12,12);
patio.stringToTime("12:12:12"); //=> time
        
Arguments Returns Throws Source
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);
           
}
    

stringToTimeStamp Function Public


Defined time.js

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

Example
var 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'); //=> timeStamp
        
Arguments Returns Throws Source
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);
           
}
    

stringToYear Function Public


Defined time.js

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

Example
var year = new sql.Year(2004);
patio.stringToYear("2004"); //=> year
patio.yearFormat = "yy";
patio.stringToYear("04"); //=> year
        
Arguments Returns Throws Source
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);
           
}
    

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
var 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 Returns Source
function (dt,format){
   return dateFormat(isInstanceOf(dt, SQL.TimeStamp) ? dt.date : dt, format || this.timeStampFormat);
           
}
    

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
var 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 Returns Source
function (dt,format){
   return dateFormat(isInstanceOf(dt, SQL.Time) ? dt.date : dt, format || this.timeFormat);
           
}
    

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
var 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 Returns Source
function (dt,format){
   return dateFormat(isInstanceOf(dt, SQL.Year) ? dt.date : dt, format || this.yearFormat);
           
}
    

Documentation generated using coddoc.