Debian Codegraph @

dojox/date/buddhist/Date.js

raw symbols SCIP
1 define([
2 "dojo/_base/lang",
3 "dojo/_base/declare",
4 "dojo/date"
5 ], function(lang, declare, dd){
6
7 var BDate = declare("dojox.date.buddhist.Date", null, {
8
9 _date: 0,
10 _month: 0,
11 _year: 0,
12 _hours: 0,
13 _minutes: 0,
14 _seconds: 0,
15 _milliseconds: 0,
16 _day: 0,
17
18 constructor: function(){
19 // summary:
20 // This is the constructor
21 // description:
22 // This function initialize the date object values
23 // example:
24 // | var date1 = new dojox.date.buddhist.Date();
25 // | var date2 = new dojox.date.buddhist.Date(date1);
26 // | var date3 = new dojox.date.buddhist.Date(2552,2,12);
27
28 var len = arguments.length;
29 if(!len){// use the current date value, added "" to the similarity to date
30 this.fromGregorian(new Date());
31 }else if(len == 1){
32 var arg0 = arguments[0];
33 if(typeof arg0 == "number"){ // this is time "valueof"
34 arg0 = new Date(arg0);
35 }
36
37 if(arg0 instanceof Date){
38 this.fromGregorian(arg0);
39 }else if(arg0 == ""){
40 this._date = new Date("");
41 }else{
42 this._year = arg0._year;
43 this._month = arg0._month;
44 this._date = arg0._date;
45 this._hours = arg0._hours;
46 this._minutes = arg0._minutes;
47 this._seconds = arg0._seconds;
48 this._milliseconds = arg0._milliseconds;
49 }
50 }else if(len >=3){
51 this._year += arguments[0];
52 this._month += arguments[1];
53 this._date += arguments[2];
54
55 if(this._month >11){
56 console.warn("the month is incorrect , set 0");
57 this._month = 0;
58 }
59 this._hours += arguments[3] || 0;
60 this._minutes += arguments[4] || 0;
61 this._seconds += arguments[5] || 0;
62 this._milliseconds += arguments[6] || 0;
63 }
64 },
65
66 getDate: function(/*boolean?*/isNumber){
67 // summary:
68 // This function returns the date value (0 - 30)
69 // example:
70 // | var date1 = new dojox.date.buddhist.Date();
71 // | console.log(date1.getDate());
72 return parseInt(this._date);
73 },
74
75 getMonth: function(){
76 // summary:
77 // This function return the month value ( 0 - 11 )
78 // example:
79 // | var date1 = new dojox.date.buddhist.Date();
80 // | console.log(date1.getMonth()+1);
81 return parseInt(this._month);
82 },
83
84
85 getFullYear: function(){
86 // summary:
87 // This function return the Year value
88 // example:
89 // | var date1 = new dojox.date.buddhist.Date();
90 // | console.log(date1.getFullYear());
91 return parseInt(this._year);
92 },
93
94 getHours: function(){
95 // summary:
96 // returns the Hour value
97 return this._hours;
98 },
99
100 getMinutes: function(){
101 // summary:
102 // returns the Minutes value
103 return this._minutes;
104 },
105
106 getSeconds: function(){
107 // summary:
108 // returns the Seconds value
109 return this._seconds;
110 },
111
112 getMilliseconds: function(){
113 // summary:
114 // returns the Milliseconds value
115 return this._milliseconds;
116 },
117
118 setDate: function(/*number*/date){
119 // summary:
120 // This function sets the Date
121 // example:
122 // | var date1 = new dojox.date.buddhist.Date();
123 // | date1.setDate(2);
124 date = parseInt(date);
125
126 if(date > 0 && date <= this._getDaysInMonth(this._month, this._year)){
127 this._date = date;
128 }else{
129 var mdays;
130 if(date>0){
131 for(mdays = this._getDaysInMonth(this._month, this._year);
132 date > mdays;
133 date -= mdays,mdays = this._getDaysInMonth(this._month, this._year)){
134 this._month++;
135 if(this._month >= 12){this._year++; this._month -= 12;}
136 }
137
138 this._date = date;
139 }else{
140 for(mdays = this._getDaysInMonth((this._month-1)>=0 ?(this._month-1) :11 ,((this._month-1)>=0)? this._year: this._year-1);
141 date <= 0;
142 mdays = this._getDaysInMonth((this._month-1)>=0 ? (this._month-1) :11,((this._month-1)>=0)? this._year: this._year-1)){
143 this._month--;
144 if(this._month < 0){this._year--; this._month += 12;}
145
146 date+=mdays;
147 }
148 this._date = date;
149 }
150 }
151 return this;
152 },
153
154 setFullYear: function(/*number*/year, /*number?*/month, /*number?*/ date){
155 // summary:
156 // This function set Year
157 // example:
158 // | var date1 = new dojox.date.buddhist.Date();
159 // | date1.setFullYear(2552);
160 // | date1.setFullYear(2552, 1, 1);
161 this._year = parseInt(year);
162 },
163
164 setMonth: function(/*number*/month){
165 // summary:
166 // This function set Month
167 // example:
168 // | var date1 = new dojox.date.buddhist.Date();
169 // | date1.setMonth(0); //first month
170 this._year += Math.floor(month / 12);
171 this._month = Math.floor(month % 12);
172 for(; this._month < 0; this._month = this._month+12);
173 },
174
175 setHours: function(){
176 // summary:
177 // set the Hours 0-23
178 var hours_arg_no = arguments.length;
179 var hours = 0;
180 if(hours_arg_no >= 1){
181 hours = parseInt(arguments[0]);
182 }
183
184 if(hours_arg_no >= 2){
185 this._minutes = parseInt(arguments[1]);
186 }
187
188 if(hours_arg_no >= 3){
189 this._seconds = parseInt(arguments[2]);
190 }
191
192 if(hours_arg_no == 4){
193 this._milliseconds = parseInt(arguments[3]);
194 }
195
196 while(hours >= 24){
197 this._date++;
198 var mdays = this._getDaysInMonth(this._month, this._year);
199 if(this._date > mdays){
200 this._month ++;
201 if(this._month >= 12){this._year++; this._month -= 12;}
202 this._date -= mdays;
203 }
204 hours -= 24;
205 }
206 this._hours = hours;
207 },
208
209 _addMinutes: function(/*Number*/minutes){
210 minutes += this._minutes;
211 this.setMinutes(minutes);
212 this.setHours(this._hours + parseInt(minutes / 60));
213 return this;
214 },
215
216 _addSeconds: function(/*Number*/seconds){
217 seconds += this._seconds;
218 this.setSeconds(seconds);
219 this._addMinutes(parseInt(seconds / 60));
220 return this;
221 },
222
223 _addMilliseconds: function(/*Number*/milliseconds){
224 milliseconds += this._milliseconds;
225 this.setMilliseconds(milliseconds);
226 this._addSeconds(parseInt(milliseconds / 1000));
227 return this;
228 },
229
230 setMinutes: function(/*Number*/minutes){
231 // summary:
232 // sets the minutes (0-59) only.
233 this._minutes = minutes % 60;
234 return this;
235 },
236
237 setSeconds: function(/*Number*/seconds){
238 // summary:
239 // sets the seconds (0-59) only.
240 this._seconds = seconds % 60;
241 return this;
242 },
243
244 setMilliseconds: function(/*Number*/milliseconds){
245 this._milliseconds = milliseconds % 1000;
246 return this;
247 },
248
249 toString: function(){
250 // summary:
251 // This returns a string representation of the date in "dd, MM, YYYY HH:MM:SS" format
252 return isNaN(this._date)?"Invalid Date":
253 this._date + ", " + this._month + ", " + this._year + " " + this._hours + ":" + this._minutes + ":" + this._seconds; // String
254 },
255
256 //FIXME: remove this and replace usage with dojox.date.buddhist.getDaysInMonth?
257 _getDaysInMonth: function(/*number*/month, /*number*/ year){
258 return dd.getDaysInMonth(new Date(year-543, month));
259 },
260
261 fromGregorian: function(/*Date*/gdate){
262 // summary:
263 // This function sets this Date to the Hebrew Date corresponding to the Gregorian Date
264 var date = new Date(gdate);
265 this._date = date.getDate();
266 this._month = date.getMonth();
267 this._year = date.getFullYear()+543;
268 this._hours = date.getHours();
269 this._minutes = date.getMinutes();
270 this._seconds = date.getSeconds();
271 this._milliseconds = date.getMilliseconds();
272 this._day = date.getDay();
273 return this;
274 },
275
276 toGregorian: function(){
277 // summary:
278 // This returns the equivalent Gregorian date value as a Date object
279 return new Date(this._year-543, this._month, this._date, this._hours, this._minutes, this._seconds, this._milliseconds); // Date
280 },
281
282 getDay: function(){
283 // summary:
284 // This function return Week Day value ( 0 - 6 )
285 return this.toGregorian().getDay(); // int
286 }
287 });
288
289 BDate.prototype.valueOf = function(){
290 return this.toGregorian().valueOf();
291 };
292
293 return BDate;
294 });