~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/datatype-date-math/datatype-date-math-debug.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-15 18:14:08 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120315181408-zgl94hzo0x4n99an
Tags: 0.1+bzr295+dfsg-0ubuntu2
* debian/patches:
  - 01-fix-database-settings.patch: Update to set PSERV_URL.
  - 02-pserv-config.patch: Set port to 8001.
* debian/maas.postinst: Run maas-import-isos on install.
* debian/control: Depends on rabbitmq-server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.4.1 (build 4118)
 
3
Copyright 2011 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('datatype-date-math', function(Y) {
 
8
 
 
9
/**
 
10
 * Parse number submodule.
 
11
 *
 
12
 * @module datatype
 
13
 * @submodule datatype-date-parse
 
14
 * @for DataType.Date
 
15
 */
 
16
var LANG = Y.Lang;
 
17
 
 
18
Y.mix(Y.namespace("DataType.Date"), {
 
19
 
 
20
        /**
 
21
         * Checks whether a native JavaScript Date contains a valid value.
 
22
         * @for DataType.Date
 
23
         * @method isValidDate
 
24
         * @param oDate {Date} Date in the month for which the number of days is desired.
 
25
         * @return {Boolean} True if the date argument contains a valid value.
 
26
         */
 
27
         isValidDate : function (oDate) {
 
28
                if(LANG.isDate(oDate) && (isFinite(oDate)) && (oDate != "Invalid Date") && !isNaN(oDate) && (oDate != null)) {
 
29
            return true;
 
30
        }
 
31
        else {
 
32
            Y.log("Could not validate data " + LANG.dump(oDate) + " as type Date", "warn", "date");
 
33
            return false;
 
34
        }
 
35
        },
 
36
        
 
37
        areEqual : function (aDate, bDate) {
 
38
                return (this.isValidDate(aDate) && this.isValidDate(bDate) && (aDate.getTime() == bDate.getTime()));    
 
39
        },
 
40
 
 
41
    isGreater : function (aDate, bDate) {
 
42
        return (this.isValidDate(aDate) && this.isValidDate(bDate) && (aDate.getTime() > bDate.getTime()));
 
43
    },
 
44
 
 
45
    isGreaterOrEqual : function (aDate, bDate) {
 
46
        return (this.isValidDate(aDate) && this.isValidDate(bDate) && (aDate.getTime() >= bDate.getTime()));
 
47
    },
 
48
 
 
49
        addMonths : function (oDate, numMonths) {
 
50
                var newYear = oDate.getFullYear();
 
51
                var newMonth = oDate.getMonth() + numMonths;            
 
52
                
 
53
                newYear  = Math.floor(newYear + newMonth / 12);
 
54
                newMonth = (newMonth % 12 + 12) % 12;
 
55
                
 
56
                var newDate = new Date (oDate.getTime());
 
57
                newDate.setYear(newYear);
 
58
                newDate.setMonth(newMonth);
 
59
                
 
60
                return newDate;
 
61
        },
 
62
        
 
63
        addYears : function (oDate, numYears) {
 
64
                var newYear = oDate.getFullYear() + numYears;
 
65
                var newDate = new Date(oDate.getTime());
 
66
                
 
67
                newDate.setYear(newYear);
 
68
                return newDate;
 
69
        },
 
70
 
 
71
    listOfDatesInMonth : function (oDate) {
 
72
       if (!this.isValidDate(oDate)) {
 
73
         return [];
 
74
       }
 
75
 
 
76
       var daysInMonth = this.daysInMonth(oDate),
 
77
           year        = oDate.getFullYear(),
 
78
           month       = oDate.getMonth(),
 
79
           output      = [];
 
80
 
 
81
       for (var day = 1; day <= daysInMonth; day++) {
 
82
           output.push(new Date(year, month, day, 12, 0, 0));
 
83
       }
 
84
 
 
85
       return output;
 
86
    },
 
87
 
 
88
        /**
 
89
         * Takes a native JavaScript Date and returns the number of days in the month that the given date belongs to.
 
90
         * @for DataType.Date
 
91
         * @method daysInMonth
 
92
         * @param oDate {Date} Date in the month for which the number of days is desired.
 
93
         * @return {Number} A number (either 28, 29, 30 or 31) of days in the given month.
 
94
         */
 
95
         daysInMonth : function (oDate) {
 
96
                if (!this.isValidDate(oDate)) {
 
97
                        return 0;
 
98
                }
 
99
                
 
100
                var mon = oDate.getMonth();
 
101
                var lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
 
102
 
 
103
                if (mon != 1) {
 
104
                        return lengths[mon];
 
105
                }
 
106
                else {
 
107
 
 
108
                        var year = oDate.getFullYear();
 
109
                        if (year%400 === 0) {
 
110
                               return 29;
 
111
                        }       
 
112
                        else if (year%100 === 0) {
 
113
                                   return 28;
 
114
                        }
 
115
                        else if (year%4 === 0) {
 
116
                               return 29;
 
117
                        }
 
118
                        else {
 
119
                               return 28;
 
120
                    }
 
121
           } 
 
122
        }
 
123
 
 
124
});
 
125
 
 
126
 
 
127
}, '3.4.1' ,{requires:['yui-base']});