Changeset 8669

Show
Ignore:
Timestamp:
05/21/07 06:37:30 (20 months ago)
Author:
pottedmeat
Message:

fixes #3079. Fix getTimezone, weekdays, Jan 1 calculation, and support overrides

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojox/trunk/date/php.js

    r8661 r8669  
    22dojo.require("dojo.date"); 
    33 
    4 dojox.date.php.format = function(/*Date*/ date, /*String*/ format){ 
     4dojox.date.php.format = function(/*Date*/ date, /*String*/ format, /*Object?*/ overrides){ 
    55        // summary: Get a formatted string for a given date object 
    66        var df = new dojox.date.php.DateFormat(date); 
    7         return df.format(format);        
     7        return df.format(format, overrides);     
    88} 
    99 
    10 dojox.date.php.DateFormat = function(date){ 
     10dojox.date.php.DateFormat = function(/*Date*/ date){ 
    1111        this.date = date; 
    1212} 
     
    1818        monthdays: [31,28,31,30,31,30,31,31,30,31,30,31], 
    1919 
    20         format: function(/*String*/ format){ 
     20        format: function(/*String*/ format, /*Object?*/ overrides){ 
    2121                // summary: Format the internal date object 
    2222                var parts = []; 
    2323                for(var i = 0; i < format.length; i++){ 
    2424                        var chr = format.charAt(i); 
    25                         if(typeof this[chr] == "function"){ 
     25                        if(overrides && typeof overrides[chr] == "function"){ 
     26                                parts.push(overrides[chr].call(this)); 
     27                        }else if(typeof this[chr] == "function"){ 
    2628                                parts.push(this[chr]()); 
    2729                        }else{ 
     
    4244        D: function(){ 
    4345                // summary: A textual representation of a day, three letters 
    44                 return weekdays_3[this.date.getDay()]; 
     46                return this.weekdays_3[this.date.getDay()]; 
    4547        }, 
    4648 
     
    5254        l: function(){ 
    5355                // summary: A full textual representation of the day of the week 
    54                 return weekdays[this.date.getDay()]; 
     56                return this.weekdays[this.date.getDay()]; 
    5557        }, 
    5658         
     
    7981        z: function(){ 
    8082                // summary: The day of the year (starting from 0) 
    81                 var millis = this.date.getTime() - new Date(this.date.getYear(), 1, 1).getTime(); 
     83                var millis = this.date.getTime() - new Date(this.date.getFullYear(), 0, 1).getTime(); 
    8284                return Math.floor(millis/86400000) + ""; 
    8385        }, 
     
    8890                // summary: ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) 
    8991                var week; 
    90                 var jan1_w = new Date(this.date.getYear(), 1, 1).getDay() + 1; 
     92                var jan1_w = new Date(this.date.getFullYear(), 0, 1).getDay() + 1; 
    9193                var w = this.date.getDay() + 1; 
    9294                var z = parseInt(this.z()); 
    9395 
    9496                if(z <= (8 - jan1_w) && jan1_w > 4){ 
    95                         if(jan1_w == 5 || (jan1_w == 6 && Boolean(this.L()))){ 
     97                        var last_year = new Date(this.date.getFullYear() - 1, this.date.getMonth(), this.date.getDate()); 
     98                        if(jan1_w == 5 || (jan1_w == 6 && dojo.date.isLeapYear(last_year))){ 
    9699                                week = 53; 
    97100                        }else{ 
     
    109112                        }else{ 
    110113                                var j = z + (7 - w) + (jan1_w - 1); 
    111                                 week = j / 7; 
     114                                week = Math.ceil(j / 7); 
    112115                                if(jan1_w > 4){ 
    113116                                        --week; 
     
    242245        O: function(){ 
    243246                // summary: Difference to Greenwich time (GMT) in hours 
    244                 var off = Math.abs(this.date.getTimeZoneOffset()); 
     247                var off = Math.abs(this.date.getTimezoneOffset()); 
    245248                var hours = Math.floor(off / 60) + ""; 
    246249                var mins = (off % 60) + ""; 
     
    267270                //              Timezone offset in seconds. The offset for timezones west of UTC is always negative, 
    268271                //              and for those east of UTC is always positive. 
    269                 return this.date.getTimeZoneOffset() * -60; 
     272                return this.date.getTimezoneOffset() * -60; 
    270273        }, 
    271274