as3corelib 0.1.0 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. data/Gemfile +1 -4
  2. data/Gemfile.lock +7 -4
  3. data/README.textile +20 -10
  4. data/Rakefile +32 -2
  5. data/as3corelib.gemspec +13 -11
  6. data/lib/as3corelib.rb +10 -4
  7. data/lib/as3corelib/version.rb +4 -0
  8. metadata +31 -121
  9. data/build/build.properties +0 -48
  10. data/build/build.xml +0 -104
  11. data/examples/JSONExample/JSONExample.mxml +0 -73
  12. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +0 -313
  13. data/src/com/adobe/air/filesystem/FileMonitor.as +0 -245
  14. data/src/com/adobe/air/filesystem/FileUtil.as +0 -63
  15. data/src/com/adobe/air/filesystem/VolumeMonitor.as +0 -184
  16. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +0 -61
  17. data/src/com/adobe/air/logging/FileTarget.as +0 -95
  18. data/src/com/adobe/air/net/ResourceCache.as +0 -165
  19. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +0 -70
  20. data/src/com/adobe/crypto/HMAC.as +0 -127
  21. data/src/com/adobe/crypto/MD5.as +0 -281
  22. data/src/com/adobe/crypto/MD5Stream.as +0 -402
  23. data/src/com/adobe/crypto/SHA1.as +0 -289
  24. data/src/com/adobe/crypto/SHA224.as +0 -257
  25. data/src/com/adobe/crypto/SHA256.as +0 -261
  26. data/src/com/adobe/crypto/WSSEUsernameToken.as +0 -114
  27. data/src/com/adobe/errors/IllegalStateError.as +0 -63
  28. data/src/com/adobe/fileformats/vcard/Address.as +0 -47
  29. data/src/com/adobe/fileformats/vcard/Email.as +0 -39
  30. data/src/com/adobe/fileformats/vcard/Phone.as +0 -39
  31. data/src/com/adobe/fileformats/vcard/VCard.as +0 -54
  32. data/src/com/adobe/fileformats/vcard/VCardParser.as +0 -246
  33. data/src/com/adobe/images/BitString.as +0 -39
  34. data/src/com/adobe/images/JPGEncoder.as +0 -648
  35. data/src/com/adobe/images/PNGEncoder.as +0 -141
  36. data/src/com/adobe/net/DynamicURLLoader.as +0 -55
  37. data/src/com/adobe/net/IURIResolver.as +0 -76
  38. data/src/com/adobe/net/MimeTypeMap.as +0 -200
  39. data/src/com/adobe/net/URI.as +0 -2466
  40. data/src/com/adobe/net/URIEncodingBitmap.as +0 -139
  41. data/src/com/adobe/net/proxies/RFC2817Socket.as +0 -198
  42. data/src/com/adobe/protocols/dict/Database.as +0 -66
  43. data/src/com/adobe/protocols/dict/Definition.as +0 -71
  44. data/src/com/adobe/protocols/dict/Dict.as +0 -360
  45. data/src/com/adobe/protocols/dict/DictionaryServer.as +0 -60
  46. data/src/com/adobe/protocols/dict/MatchStrategy.as +0 -66
  47. data/src/com/adobe/protocols/dict/Response.as +0 -71
  48. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +0 -53
  49. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +0 -67
  50. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +0 -70
  51. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +0 -69
  52. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +0 -69
  53. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +0 -55
  54. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +0 -80
  55. data/src/com/adobe/protocols/dict/events/MatchEvent.as +0 -67
  56. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +0 -70
  57. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +0 -54
  58. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +0 -68
  59. data/src/com/adobe/protocols/dict/util/SocketHelper.as +0 -81
  60. data/src/com/adobe/serialization/json/JSON.as +0 -86
  61. data/src/com/adobe/serialization/json/JSONDecoder.as +0 -327
  62. data/src/com/adobe/serialization/json/JSONEncoder.as +0 -312
  63. data/src/com/adobe/serialization/json/JSONParseError.as +0 -87
  64. data/src/com/adobe/serialization/json/JSONToken.as +0 -104
  65. data/src/com/adobe/serialization/json/JSONTokenType.as +0 -69
  66. data/src/com/adobe/serialization/json/JSONTokenizer.as +0 -702
  67. data/src/com/adobe/utils/ArrayUtil.as +0 -187
  68. data/src/com/adobe/utils/DateUtil.as +0 -701
  69. data/src/com/adobe/utils/DictionaryUtil.as +0 -87
  70. data/src/com/adobe/utils/IntUtil.as +0 -99
  71. data/src/com/adobe/utils/NumberFormatter.as +0 -74
  72. data/src/com/adobe/utils/StringUtil.as +0 -239
  73. data/src/com/adobe/utils/XMLUtil.as +0 -168
  74. data/src/com/adobe/webapis/ServiceBase.as +0 -48
  75. data/src/com/adobe/webapis/URLLoaderBase.as +0 -108
  76. data/src/com/adobe/webapis/events/ServiceEvent.as +0 -82
  77. data/tests/src/CoreLibTestRunner-app.xml +0 -135
  78. data/tests/src/CoreLibTestRunner.as +0 -138
  79. data/tests/src/CoreLibTestRunner.mxml +0 -46
  80. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +0 -176
  81. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +0 -63
  82. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +0 -57
  83. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +0 -59
  84. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +0 -72
  85. data/tests/src/com/adobe/crypto/HMACMD5Test.as +0 -134
  86. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +0 -138
  87. data/tests/src/com/adobe/crypto/MD5Test.as +0 -82
  88. data/tests/src/com/adobe/crypto/SHA1Test.as +0 -151
  89. data/tests/src/com/adobe/crypto/SHA224Test.as +0 -104
  90. data/tests/src/com/adobe/crypto/SHA256Test.as +0 -116
  91. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +0 -87
  92. data/tests/src/com/adobe/images/JPGEncoderTest.as +0 -54
  93. data/tests/src/com/adobe/images/PNGEncoderTest.as +0 -54
  94. data/tests/src/com/adobe/net/URITest.as +0 -589
  95. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +0 -59
  96. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +0 -62
  97. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +0 -61
  98. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +0 -61
  99. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +0 -61
  100. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +0 -59
  101. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +0 -63
  102. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +0 -61
  103. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +0 -61
  104. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +0 -58
  105. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +0 -60
  106. data/tests/src/com/adobe/serialization/json/JSONTest.as +0 -522
  107. data/tests/src/com/adobe/serialization/json/SimpleClass.as +0 -85
  108. data/tests/src/com/adobe/utils/ArrayUtilTest.as +0 -173
  109. data/tests/src/com/adobe/utils/DateUtilTest.as +0 -436
  110. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +0 -93
  111. data/tests/src/com/adobe/utils/IntUtilTest.as +0 -73
  112. data/tests/src/com/adobe/utils/NumberFormatterTest.as +0 -70
  113. data/tests/src/com/adobe/utils/StringUtilTest.as +0 -304
  114. data/tests/src/com/adobe/utils/XMLUtilTest.as +0 -101
  115. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +0 -66
