dojox/date/php.js

  • Provides:

    • dojox.date.php
  • Requires:

    • dojo.date in common in project dojo
    • dojox.string.tokenize in common
  • dojox.date.php.format

    • type
      Function
    • parameters:
      • date: (typeof Date)
      • format: (typeof String)
    • source: [view]
       var df = new dojox.date.php.DateFormat(format);
       return df.format(date);
    • summary
      Get a formatted string for a given date object
  • dojox.date.php.DateFormat

    • type
      Function
    • parameters:
      • format: (typeof String)
    • source: [view]
       if(!this.regex){
        var keys = [];
        for(var key in this.constructor.prototype){
         if(dojo.isString(key) && key.length == 1 && dojo.isFunction(this[key])){
          keys.push(key);
         }
        }
        this.constructor.prototype.regex = new RegExp("(?:(\\\\.)|([" + keys.join("") + "]))", "g");
       }


       var replacements = [];


       this.tokens = dojox.string.tokenize(format, this.regex, function(escape, token, i){
        if(token){
         replacements.push([i, token]);
         return token;
        }
        if(escape){
         return escape.charAt(1);
        }
       });


       this.replacements = replacements;
    • summary
      Format the internal date object
  • dojox.date.php.DateFormat.constructor.prototype.regex

    • summary
  • dojox.date.php.DateFormat.tokens

    • summary
  • dojox.date.php.DateFormat.replacements

    • summary
  • dojox.date.php.DateFormat.weekdays

    • summary
  • dojox.date.php.DateFormat.weekdays_3

    • summary
  • dojox.date.php.DateFormat.months

    • summary
  • dojox.date.php.DateFormat.months_3

    • summary
  • dojox.date.php.DateFormat.monthdays

    • summary
  • dojox.date.php.DateFormat.format

    • type
      Function
    • parameters:
      • date: (typeof Date)
    • source: [view]
        this.date = date;
        for(var i = 0, replacement; replacement = this.replacements[i]; i++){
         this.tokens[replacement[0]] = this[replacement[1]]();
        }
        return this.tokens.join("");
    • summary
  • dojox.date.php.DateFormat.date

    • summary
  • dojox.date.php.DateFormat.d

    • type
      Function
    • source: [view]
        var j = this.j();
        return (j.length == 1) ? "0" + j : j;
    • summary
      Day of the month, 2 digits with leading zeros
  • dojox.date.php.DateFormat.D

    • type
      Function
    • source: [view]
        return this.weekdays_3[this.date.getDay()];
    • summary
      A textual representation of a day, three letters
  • dojox.date.php.DateFormat.j

    • type
      Function
    • source: [view]
        return this.date.getDate() + "";
    • summary
      Day of the month without leading zeros
  • dojox.date.php.DateFormat.l

    • type
      Function
    • source: [view]
        return this.weekdays[this.date.getDay()];
    • summary
      A full textual representation of the day of the week
  • dojox.date.php.DateFormat.N

    • type
      Function
    • source: [view]
        var w = this.w();
        return (!w) ? 7 : w;
    • summary
      ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)
  • dojox.date.php.DateFormat.S

    • type
      Function
    • source: [view]
        switch(this.date.getDate()){
         case 11: case 12: case 13: return "th";
         case 1: case 21: case 31: return "st";
         case 2: case 22: return "nd";
         case 3: case 23: return "rd";
         default: return "th";
        }
    • summary
      English ordinal suffix for the day of the month, 2 characters
  • dojox.date.php.DateFormat.w

    • type
      Function
    • source: [view]
        return this.date.getDay() + "";
    • summary
      Numeric representation of the day of the week
  • dojox.date.php.DateFormat.z

    • type
      Function
    • source: [view]
        var millis = this.date.getTime() - new Date(this.date.getFullYear(), 0, 1).getTime();
        return Math.floor(millis/86400000) + "";
    • summary
      The day of the year (starting from 0)
  • dojox.date.php.DateFormat.W

    • type
      Function
    • source: [view]
        var week;
        var jan1_w = new Date(this.date.getFullYear(), 0, 1).getDay() + 1;
        var w = this.date.getDay() + 1;
        var z = parseInt(this.z());


        if(z <= (8 - jan1_w) && jan1_w > 4){
         var last_year = new Date(this.date.getFullYear() - 1, this.date.getMonth(), this.date.getDate());
         if(jan1_w == 5 || (jan1_w == 6 && dojo.date.isLeapYear(last_year))){
          week = 53;
         }else{
          week = 52;
         }
        }else{
         var i;
         if(Boolean(this.L())){
          i = 366;
         }else{
          i = 365;
         }
         if((i - z) < (4 - w)){
          week = 1;
         }else{
          var j = z + (7 - w) + (jan1_w - 1);
          week = Math.ceil(j / 7);
          if(jan1_w > 4){
           --week;
          }
         }
        }

        
        return week;
    • summary
      ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
  • dojox.date.php.DateFormat.F

    • type
      Function
    • source: [view]
        return this.months[this.date.getMonth()];
    • summary
      A full textual representation of a month, such as January or March
  • dojox.date.php.DateFormat.m

    • type
      Function
    • source: [view]
        var n = this.n();
        return (n.length == 1) ? "0" + n : n;
    • summary
      Numeric representation of a month, with leading zeros
  • dojox.date.php.DateFormat.M

    • type
      Function
    • source: [view]
        return this.months_3[this.date.getMonth()];
    • summary
      A short textual representation of a month, three letters
  • dojox.date.php.DateFormat.n

    • type
      Function
    • source: [view]
        return this.date.getMonth() + 1 + "";
    • summary
      Numeric representation of a month, without leading zeros
  • dojox.date.php.DateFormat.t

    • type
      Function
    • source: [view]
        return (Boolean(this.L()) && this.date.getMonth() == 1) ? 29 : this.monthdays[this.getMonth()];
    • summary
      Number of days in the given month
  • dojox.date.php.DateFormat.L

    • type
      Function
    • source: [view]
        return (dojo.date.isLeapYear(this.date)) ? "1" : "0";
    • summary
      Whether it's a leap year
  • dojox.date.php.DateFormat.o

    • type
      Function
    • source: [view]
        // summary:
        //  ISO-8601 year number. This has the same value as Y, except that if
        //  the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
        // TODO: Figure out what this means
    • summary
      ISO-8601 year number. This has the same value as Y, except that if
      the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
      TODO: Figure out what this means
  • dojox.date.php.DateFormat.Y

    • type
      Function
    • source: [view]
        return this.date.getFullYear() + "";
    • summary
      A full numeric representation of a year, 4 digits
  • dojox.date.php.DateFormat.y

    • type
      Function
    • source: [view]
        return this.Y().slice(-2);
    • summary
      A two digit representation of a year
  • dojox.date.php.DateFormat.a

    • type
      Function
    • source: [view]
        return this.date.getHours() >= 12 ? "pm" : "am";
    • summary
      Lowercase Ante meridiem and Post meridiem
  • dojox.date.php.DateFormat.b

    • type
      Function
    • source: [view]
        return this.a().toUpperCase();
    • summary
      Uppercase Ante meridiem and Post meridiem
  • dojox.date.php.DateFormat.B

    • type
      Function
    • source: [view]
        var off = this.date.getTimezoneOffset() + 60;
        var secs = (this.date.getHours() * 3600) + (this.date.getMinutes() * 60) + this.getSeconds() + (off * 60);
        var beat = Math.abs(Math.floor(secs / 86.4) % 1000) + "";
        while(beat.length < 2) beat = "0" + beat;
        return beat;
    • summary
      Swatch Internet time
      A day is 1,000 beats. All time is measured from GMT + 1
  • dojox.date.php.DateFormat.g

    • type
      Function
    • source: [view]
        return (this.date.getHours() > 12) ? this.date.getHours() - 12 + "" : this.date.getHours() + "";
    • summary
      12-hour format of an hour without leading zeros
  • dojox.date.php.DateFormat.G

    • type
      Function
    • source: [view]
        return this.date.getHours() + "";
    • summary
      24-hour format of an hour without leading zeros
  • dojox.date.php.DateFormat.h

    • type
      Function
    • source: [view]
        var g = this.g();
        return (g.length == 1) ? "0" + g : g;
    • summary
      12-hour format of an hour with leading zeros
  • dojox.date.php.DateFormat.H

    • type
      Function
    • source: [view]
        var G = this.G();
        return (G.length == 1) ? "0" + G : G;
    • summary
      24-hour format of an hour with leading zeros
  • dojox.date.php.DateFormat.i

    • type
      Function
    • source: [view]
        var mins = this.date.getMinutes() + "";
        return (mins.length == 1) ? "0" + mins : mins;
    • summary
      Minutes with leading zeros
  • dojox.date.php.DateFormat.s

    • type
      Function
    • source: [view]
        var secs = this.date.getSeconds() + "";
        return (secs.length == 1) ? "0" + secs : secs;
    • summary
      Seconds, with leading zeros
  • dojox.date.php.DateFormat.e

    • type
      Function
    • source: [view]
        return dojo.date.getTimezoneName(this.date);
    • summary
      Timezone identifier (added in PHP 5.1.0)
  • dojox.date.php.DateFormat.I

    • type
      Function
    • source: [view]
        // summary: Whether or not the date is in daylight saving time
        // TODO: Can dojo.date do this?
    • summary
      Whether or not the date is in daylight saving time
      TODO: Can dojo.date do this?
  • dojox.date.php.DateFormat.O

    • type
      Function
    • source: [view]
        var off = Math.abs(this.date.getTimezoneOffset());
        var hours = Math.floor(off / 60) + "";
        var mins = (off % 60) + "";
        if(hours.length == 1) hours = "0" + hours;
        if(mins.length == 1) hours = "0" + mins;
        return ((this.date.getTimezoneOffset() < 0) ? "+" : "-") + hours + mins;
    • summary
      Difference to Greenwich time (GMT) in hours
  • dojox.date.php.DateFormat.P

    • type
      Function
    • source: [view]
        var O = this.O();
        return O.substring(0, 2) + ":" + O.substring(2, 4);
    • summary
      Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)
  • dojox.date.php.DateFormat.T

    • type
      Function
    • source: [view]
      dojo.provide("dojox.date.php");
      dojo.require("dojo.date");
      dojo.require("dojox.string.tokenize");


      dojox.date.php.format = function(/*Date*/ date, /*String*/ format){
       // summary: Get a formatted string for a given date object
       var df = new dojox.date.php.DateFormat(format);
       return df.format(date);
      }


      dojox.date.php.DateFormat = function(/*String*/ format){
       // summary: Format the internal date object
       if(!this.regex){
        var keys = [];
        for(var key in this.constructor.prototype){
         if(dojo.isString(key) && key.length == 1 && dojo.isFunction(this[key])){
          keys.push(key);
         }
        }
        this.constructor.prototype.regex = new RegExp("(?:(\\\\.)|([" + keys.join("") + "]))", "g");
       }


       var replacements = [];


       this.tokens = dojox.string.tokenize(format, this.regex, function(escape, token, i){
        if(token){
         replacements.push([i, token]);
         return token;
        }
        if(escape){
         return escape.charAt(1);
        }
       });


       this.replacements = replacements;
      }
      dojo.extend(dojox.date.php.DateFormat, {
       weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
       weekdays_3: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
       months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
       months_3: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
       monthdays: [31,28,31,30,31,30,31,31,30,31,30,31],


       format: function(/*Date*/ date){
        this.date = date;
        for(var i = 0, replacement; replacement = this.replacements[i]; i++){
         this.tokens[replacement[0]] = this[replacement[1]]();
        }
        return this.tokens.join("");
       },


       // Day


       d: function(){
        // summary: Day of the month, 2 digits with leading zeros
        var j = this.j();
        return (j.length == 1) ? "0" + j : j;
       },


       D: function(){
        // summary: A textual representation of a day, three letters
        return this.weekdays_3[this.date.getDay()];
       },


       j: function(){
        // summary: Day of the month without leading zeros
        return this.date.getDate() + "";
       },


       l: function(){
        // summary: A full textual representation of the day of the week
        return this.weekdays[this.date.getDay()];
       },

       
       N: function(){
        // summary: ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)
        var w = this.w();
        return (!w) ? 7 : w;
       },


       S: function(){
        // summary: English ordinal suffix for the day of the month, 2 characters
        switch(this.date.getDate()){
         case 11: case 12: case 13: return "th";
         case 1: case 21: case 31: return "st";
         case 2: case 22: return "nd";
         case 3: case 23: return "rd";
         default: return "th";
        }
       },


       w: function(){
        // summary: Numeric representation of the day of the week
        return this.date.getDay() + "";
       },


       z: function(){
        // summary: The day of the year (starting from 0)
        var millis = this.date.getTime() - new Date(this.date.getFullYear(), 0, 1).getTime();
        return Math.floor(millis/86400000) + "";
       },


       // Week


       W: function(){
        // summary: ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
        var week;
        var jan1_w = new Date(this.date.getFullYear(), 0, 1).getDay() + 1;
        var w = this.date.getDay() + 1;
        var z = parseInt(this.z());


        if(z <= (8 - jan1_w) && jan1_w > 4){
         var last_year = new Date(this.date.getFullYear() - 1, this.date.getMonth(), this.date.getDate());
         if(jan1_w == 5 || (jan1_w == 6 && dojo.date.isLeapYear(last_year))){
          week = 53;
         }else{
          week = 52;
         }
        }else{
         var i;
         if(Boolean(this.L())){
          i = 366;
         }else{
          i = 365;
         }
         if((i - z) < (4 - w)){
          week = 1;
         }else{
          var j = z + (7 - w) + (jan1_w - 1);
          week = Math.ceil(j / 7);
          if(jan1_w > 4){
           --week;
          }
         }
        }

        
        return week;
       },


       // Month


       F: function(){
        // summary: A full textual representation of a month, such as January or March
        return this.months[this.date.getMonth()];
       },


       m: function(){
        // summary: Numeric representation of a month, with leading zeros
        var n = this.n();
        return (n.length == 1) ? "0" + n : n;
       },


       M: function(){
        // summary: A short textual representation of a month, three letters
        return this.months_3[this.date.getMonth()];
       },


       n: function(){
        // summary: Numeric representation of a month, without leading zeros
        return this.date.getMonth() + 1 + "";
       },


       t: function(){
        // summary: Number of days in the given month
        return (Boolean(this.L()) && this.date.getMonth() == 1) ? 29 : this.monthdays[this.getMonth()];
       },


       // Year


       L: function(){
        // summary: Whether it's a leap year
        return (dojo.date.isLeapYear(this.date)) ? "1" : "0";
       },


       o: function(){
        // summary:
        //  ISO-8601 year number. This has the same value as Y, except that if
        //  the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
        // TODO: Figure out what this means
       },


       Y: function(){
        // summary: A full numeric representation of a year, 4 digits
        return this.date.getFullYear() + "";
       },


       y: function(){
        // summary: A two digit representation of a year
        return this.Y().slice(-2);
       },


       // Time


       a: function(){
        // summary: Lowercase Ante meridiem and Post meridiem
        return this.date.getHours() >= 12 ? "pm" : "am";
       },


       b: function(){
        // summary: Uppercase Ante meridiem and Post meridiem
        return this.a().toUpperCase();
       },


       B: function(){
        // summary:
        // Swatch Internet time
        // A day is 1,000 beats. All time is measured from GMT + 1
        var off = this.date.getTimezoneOffset() + 60;
        var secs = (this.date.getHours() * 3600) + (this.date.getMinutes() * 60) + this.getSeconds() + (off * 60);
        var beat = Math.abs(Math.floor(secs / 86.4) % 1000) + "";
        while(beat.length < 2) beat = "0" + beat;
        return beat;
       },


       g: function(){
        // summary: 12-hour format of an hour without leading zeros
        return (this.date.getHours() > 12) ? this.date.getHours() - 12 + "" : this.date.getHours() + "";
       },


       G: function(){
        // summary: 24-hour format of an hour without leading zeros
        return this.date.getHours() + "";
       },


       h: function(){
        // summary: 12-hour format of an hour with leading zeros
        var g = this.g();
        return (g.length == 1) ? "0" + g : g;
       },


       H: function(){
        // summary: 24-hour format of an hour with leading zeros
        var G = this.G();
        return (G.length == 1) ? "0" + G : G;
       },


       i: function(){
        // summary: Minutes with leading zeros
        var mins = this.date.getMinutes() + "";
        return (mins.length == 1) ? "0" + mins : mins;
       },


       s: function(){
        // summary: Seconds, with leading zeros
        var secs = this.date.getSeconds() + "";
        return (secs.length == 1) ? "0" + secs : secs;
       },


       // Timezone


       e: function(){
        // summary: Timezone identifier (added in PHP 5.1.0)
        return dojo.date.getTimezoneName(this.date);
       },


       I: function(){
        // summary: Whether or not the date is in daylight saving time
        // TODO: Can dojo.date do this?
       },


       O: function(){
        // summary: Difference to Greenwich time (GMT) in hours
        var off = Math.abs(this.date.getTimezoneOffset());
        var hours = Math.floor(off / 60) + "";
        var mins = (off % 60) + "";
        if(hours.length == 1) hours = "0" + hours;
        if(mins.length == 1) hours = "0" + mins;
        return ((this.date.getTimezoneOffset() < 0) ? "+" : "-") + hours + mins;
       },


       P: function(){
        // summary: Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)
        var O = this.O();
        return O.substring(0, 2) + ":" + O.substring(2, 4);
       },


       T: function(){
        // summary: Timezone abbreviation


        // Guess...
        return this.e().substring(0, 3);
    • summary
  • dojox.date.php.DateFormat.Z

    • type
      Function
    • source: [view]
        return this.date.getTimezoneOffset() * -60;
    • summary
      Timezone offset in seconds. The offset for timezones west of UTC is always negative,
      and for those east of UTC is always positive.
  • dojox.date.php.DateFormat.c

    • type
      Function
    • source: [view]
        return this.Y() + "-" + this.m() + "-" + this.d() + "T" + this.h() + ":" + this.i() + ":" + this.s() + this.P();
    • summary
      ISO 8601 date (added in PHP 5)
  • dojox.date.php.DateFormat.r

    • type
      Function
    • source: [view]
        return this.D() + ", " + this.d() + " " + this.M() + " " + this.Y() + " " + this.H() + ":" + this.i() + ":" + this.s() + " " + this.O();
    • summary
      RFC 2822 formatted date
  • dojox.date.php.DateFormat.U

    • type
      Function
    • source: [view]
        return Math.floor(this.date.getTime() / 1000);
    • summary
      Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  • dojox.date.php

    • type
      Object
    • summary
  • dojox.date

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary