-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServerDate.as
More file actions
333 lines (287 loc) · 8.29 KB
/
ServerDate.as
File metadata and controls
333 lines (287 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
package
{
import com.mteamapp.StringFunctions;
import diagrams.calender.MyShamsi;
import flash.utils.getTimer;
import contents.alert.Alert;
public class ServerDate
{
/**11/6/2014 1:10:14 AM*/
public static function dateToServerDate(date:Date):String
{
if(date == null)
{
return '' ;
}
var AM_PM:String = "AM";
if(date.hours>=12)
{
AM_PM = "PM";
}
var houre:Number = date.hours ;
if(houre == 0)
{
houre = 12 ;
}
if(houre >= 13)
{
houre -= 12 ;
}
var createdDate:String = (date.month+1)+'/'+date.date+'/'+date.fullYear+' '+houre+':'+date.minutes+':'+date.seconds+' '+AM_PM;
return createdDate ;
}
/**2020_01_02 */
public static function dateToServerDate3(date:Date):String
{
return date.fullYear+"_"+StringFunctions.numToString(date.month+1)+"_"+StringFunctions.numToString(date.date);
}
/**2015-10-27T10:46:56.9335483+03:30*///2017-05-25T17:27:38.503Z
public static function dateToServerDate2(date:Date,addTimeZone:Boolean=true):String
{
if(date==null)
{
return '' ;
}
var zone:String = '' ;
if(addTimeZone)
{
zone = TimeToString.timeInString(Math.abs(date.timezoneOffset));
if(date.timezoneOffset<0)
{
zone = '+'+zone ;
}
else
{
zone = '-'+zone ;
}
}
var stringedDate:String = date.fullYear+'-'+TimeToString.numToString(date.month+1)+'-'+TimeToString.numToString(date.date)+'T' +
TimeToString.numToString(date.hours)+':'+TimeToString.numToString(date.minutes)+':'+TimeToString.numToString(date.seconds)+zone;
return stringedDate ;
}
/**2015-10-27T10:46:56.9335483+03:30<br>
* 2018-04-15T17:00:00*/
public static function serverDateToDate2(date:String):Date
{
var myDate:Date = new Date();
try
{
/**2015-10-27 , 10:46:56.9335483+03:30*/
var splitedDateT:Array = date.split('T');
/**2015 , 10 , 27*/
var splitedDatePart:Array = splitedDateT[0].split('-');
/**10 , 46 , 56.9335483+03 <strong>,</strong> 30*/
var splitedTimePart:Array = splitedDateT[1].split(':');
/**56.9335483 , 03:30*/
var splitedZoneAndSecond:Array ;
/**+ or -*/
var zoneMinutes:int = 0 ;
var noZoneAvailable:Boolean = true ;
var second:String ;
if(splitedTimePart[2].indexOf('+')!=-1)
{
splitedZoneAndSecond = splitedTimePart[2].split('+');
if(splitedZoneAndSecond.length>1)
{
zoneMinutes = -1*TimeToString.stringToNumBased60(splitedZoneAndSecond[1]+':'+splitedTimePart[3]) ;
}
noZoneAvailable = false ;
}
else if(splitedTimePart[2].indexOf('-')!=-1)
{
splitedZoneAndSecond = splitedTimePart[2].split('-');
if(splitedZoneAndSecond.length>0)
{
zoneMinutes = 1*TimeToString.stringToNumBased60(splitedZoneAndSecond[1]+':'+splitedTimePart[3]) ;
}
noZoneAvailable = false ;
}
else
{
splitedZoneAndSecond = [splitedTimePart[2]]
}
// trace("splitedZoneAndSecond : "+splitedZoneAndSecond);
myDate.fullYearUTC = uint(splitedDatePart[0]);
myDate.monthUTC = uint(splitedDatePart[1])-1;
myDate.dateUTC = uint(splitedDatePart[2]);
myDate.milliseconds = 0 ;
if(noZoneAvailable)
{
myDate.hours = uint(splitedTimePart[0]);
myDate.minutes = uint(splitedTimePart[1]);
myDate.seconds = uint(splitedZoneAndSecond[0]);
}
else
{
myDate.hoursUTC = uint(splitedTimePart[0]);
myDate.minutesUTC = uint(splitedTimePart[1]);
myDate.secondsUTC = uint(splitedZoneAndSecond[0]);
myDate.minutes+=zoneMinutes;
}
}
catch(e:Error)
{
trace("Date format is not parsable : "+date);
return null ;
}
return myDate ;
}
/**31/01/2018 15:50:08*/
public static function serverDateToDate(date:String):Date
{
if(date == '' || date==null)
{
return new Date();
}
//Alert.show("date: "+date);
var splitter:Array;
var dateSplitter:Array ;
var timeSplitter:Array;
var createdDate:Date;
splitter = date.split(' ');
dateSplitter = (splitter[0] as String).split('/');
timeSplitter = (splitter[1] as String).split(':');
if(timeSplitter[0]=='12')
{
timeSplitter[0] = '0' ;
}
var month:Number = Number(dateSplitter[0]) ;
var day:Number = Number(dateSplitter[1]) ;
if(month>12)
{
month = day ;
day = Number(dateSplitter[0]) ;
}
createdDate = new Date(Number(dateSplitter[2]),month-1,day,Number(timeSplitter[0]),Number(timeSplitter[1]),Number(timeSplitter[2]));
if(splitter[2] == "PM" && Number(timeSplitter[0])<12)
{
createdDate.hours+=12 ;
}
return createdDate ;
}
/**1396-12-15 10:50:00
* 1396/12/15 10:50:00"
* 1396/12/15 10:50:00 AM
* */
public static function serverDateToShamsiDate(date:String):MyShamsi
{
if(date == '' || date==null)
{
return new MyShamsi();
}
var splitter:Array;
var dateSplitter:Array ;
var timeSplitter:Array;
var createdDate:MyShamsi;
date = date.split('/').join('-') ;
splitter = date.split(' ');
var formatDate:String='/';
if(date.indexOf(formatDate)==-1)formatDate = '-';
dateSplitter = (splitter[0] as String).split(formatDate);
timeSplitter = (splitter[1] as String).split(':');
if(timeSplitter[0]=='12')
{
timeSplitter[0] = '0';
}
createdDate = new MyShamsi(Number(dateSplitter[0]),Number(dateSplitter[1])-1,Number(dateSplitter[2]),Number(timeSplitter[0]),Number(timeSplitter[1]),(timeSplitter.length>=3)?Number(timeSplitter[2]):null);
if(splitter[2] == "PM" && Number(timeSplitter[0])<12)
{
createdDate.hours+=12 ;
}
return createdDate ;
}
/**2015-08-30 or 2015/08/30*/
public static function serverDateToDate3(date:String):Date
{
if(date == '' || date==null)
{
return new Date();
}
var dateSplitter:Array ;
var createdDate:Date;
if( date.indexOf('/')!=-1)
{
dateSplitter = date.split('/');
}
else if(date.indexOf('-')!=-1)
{
dateSplitter = date.split('-');
}
createdDate = new Date(Number(dateSplitter[0]),Number(dateSplitter[1])-1,Number(dateSplitter[2]),0,0,0);
return createdDate ;
}
/**2015/11/06 23:00:00 or 2015-11-06 23:00:00*/
public static function serverDateToDate4(date:String):Date
{
if(date == '' || date==null)
{
return new Date();
}
var splitter:Array;
var dateSplitter:Array ;
var timeSplitter:Array;
var createdDate:Date;
splitter = date.split(' ');
if(date.indexOf('/')!=-1)
{
dateSplitter = (splitter[0] as String).split('/');
}
else if(date.indexOf('-')!=-1)
{
dateSplitter = (splitter[0] as String).split('-');
}
timeSplitter = (splitter[1] as String).split(':');
if(timeSplitter[0]=='12')
{
timeSplitter[0] = '0' ;
}
createdDate = new Date(Number(dateSplitter[0]),Number(dateSplitter[1])-1,Number(dateSplitter[2]),Number(timeSplitter[0]),Number(timeSplitter[1]),Number(timeSplitter[2]));
return createdDate ;
}
public static function copyDate(date:Date):Date
{
if(date==null)
{
return null;
}
var clonedDate:Date = new Date(date.fullYear,date.month,date.date,date.hours,date.minutes,date.seconds,date.milliseconds);
return clonedDate;
}
/////////////////////////////////////////////////////////////Shamsi↓
/**Sample is : 1395/09/06 or "1399/06/13 13:13"*/
public static function stringToMyShamsi(stringedDate:String):MyShamsi
{
if(stringedDate == null)
{
return null ;
}
var splitedTime:Array = stringedDate.split(' ');
var timePart:String = '' ;
if(splitedTime.length>1)
{
timePart = splitedTime[1];
stringedDate = splitedTime[0];
}
var splited:Array = stringedDate.split('/');
if(splited.length!=3)
{
return null ;
}
var houre:uint = 0 ;
var minutes:uint = 0 ;
var seconds:uint = 0 ;
var miliseconds:uint = 0 ;
if(timePart!='')
{
//12:15
var splitedClock:Array = timePart.split(':');
houre = uint(splitedClock[0]);
minutes = uint(splitedClock[1]);
seconds = uint(splitedClock[2]);
miliseconds = uint(splitedClock[3]);
}
var createdShamsi:MyShamsi = new MyShamsi(uint(splited[0]),uint(splited[1])-1,uint(splited[2]),houre,minutes,seconds,miliseconds);
return createdShamsi ;
}
}
}