@@ -1,187 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.utils
34
- {
35
-
36
- /**
37
- * Class that contains static utility methods for manipulating and working
38
- * with Arrays.
39
- *
40
- * Note that all APIs assume that they are working with well formed arrays.
41
- * i.e. they will only manipulate indexed values.
42
- *
43
- * @langversion ActionScript 3.0
44
- * @playerversion Flash 9.0
45
- * @tiptext
46
- */
47
- public class ArrayUtil
48
- {
49
-
50
- /**
51
- * Determines whether the specified array contains the specified value.
52
- *
53
- * @param arr The array that will be checked for the specified value.
54
- *
55
- * @param value The object which will be searched for within the array
56
- *
57
- * @return True if the array contains the value, False if it does not.
58
- *
59
- * @langversion ActionScript 3.0
60
- * @playerversion Flash 9.0
61
- * @tiptext
62
- */
63
- public static function arrayContainsValue(arr:Array, value:Object):Boolean
64
- {
65
- return (arr.indexOf(value) != -1);
66
- }
67
-
68
- /**
69
- * Remove all instances of the specified value from the array,
70
- *
71
- * @param arr The array from which the value will be removed
72
- *
73
- * @param value The object that will be removed from the array.
74
- *
75
- * @langversion ActionScript 3.0
76
- * @playerversion Flash 9.0
77
- * @tiptext
78
- */
79
- public static function removeValueFromArray(arr:Array, value:Object):void
80
- {
81
- var len:uint = arr.length;
82
-
83
- for(var i:Number = len; i > -1; i--)
84
- {
85
- if(arr[i] === value)
86
- {
87
- arr.splice(i, 1);
88
- }
89
- }
90
- }
91
-
92
- /**
93
- * Create a new array that only contains unique instances of objects
94
- * in the specified array.
95
- *
96
- * Basically, this can be used to remove duplication object instances
97
- * from an array
98
- *
99
- * @param arr The array which contains the values that will be used to
100
- * create the new array that contains no duplicate values.
101
- *
102
- * @return A new array which only contains unique items from the specified
103
- * array.
104
- *
105
- * @langversion ActionScript 3.0
106
- * @playerversion Flash 9.0
107
- * @tiptext
108
- */
109
- public static function createUniqueCopy(a:Array):Array
110
- {
111
- var newArray:Array = new Array();
112
-
113
- var len:Number = a.length;
114
- var item:Object;
115
-
116
- for (var i:uint = 0; i < len; ++i)
117
- {
118
- item = a[i];
119
-
120
- if(ArrayUtil.arrayContainsValue(newArray, item))
121
- {
122
- continue;
123
- }
124
-
125
- newArray.push(item);
126
- }
127
-
128
- return newArray;
129
- }
130
-
131
- /**
132
- * Creates a copy of the specified array.
133
- *
134
- * Note that the array returned is a new array but the items within the
135
- * array are not copies of the items in the original array (but rather
136
- * references to the same items)
137
- *
138
- * @param arr The array that will be copies
139
- *
140
- * @return A new array which contains the same items as the array passed
141
- * in.
142
- *
143
- * @langversion ActionScript 3.0
144
- * @playerversion Flash 9.0
145
- * @tiptext
146
- */
147
- public static function copyArray(arr:Array):Array
148
- {
149
- return arr.slice();
150
- }
151
-
152
- /**
153
- * Compares two arrays and returns a boolean indicating whether the arrays
154
- * contain the same values at the same indexes.
155
- *
156
- * @param arr1 The first array that will be compared to the second.
157
- *
158
- * @param arr2 The second array that will be compared to the first.
159
- *
160
- * @return True if the arrays contains the same values at the same indexes.
161
- False if they do not.
162
- *
163
- * @langversion ActionScript 3.0
164
- * @playerversion Flash 9.0
165
- * @tiptext
166
- */
167
- public static function arraysAreEqual(arr1:Array, arr2:Array):Boolean
168
- {
169
- if(arr1.length != arr2.length)
170
- {
171
- return false;
172
- }
173
-
174
- var len:Number = arr1.length;
175
-
176
- for(var i:Number = 0; i < len; i++)
177
- {
178
- if(arr1[i] !== arr2[i])
179
- {
180
- return false;
181
- }
182
- }
183
-
184
- return true;
185
- }
186
- }
187
- }
@@ -1,701 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.utils
34
- {
35
- import mx.formatters.DateBase;
36
-
37
- /**
38
- * Class that contains static utility methods for manipulating and working
39
- * with Dates.
40
- *
41
- * @langversion ActionScript 3.0
42
- * @playerversion Flash 9.0
43
- * @tiptext
44
- */
45
- public class DateUtil
46
- {
47
-
48
- /**
49
- * Returns the English Short Month name (3 letters) for the Month that
50
- * the Date represents.
51
- *
52
- * @param d The Date instance whose month will be used to retrieve the
53
- * short month name.
54
- *
55
- * @return An English 3 Letter Month abbreviation.
56
- *
57
- * @langversion ActionScript 3.0
58
- * @playerversion Flash 9.0
59
- * @tiptext
60
- *
61
- * @see SHORT_MONTH
62
- */
63
- public static function getShortMonthName(d:Date):String
64
- {
65
- return DateBase.monthNamesShort[d.getMonth()];
66
- }
67
-
68
- /**
69
- * Returns the index of the month that the short month name string
70
- * represents.
71
- *
72
- * @param m The 3 letter abbreviation representing a short month name.
73
- *
74
- * @param Optional parameter indicating whether the search should be case
75
- * sensitive
76
- *
77
- * @return A int that represents that month represented by the specifed
78
- * short name.
79
- *
80
- * @langversion ActionScript 3.0
81
- * @playerversion Flash 9.0
82
- * @tiptext
83
- *
84
- * @see SHORT_MONTH
85
- */
86
- public static function getShortMonthIndex(m:String):int
87
- {
88
- return DateBase.monthNamesShort.indexOf(m);
89
- }
90
-
91
- /**
92
- * Returns the English full Month name for the Month that
93
- * the Date represents.
94
- *
95
- * @param d The Date instance whose month will be used to retrieve the
96
- * full month name.
97
- *
98
- * @return An English full month name.
99
- *
100
- * @langversion ActionScript 3.0
101
- * @playerversion Flash 9.0
102
- * @tiptext
103
- *
104
- * @see FULL_MONTH
105
- */
106
- public static function getFullMonthName(d:Date):String
107
- {
108
- return DateBase.monthNamesLong[d.getMonth()];
109
- }
110
-
111
- /**
112
- * Returns the index of the month that the full month name string
113
- * represents.
114
- *
115
- * @param m A full month name.
116
- *
117
- * @return A int that represents that month represented by the specifed
118
- * full month name.
119
- *
120
- * @langversion ActionScript 3.0
121
- * @playerversion Flash 9.0
122
- * @tiptext
123
- *
124
- * @see FULL_MONTH
125
- */
126
- public static function getFullMonthIndex(m:String):int
127
- {
128
- return DateBase.monthNamesLong.indexOf(m);
129
- }
130
-
131
- /**
132
- * Returns the English Short Day name (3 letters) for the day that
133
- * the Date represents.
134
- *
135
- * @param d The Date instance whose day will be used to retrieve the
136
- * short day name.
137
- *
138
- * @return An English 3 Letter day abbreviation.
139
- *
140
- * @langversion ActionScript 3.0
141
- * @playerversion Flash 9.0
142
- * @tiptext
143
- *
144
- * @see SHORT_DAY
145
- */
146
- public static function getShortDayName(d:Date):String
147
- {
148
- return DateBase.dayNamesShort[d.getDay()];
149
- }
150
-
151
- /**
152
- * Returns the index of the day that the short day name string
153
- * represents.
154
- *
155
- * @param m A short day name.
156
- *
157
- * @return A int that represents that short day represented by the specifed
158
- * full month name.
159
- *
160
- * @langversion ActionScript 3.0
161
- * @playerversion Flash 9.0
162
- * @tiptext
163
- *
164
- * @see SHORT_DAY
165
- */
166
- public static function getShortDayIndex(d:String):int
167
- {
168
- return DateBase.dayNamesShort.indexOf(d);
169
- }
170
-
171
- /**
172
- * Returns the English full day name for the day that
173
- * the Date represents.
174
- *
175
- * @param d The Date instance whose day will be used to retrieve the
176
- * full day name.
177
- *
178
- * @return An English full day name.
179
- *
180
- * @langversion ActionScript 3.0
181
- * @playerversion Flash 9.0
182
- * @tiptext
183
- *
184
- * @see FULL_DAY
185
- */
186
- public static function getFullDayName(d:Date):String
187
- {
188
- return DateBase.dayNamesLong[d.getDay()];
189
- }
190
-
191
- /**
192
- * Returns the index of the day that the full day name string
193
- * represents.
194
- *
195
- * @param m A full day name.
196
- *
197
- * @return A int that represents that full day represented by the specifed
198
- * full month name.
199
- *
200
- * @langversion ActionScript 3.0
201
- * @playerversion Flash 9.0
202
- * @tiptext
203
- *
204
- * @see FULL_DAY
205
- */
206
- public static function getFullDayIndex(d:String):int
207
- {
208
- return DateBase.dayNamesLong.indexOf(d);
209
- }
210
-
211
- /**
212
- * Returns a two digit representation of the year represented by the
213
- * specified date.
214
- *
215
- * @param d The Date instance whose year will be used to generate a two
216
- * digit string representation of the year.
217
- *
218
- * @return A string that contains a 2 digit representation of the year.
219
- * Single digits will be padded with 0.
220
- *
221
- * @langversion ActionScript 3.0
222
- * @playerversion Flash 9.0
223
- * @tiptext
224
- */
225
- public static function getShortYear(d:Date):String
226
- {
227
- var dStr:String = String(d.getFullYear());
228
-
229
- if(dStr.length < 3)
230
- {
231
- return dStr;
232
- }
233
-
234
- return (dStr.substr(dStr.length - 2));
235
- }
236
-
237
- /**
238
- * Compares two dates and returns an integer depending on their relationship.
239
- *
240
- * Returns -1 if d1 is greater than d2.
241
- * Returns 1 if d2 is greater than d1.
242
- * Returns 0 if both dates are equal.
243
- *
244
- * @param d1 The date that will be compared to the second date.
245
- * @param d2 The date that will be compared to the first date.
246
- *
247
- * @return An int indicating how the two dates compare.
248
- *
249
- * @langversion ActionScript 3.0
250
- * @playerversion Flash 9.0
251
- * @tiptext
252
- */
253
- public static function compareDates(d1:Date, d2:Date):int
254
- {
255
- var d1ms:Number = d1.getTime();
256
- var d2ms:Number = d2.getTime();
257
-
258
- if(d1ms > d2ms)
259
- {
260
- return -1;
261
- }
262
- else if(d1ms < d2ms)
263
- {
264
- return 1;
265
- }
266
- else
267
- {
268
- return 0;
269
- }
270
- }
271
-
272
- /**
273
- * Returns a short hour (0 - 12) represented by the specified date.
274
- *
275
- * If the hour is less than 12 (0 - 11 AM) then the hour will be returned.
276
- *
277
- * If the hour is greater than 12 (12 - 23 PM) then the hour minus 12
278
- * will be returned.
279
- *
280
- * @param d1 The Date from which to generate the short hour
281
- *
282
- * @return An int between 0 and 13 ( 1 - 12 ) representing the short hour.
283
- *
284
- * @langversion ActionScript 3.0
285
- * @playerversion Flash 9.0
286
- * @tiptext
287
- */
288
- public static function getShortHour(d:Date):int
289
- {
290
- var h:int = d.hours;
291
-
292
- if(h == 0 || h == 12)
293
- {
294
- return 12;
295
- }
296
- else if(h > 12)
297
- {
298
- return h - 12;
299
- }
300
- else
301
- {
302
- return h;
303
- }
304
- }
305
-
306
- /**
307
- * Returns a string indicating whether the date represents a time in the
308
- * ante meridiem (AM) or post meridiem (PM).
309
- *
310
- * If the hour is less than 12 then "AM" will be returned.
311
- *
312
- * If the hour is greater than 12 then "PM" will be returned.
313
- *
314
- * @param d1 The Date from which to generate the 12 hour clock indicator.
315
- *
316
- * @return A String ("AM" or "PM") indicating which half of the day the
317
- * hour represents.
318
- *
319
- * @langversion ActionScript 3.0
320
- * @playerversion Flash 9.0
321
- * @tiptext
322
- */
323
- public static function getAMPM(d:Date):String
324
- {
325
- return (d.hours > 11)? "PM" : "AM";
326
- }
327
-
328
- /**
329
- * Parses dates that conform to RFC822 into Date objects. This method also
330
- * supports four-digit years (not supported in RFC822), but two-digit years
331
- * (referring to the 20th century) are fine, too.
332
- *
333
- * This function is useful for parsing RSS .91, .92, and 2.0 dates.
334
- *
335
- * @param str
336
- *
337
- * @returns
338
- *
339
- * @langversion ActionScript 3.0
340
- * @playerversion Flash 9.0
341
- * @tiptext
342
- *
343
- * @see http://asg.web.cmu.edu/rfc/rfc822.html
344
- */
345
- public static function parseRFC822(str:String):Date
346
- {
347
- var finalDate:Date;
348
- try
349
- {
350
- var dateParts:Array = str.split(" ");
351
- var day:String = null;
352
-
353
- if (dateParts[0].search(/\d/) == -1)
354
- {
355
- day = dateParts.shift().replace(/\W/, "");
356
- }
357
-
358
- var date:Number = Number(dateParts.shift());
359
- var month:Number = Number(DateUtil.getShortMonthIndex(dateParts.shift()));
360
- var year:Number = Number(dateParts.shift());
361
- var timeParts:Array = dateParts.shift().split(":");
362
- var hour:Number = int(timeParts.shift());
363
- var minute:Number = int(timeParts.shift());
364
- var second:Number = (timeParts.length > 0) ? int(timeParts.shift()): 0;
365
-
366
- var milliseconds:Number = Date.UTC(year, month, date, hour, minute, second, 0);
367
-
368
- var timezone:String = dateParts.shift();
369
- var offset:Number = 0;
370
-
371
- if (timezone.search(/\d/) == -1)
372
- {
373
- switch(timezone)
374
- {
375
- case "UT":
376
- offset = 0;
377
- break;
378
- case "UTC":
379
- offset = 0;
380
- break;
381
- case "GMT":
382
- offset = 0;
383
- break;
384
- case "EST":
385
- offset = (-5 * 3600000);
386
- break;
387
- case "EDT":
388
- offset = (-4 * 3600000);
389
- break;
390
- case "CST":
391
- offset = (-6 * 3600000);
392
- break;
393
- case "CDT":
394
- offset = (-5 * 3600000);
395
- break;
396
- case "MST":
397
- offset = (-7 * 3600000);
398
- break;
399
- case "MDT":
400
- offset = (-6 * 3600000);
401
- break;
402
- case "PST":
403
- offset = (-8 * 3600000);
404
- break;
405
- case "PDT":
406
- offset = (-7 * 3600000);
407
- break;
408
- case "Z":
409
- offset = 0;
410
- break;
411
- case "A":
412
- offset = (-1 * 3600000);
413
- break;
414
- case "M":
415
- offset = (-12 * 3600000);
416
- break;
417
- case "N":
418
- offset = (1 * 3600000);
419
- break;
420
- case "Y":
421
- offset = (12 * 3600000);
422
- break;
423
- default:
424
- offset = 0;
425
- }
426
- }
427
- else
428
- {
429
- var multiplier:Number = 1;
430
- var oHours:Number = 0;
431
- var oMinutes:Number = 0;
432
- if (timezone.length != 4)
433
- {
434
- if (timezone.charAt(0) == "-")
435
- {
436
- multiplier = -1;
437
- }
438
- timezone = timezone.substr(1, 4);
439
- }
440
- oHours = Number(timezone.substr(0, 2));
441
- oMinutes = Number(timezone.substr(2, 2));
442
- offset = (((oHours * 3600000) + (oMinutes * 60000)) * multiplier);
443
- }
444
-
445
- finalDate = new Date(milliseconds - offset);
446
-
447
- if (finalDate.toString() == "Invalid Date")
448
- {
449
- throw new Error("This date does not conform to RFC822.");
450
- }
451
- }
452
- catch (e:Error)
453
- {
454
- var eStr:String = "Unable to parse the string [" +str+ "] into a date. ";
455
- eStr += "The internal error was: " + e.toString();
456
- throw new Error(eStr);
457
- }
458
- return finalDate;
459
- }
460
-
461
- /**
462
- * Returns a date string formatted according to RFC822.
463
- *
464
- * @param d
465
- *
466
- * @returns
467
- *
468
- * @langversion ActionScript 3.0
469
- * @playerversion Flash 9.0
470
- * @tiptext
471
- *
472
- * @see http://asg.web.cmu.edu/rfc/rfc822.html
473
- */
474
- public static function toRFC822(d:Date):String
475
- {
476
- var date:Number = d.getUTCDate();
477
- var hours:Number = d.getUTCHours();
478
- var minutes:Number = d.getUTCMinutes();
479
- var seconds:Number = d.getUTCSeconds();
480
- var sb:String = new String();
481
- sb += DateBase.dayNamesShort[d.getUTCDay()];
482
- sb += ", ";
483
-
484
- if (date < 10)
485
- {
486
- sb += "0";
487
- }
488
- sb += date;
489
- sb += " ";
490
- //sb += DateUtil.SHORT_MONTH[d.getUTCMonth()];
491
- sb += DateBase.monthNamesShort[d.getUTCMonth()];
492
- sb += " ";
493
- sb += d.getUTCFullYear();
494
- sb += " ";
495
- if (hours < 10)
496
- {
497
- sb += "0";
498
- }
499
- sb += hours;
500
- sb += ":";
501
- if (minutes < 10)
502
- {
503
- sb += "0";
504
- }
505
- sb += minutes;
506
- sb += ":";
507
- if (seconds < 10)
508
- {
509
- sb += "0";
510
- }
511
- sb += seconds;
512
- sb += " GMT";
513
- return sb;
514
- }
515
-
516
- /**
517
- * Parses dates that conform to the W3C Date-time Format into Date objects.
518
- *
519
- * This function is useful for parsing RSS 1.0 and Atom 1.0 dates.
520
- *
521
- * @param str
522
- *
523
- * @returns
524
- *
525
- * @langversion ActionScript 3.0
526
- * @playerversion Flash 9.0
527
- * @tiptext
528
- *
529
- * @see http://www.w3.org/TR/NOTE-datetime
530
- */
531
- public static function parseW3CDTF(str:String):Date
532
- {
533
- var finalDate:Date;
534
- try
535
- {
536
- var dateStr:String = str.substring(0, str.indexOf("T"));
537
- var timeStr:String = str.substring(str.indexOf("T")+1, str.length);
538
- var dateArr:Array = dateStr.split("-");
539
- var year:Number = Number(dateArr.shift());
540
- var month:Number = Number(dateArr.shift());
541
- var date:Number = Number(dateArr.shift());
542
-
543
- var multiplier:Number;
544
- var offsetHours:Number;
545
- var offsetMinutes:Number;
546
- var offsetStr:String;
547
-
548
- if (timeStr.indexOf("Z") != -1)
549
- {
550
- multiplier = 1;
551
- offsetHours = 0;
552
- offsetMinutes = 0;
553
- timeStr = timeStr.replace("Z", "");
554
- }
555
- else if (timeStr.indexOf("+") != -1)
556
- {
557
- multiplier = 1;
558
- offsetStr = timeStr.substring(timeStr.indexOf("+")+1, timeStr.length);
559
- offsetHours = Number(offsetStr.substring(0, offsetStr.indexOf(":")));
560
- offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":")+1, offsetStr.length));
561
- timeStr = timeStr.substring(0, timeStr.indexOf("+"));
562
- }
563
- else // offset is -
564
- {
565
- multiplier = -1;
566
- offsetStr = timeStr.substring(timeStr.indexOf("-")+1, timeStr.length);
567
- offsetHours = Number(offsetStr.substring(0, offsetStr.indexOf(":")));
568
- offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":")+1, offsetStr.length));
569
- timeStr = timeStr.substring(0, timeStr.indexOf("-"));
570
- }
571
- var timeArr:Array = timeStr.split(":");
572
- var hour:Number = Number(timeArr.shift());
573
- var minutes:Number = Number(timeArr.shift());
574
- var secondsArr:Array = (timeArr.length > 0) ? String(timeArr.shift()).split(".") : null;
575
- var seconds:Number = (secondsArr != null && secondsArr.length > 0) ? Number(secondsArr.shift()) : 0;
576
- //var milliseconds:Number = (secondsArr != null && secondsArr.length > 0) ? Number(secondsArr.shift()) : 0;
577
-
578
- var milliseconds:Number = (secondsArr != null && secondsArr.length > 0) ? 1000*parseFloat("0." + secondsArr.shift()) : 0;
579
- var utc:Number = Date.UTC(year, month-1, date, hour, minutes, seconds, milliseconds);
580
- var offset:Number = (((offsetHours * 3600000) + (offsetMinutes * 60000)) * multiplier);
581
- finalDate = new Date(utc - offset);
582
-
583
- if (finalDate.toString() == "Invalid Date")
584
- {
585
- throw new Error("This date does not conform to W3CDTF.");
586
- }
587
- }
588
- catch (e:Error)
589
- {
590
- var eStr:String = "Unable to parse the string [" +str+ "] into a date. ";
591
- eStr += "The internal error was: " + e.toString();
592
- throw new Error(eStr);
593
- }
594
- return finalDate;
595
- }
596
-
597
- /**
598
- * Returns a date string formatted according to W3CDTF.
599
- *
600
- * @param d
601
- * @param includeMilliseconds Determines whether to include the
602
- * milliseconds value (if any) in the formatted string.
603
- *
604
- * @returns
605
- *
606
- * @langversion ActionScript 3.0
607
- * @playerversion Flash 9.0
608
- * @tiptext
609
- *
610
- * @see http://www.w3.org/TR/NOTE-datetime
611
- */
612
- public static function toW3CDTF(d:Date,includeMilliseconds:Boolean=false):String
613
- {
614
- var date:Number = d.getUTCDate();
615
- var month:Number = d.getUTCMonth();
616
- var hours:Number = d.getUTCHours();
617
- var minutes:Number = d.getUTCMinutes();
618
- var seconds:Number = d.getUTCSeconds();
619
- var milliseconds:Number = d.getUTCMilliseconds();
620
- var sb:String = new String();
621
-
622
- sb += d.getUTCFullYear();
623
- sb += "-";
624
-
625
- //thanks to "dom" who sent in a fix for the line below
626
- if (month + 1 < 10)
627
- {
628
- sb += "0";
629
- }
630
- sb += month + 1;
631
- sb += "-";
632
- if (date < 10)
633
- {
634
- sb += "0";
635
- }
636
- sb += date;
637
- sb += "T";
638
- if (hours < 10)
639
- {
640
- sb += "0";
641
- }
642
- sb += hours;
643
- sb += ":";
644
- if (minutes < 10)
645
- {
646
- sb += "0";
647
- }
648
- sb += minutes;
649
- sb += ":";
650
- if (seconds < 10)
651
- {
652
- sb += "0";
653
- }
654
- sb += seconds;
655
- if (includeMilliseconds && milliseconds > 0)
656
- {
657
- sb += ".";
658
- sb += milliseconds;
659
- }
660
- sb += "-00:00";
661
- return sb;
662
- }
663
-
664
- /**
665
- * Converts a date into just after midnight.
666
- */
667
- public static function makeMorning(d:Date):Date
668
- {
669
- var d:Date = new Date(d.time);
670
- d.hours = 0;
671
- d.minutes = 0;
672
- d.seconds = 0;
673
- d.milliseconds = 0;
674
- return d;
675
- }
676
-
677
- /**
678
- * Converts a date into just befor midnight.
679
- */
680
- public static function makeNight(d:Date):Date
681
- {
682
- var d:Date = new Date(d.time);
683
- d.hours = 23;
684
- d.minutes = 59;
685
- d.seconds = 59;
686
- d.milliseconds = 999;
687
- return d;
688
- }
689
-
690
- /**
691
- * Sort of converts a date into UTC.
692
- */
693
- public static function getUTCDate(d:Date):Date
694
- {
695
- var nd:Date = new Date();
696
- var offset:Number = d.getTimezoneOffset() * 60 * 1000;
697
- nd.setTime(d.getTime() + offset);
698
- return nd;
699
- }
700
- }
701
- }