forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTimezone.as
More file actions
92 lines (76 loc) · 2.22 KB
/
Timezone.as
File metadata and controls
92 lines (76 loc) · 2.22 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
package utils.date
{
/*
* Need to discuss how to refactor timezone logic into better utils
*
* This class currently only works with USA (the offsets default to EAST if the timezone is outside of the USA.
*
* */
public class Timezone
{
public static const EAST:String = "ET";
public static const WEST:String = "WT";
public static const ARIZONA:String = "AZ";
public static const MOUNTAIN:String = "MT";
public static const CENTRAL:String = "CT";
public static const PACIFIC:String = "PT";
public static const ALASKA:String = "AK";
public static const HAWAII:String = "HT";
private static var nonDstOffsetDate:Date = new Date(2010, 1, 1);
private static var dstOffsetDate:Date = new Date(2010, 7, 1);
private static var observesDST:Boolean = (nonDstOffsetDate.timezoneOffset != dstOffsetDate.timezoneOffset);
private static var timezone:String = EAST;
public static function get zuluOffset():String
{
var offset:Number = nonDstOffsetDate.timezoneOffset / 60;
if(offset > 11 || offset <= 5)
{
offset = 4; //defaulting to east coast
return String(offset);
}
return String(new Date().timezoneOffset / 60);
}
public static function get dstOffset():String
{
var offset:Number = dstOffsetDate.timezoneOffset / 60;
if(offset > 10 || offset <= 4)
{
offset = 4; //defaulting to east coast
}
return String(offset);
}
public static function get nonDstOffset():String
{
var offset:Number = nonDstOffsetDate.timezoneOffset / 60;
if(offset > 11 || offset <= 5)
{
offset = 5; //defaulting to east coast
}
return String(offset);
}
public static function get name():String
{
//Default to Eastern
switch (nonDstOffset)
{
case "10":
timezone = HAWAII; //Hawaii
break;
case "9":
timezone = ALASKA; //Alaska
break;
case "8":
timezone = PACIFIC;//Pacific
break;
case "7":
timezone = MOUNTAIN;//Mountain
if(!observesDST) timezone = ARIZONA;
break;
case "6":
timezone = CENTRAL;//Central
break;
}
return timezone;
}
}
}