iso8601-js 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ node_modules
2
+ npm-debug.log
3
+ out/
4
+ Gemfile.lock
5
+ pkg/
@@ -0,0 +1,23 @@
1
+ ## 0.2.0 (2011-12-27)
2
+
3
+ * API changed to match [ECMAScript 5.1][ecmascript] ISO 8601 support for the
4
+ Date object.
5
+ * `Date.prototype.toISO8601UTCString` is now `Date.prototype.toISOString`.
6
+ * `Date.prototype.toISO8601LocaleString` has been removed. Similar formatting
7
+ is available by passing *true* to `Date.prototype.toISO8601String` which
8
+ allows other customizations as well.
9
+ * ISO 8601 UTC formatting falls back to native support if available. Performance
10
+ improvement on modern browsers for common usages.
11
+ * Stricter browser test for native ISO 8601 parsing. Ensures timezone offsets
12
+ are correctly handled. Fixes Firefox issues.
13
+ * Unit tests. Suite runs via node or browser harness.
14
+
15
+ ## 0.1.0 (2011-12-23)
16
+
17
+ * First release. Extracted from the Do web client, based on Paul Gallagher's
18
+ [rfc3339date.js library][rfc3339date.js].
19
+
20
+
21
+
22
+ [ecmascript]: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
23
+ [rfc3339date.js]: https://github.com/tardate/rfc3339date.js
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Paul GALLAGHER (http://tardate.com)
2
+ Copyright (c) 2011 Do (http://do.com)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ all:
2
+ mkdir -p ./out
3
+ ./node_modules/.bin/coffee -o out -c lib/iso8601.coffee
4
+ ./node_modules/.bin/uglifyjs -o out/iso8601.js.min out/iso8601.js
5
+
6
+ clean:
7
+ rm out/*
8
+
9
+ test:
10
+ TZ='PST+8' ./node_modules/.bin/mocha --reporter spec
11
+
12
+ testbrowser:
13
+ echo "Browse to http://localhost:8000/test/browser/index.html"
14
+ python -m SimpleHTTPServer
15
+
16
+ .PHONY: all clean test testbrowser
@@ -0,0 +1,124 @@
1
+ iso8601.js
2
+ ==========
3
+
4
+ Partial ECMAScript 5.1 Date object cross-browser polyfill to add
5
+ a [ISO 8601][iso8601] support to **Date.parse** and
6
+ **Date.prototype.toISOString**. Originally based on Paul Gallagher's
7
+ a [rfc3339date.js library][rfc3339date.js].
8
+
9
+ Supports only the subset of ISO 8601 described in
10
+ a [ECMAScript 5.1 section 15.9.4.2][ecmascript], [RFC 3339][rfc3339], and the
11
+ a [Date and Time Formats W3C NOTE][w3c-note].
12
+
13
+
14
+ ## Usage
15
+
16
+ Download [iso8601.js][downloads] and include as usual before other scripts:
17
+
18
+ ```html
19
+ <script src="iso8601.min.js"></script>
20
+ ```
21
+
22
+ If you're using [Sprockets 2][sprockets], you can use the gem version of the
23
+ library. Add to your Gemfile:
24
+
25
+ ```ruby
26
+ gem 'iso8601-js'
27
+ ```
28
+
29
+ If using Rails 3.1+, the library is automatically added to your asset paths.
30
+ Otherwise add `ISO8601JS.assets_path` to your Sprockets environment:
31
+
32
+ ```ruby
33
+ env = Sprockets::Environment.new # or however you initialize Sprockets
34
+ env.append_path ISO8601JS.assets_path
35
+ ```
36
+
37
+ Then require it from the appropriate JavaScript or CoffeeScript files with the
38
+ `= require` Sprockets directive:
39
+
40
+ JavaScript:
41
+
42
+ ```javascript
43
+ //= require iso8601-js
44
+ ```
45
+
46
+ CoffeeScript:
47
+
48
+ ```coffee-script
49
+ #= require iso8601-js
50
+ ```
51
+
52
+
53
+ ## Parsing
54
+
55
+ Parse ISO 8601 date/time strings two ways:
56
+
57
+ * **Date.parseISO8601("...")** builds a Date instance from a string containing
58
+ an ISO 8610 date.
59
+ * **Date.parse("...")** is polyfilled to attempt ISO 8601 parsing on the string
60
+ before using the browser's native `Date.parse`. Returns the number of
61
+ milliseconds between the Unix epoch and the date.
62
+
63
+ Examples:
64
+
65
+ ```js
66
+ console.log(Date.parseISO8601("2010-07-20T15:00:00Z"))
67
+ // => Tue Jul 20 2010 08:00:00 GMT-0700 (PDT)
68
+
69
+ console.log(Date.parse("2010-07-20T15:00:00Z"));
70
+ // => 1307834445456
71
+ ```
72
+
73
+
74
+ ## Formatting
75
+
76
+ Format ISO 8601 date strings directly from Date instances:
77
+
78
+ * **Date.prototype.toISOString** generates an ISO 8601 string in UTC.
79
+ * **Date.prototype.toISO8601String** generates an ISO 8601 string with
80
+ formatting options:
81
+ * *localTimezone*: Use local timezone with offset or UTC? Defaults to *false*.
82
+ * *separators*: Include date/time separator? Defaults to *true*.
83
+ * *milliseconds*: Include milliseconds? Defaults to *true*.
84
+
85
+ Examples:
86
+
87
+ ```js
88
+ var date = Date.parseISO8601("2010-07-20T15:00:00Z");
89
+
90
+ console.log(date.toISOString());
91
+ // => "2010-07-20T15:00:00.000Z"
92
+
93
+ console.log(date.toISO8601String(true, true, false));
94
+ // => "2010-07-20T08:00:00-07:00"
95
+ ```
96
+
97
+
98
+ ## Caveats
99
+
100
+ The Date constructor is not polyfilled to support ISO 8601. Avoid using `new
101
+ Date("...")` to parse strings.
102
+
103
+
104
+ ## Contributing
105
+
106
+ iso8601.js is written in [CoffeeScript][coffeescript]. Use `npm install` to
107
+ install required development packages. Compile minified JavaScript output with
108
+ `make`. Run the test suite via `make test`.
109
+
110
+ Patches and bug reports are always welcome. Just send a
111
+ [pull request][pullrequests] or file an [issue][issues].
112
+
113
+
114
+
115
+ [iso8601]: http://en.wikipedia.org/wiki/ISO_8601
116
+ [rfc3339date.js]: https://github.com/tardate/rfc3339date.js
117
+ [ecmascript]: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
118
+ [rfc3339]: http://www.ietf.org/rfc/rfc3339.txt
119
+ [w3c-note]: http://www.w3.org/TR/NOTE-datetime
120
+ [downloads]: https://github.com/Do/iso8601.js/downloads
121
+ [sprockets]: https://github.com/sstephenson/sprockets
122
+ [coffeescript]: http://coffeescript.org/
123
+ [pullrequests]: https://github.com/Do/iso8601.js/pulls
124
+ [issues]: https://github.com/Do/iso8601.js/issues
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/iso8601-js/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'iso8601-js'
7
+ gem.version = ISO8601JS::VERSION
8
+ gem.authors = ['Gopal Patel', 'David Yung', 'Sai Tun']
9
+ gem.email = ['nixme@stillhope.com', 'azethoth@do.com', 'sai@do.com']
10
+ gem.license = 'MIT'
11
+ gem.homepage = 'https://github.com/Do/iso8601.js'
12
+ gem.summary = 'Sprockets asset gem for the iso8601.js EC5.1 polyfill library'
13
+ gem.description = 'Adds cross-browser ISO 8601 support to the JavaScript Date object based on EC5.1. This is a Sprockets gem to simplify inclusion of the client-side library.'
14
+
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.require_paths = ['lib']
19
+
20
+ # Dependencies
21
+ gem.add_dependency 'sprockets', '~> 2.0'
22
+ gem.add_dependency 'coffee-script', '~> 2.2'
23
+ gem.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'iso8601-js/version'
2
+
3
+ module ISO8601JS
4
+ ASSETS_PATH = File.expand_path('..', __FILE__).freeze
5
+
6
+ def self.assets_path
7
+ ASSETS_PATH
8
+ end
9
+
10
+
11
+ # Automatic initialization if used with Rails 3.1+
12
+ if defined? ::Rails::Railtie
13
+ class Railtie < ::Rails::Railtie
14
+ initializer 'iso8601-js', :after => 'sprockets.environment' do |app|
15
+ app.assets.append_path(ISO8601JS.assets_path) if app.assets
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module ISO8601JS
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,236 @@
1
+ # iso8601.js
2
+ #
3
+ # Partial ECMAScript 5.1 Date object polyfill to support the ISO 8601 format
4
+ # specified in section 15.9.1.15 in Date.parse (section 15.9.4.2) and
5
+ # Date.prototype.toISOString (section 15.9.5.43). ISO 8601 formats from RFC 3339
6
+ # and the W3C Date and Time Formats NOTE (http://www.w3.org/TR/NOTE-datetime)
7
+ # are also supported.
8
+ #
9
+ # Adds string parsing and formatting functions directly to the native Date
10
+ # object and prototype. Uses native functionality where available.
11
+ #
12
+ # Examples
13
+ #
14
+ # Date.parse("2010-07-20T15:00:00Z")
15
+ # // => 1307834445456
16
+ #
17
+ # date = Date.parseISO8601("2010-07-20T15:00:00Z")
18
+ # // => Tue Jul 20 2010 08:00:00 GMT-0700 (PDT)
19
+ #
20
+ # date.toISOString()
21
+ # // => "2010-07-20T15:00:00.000Z"
22
+ #
23
+ # date.toISO8601String(true)
24
+ # // => "2010-07-20T08:00:00.000-07:00"
25
+ #
26
+ # Note: Avoid using "new Date(...)" to parse ISO 8601 strings since this library
27
+ # does not polyfill the Date constructor.
28
+ #
29
+ #
30
+ # Originally based on Paul Gallagher's rfc3339date.js library
31
+ # https://github.com/tardate/rfc3339date.js
32
+ # Copyright (c) 2010 Paul GALLAGHER http://tardate.com
33
+ #
34
+ # Additional modifications by the Do team
35
+ # Copyright (c) 2011 Do http://do.com
36
+ #
37
+ # Licensed under the MIT license
38
+ # http://www.opensource.org/licenses/mit-license.php
39
+ #
40
+
41
+
42
+
43
+ # Helper function to left-pad numbers to the specified length
44
+ pad = (number, length = 2) ->
45
+ result = number.toString()
46
+ while result.length < length
47
+ result = '0' + result
48
+ result
49
+
50
+ # Unit tests to check native ISO 8601 support
51
+ supportsISOParsing = Date.parse?('2011-06-11T23:20:45.456-0700') is 1307859645456
52
+ supportsISOFormatting = Date::toISOString?
53
+
54
+
55
+
56
+ # Date.prototype.toISO8601String
57
+ #
58
+ # Format the date in ISO 8601 / RFC 3339 with custom rules. With no parameters,
59
+ # output is equivalent to the ECMAScript 5.1 defined Date.prototype.toISOString.
60
+ #
61
+ # localTimezone - Use local timezone or UTC offset? (default: false, i.e. UTC)
62
+ # separators - Include date/time separators? (default: true)
63
+ # milliseconds - Include milliseconds? (default: true)
64
+ #
65
+ # Examples
66
+ #
67
+ # new Date().toISO8601String(true)
68
+ # // => "2010-07-25T19:51:31.427+08:00"
69
+ #
70
+ # new Date().toISO8601String(true)
71
+ # // => "2010-07-25T19:51:31.427+08:00"
72
+ #
73
+ # new Date().toISO8601String(true)
74
+ # // => "2010-07-25T19:51:31.427+08:00"
75
+ #
76
+ Date::toISO8601String = (localTimezone = false, separators = true, milliseconds = true) ->
77
+ # Raise RangeError for invalid dates
78
+ timet = @getTime()
79
+ if timet != timet # isNaN
80
+ throw new RangeError 'Invalid date'
81
+
82
+ dateSeparator = if separators then '-' else ''
83
+ timeSeparator = if separators then ':' else ''
84
+
85
+ result =
86
+ if localTimezone
87
+ @getFullYear().toString() + dateSeparator +
88
+ pad(@getMonth() + 1) + dateSeparator +
89
+ pad(@getDate()) + 'T' +
90
+ pad(@getHours()) + timeSeparator +
91
+ pad(@getMinutes()) + timeSeparator +
92
+ pad(@getSeconds())
93
+ else
94
+ @getUTCFullYear().toString() + dateSeparator +
95
+ pad(@getUTCMonth() + 1) + dateSeparator +
96
+ pad(@getUTCDate()) + 'T' +
97
+ pad(@getUTCHours()) + timeSeparator +
98
+ pad(@getUTCMinutes()) + timeSeparator +
99
+ pad(@getUTCSeconds())
100
+
101
+ if milliseconds
102
+ result += '.' +
103
+ pad (if localTimezone then @getMilliseconds() else @getUTCMilliseconds()), 3
104
+
105
+ if localTimezone
106
+ tzOffset = @getTimezoneOffset()
107
+ if tzOffset >= 0
108
+ result += '-'
109
+ else
110
+ result += '+'
111
+ tzOffset *= -1
112
+ result + pad(tzOffset / 60) + timeSeparator + pad(tzOffset % 60)
113
+ else
114
+ result + 'Z'
115
+
116
+
117
+
118
+ # Date.prototype.toISOString
119
+ #
120
+ # Format the date in UTC ISO 8601 / RFC 3339.
121
+ #
122
+ # Defined in ECMAScript 5.1 section 15.9.5.43. An implementation is set only if
123
+ # the browser lacks native support.
124
+ #
125
+ # Examples
126
+ #
127
+ # new Date().toISOString()
128
+ # // => "2010-07-25T11:51:31.427Z"
129
+ #
130
+ unless supportsISOFormatting
131
+ Date::toISOString = Date::toISO8601String
132
+
133
+
134
+
135
+ # Date.parseISO8601
136
+ #
137
+ # Parses ISO8601 / RFC 3339 date strings to a Date object. Uses native browser
138
+ # parsing if available.
139
+ #
140
+ # input - The String to parse.
141
+ # useNative - Use browser native parsing if available? (default: true)
142
+ #
143
+ # Examples
144
+ #
145
+ # Date.parseISO8601("2010-07-20T15:00:00Z")
146
+ # // => ....
147
+ #
148
+ ISO8601_PATTERN = ///
149
+ (\d\d\d\d) # year
150
+ (-)?
151
+ (\d\d) # month
152
+ (-)?
153
+ (\d\d) # day
154
+ (T)?
155
+ (\d\d) # hour
156
+ (:)?
157
+ (\d\d)? # minute
158
+ (:)?
159
+ (\d\d)? # seconds
160
+ ([\.,]\d+)? # milliseconds
161
+ (
162
+ $| # end of input = no timezone information
163
+ Z| # UTC
164
+ ([+-]) # offset direction
165
+ (\d\d) # offset hours
166
+ (:)?
167
+ (\d\d)? # offset minutes
168
+ )
169
+ ///i
170
+
171
+ DECIMAL_SEPARATOR = String(1.5).charAt(1)
172
+
173
+ parseISO8601 = (input) ->
174
+ type = Object::toString.call(input)
175
+
176
+ # Return the input if it's already a Date instance
177
+ return input if type == '[object Date]'
178
+
179
+ # Can only parse Strings
180
+ return undefined unless type == '[object String]'
181
+
182
+ if matches = input.match(ISO8601_PATTERN)
183
+ year = parseInt(matches[1], 10)
184
+ month = parseInt(matches[3], 10) - 1
185
+ day = parseInt(matches[5], 10)
186
+ hour = parseInt(matches[7], 10)
187
+ minutes = if matches[9] then parseInt(matches[9], 10) else 0
188
+ seconds = if matches[11] then parseInt(matches[11], 10) else 0
189
+ milliseconds =
190
+ if matches[12]
191
+ parseFloat(DECIMAL_SEPARATOR + matches[12][1..]) * 1000
192
+ else
193
+ 0
194
+
195
+ result = Date.UTC(year, month, day, hour, minutes, seconds, milliseconds)
196
+ if matches[13] && matches[14] # Timezone adjustment
197
+ offset = matches[15] * 60
198
+ offset += parseInt(matches[17], 10) if (matches[17])
199
+ offset *= if matches[14] is '-' then -1 else 1
200
+ result -= offset * 60 * 1000
201
+ new Date(result)
202
+
203
+ if supportsISOParsing
204
+ Date.parseISO8601 = (input, useNative = true) ->
205
+ if useNative # Use the default Date constructor, we have native support.
206
+ new Date(input)
207
+ else # Force the polyfill.
208
+ parseISO8601 input
209
+ else # No native support, always use polyfill.
210
+ Date.parseISO8601 = parseISO8601
211
+
212
+
213
+
214
+ # Date.parse
215
+ #
216
+ # Parses date strings; returns time in milliseconds since the Unix epoch. See
217
+ # http://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/parse
218
+ #
219
+ # This polyfills the standard Date.parse to support ISO 8601 / RFC 3339 date
220
+ # strings only if the browser doesen't have native support.
221
+ #
222
+ # Examples
223
+ #
224
+ # Date.parse("2010-07-20T15:00:00Z")
225
+ # // => 1279638000000
226
+ #
227
+ if Object::toString.call(Date.parse) != '[object Function]'
228
+ # No built-in Date.parse, use our version.
229
+ Date.parse = (input) -> parseISO8601(input)?.getTime()
230
+ else if not supportsISOParsing
231
+ # No native ISO 8601 parsing, chain our version
232
+ oldDateParse = Date.parse
233
+ Date.parse = (input) ->
234
+ result = parseISO8601(input)?.getTime()
235
+ result = oldDateParse(input) if not result and oldDateParse
236
+ result
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "iso8601",
3
+ "description": "EC5.1 Date polyfill for ISO8601 support",
4
+ "version": "0.2.0",
5
+ "keywords": ["date", "time", "iso8601", "polyfill", "shim"],
6
+ "contributors": [
7
+ {
8
+ "name": "Gopal Patel",
9
+ "email": "nixme@stillhope.com"
10
+ },
11
+ {
12
+ "name": "David Yung",
13
+ "email": "azethoth@do.com"
14
+ },
15
+ {
16
+ "name": "Sai Tun",
17
+ "email": "sai@do.com"
18
+ }
19
+ ],
20
+ "homepage": "https://github.com/Do/iso8601.js",
21
+ "bugs": "https://github.com/Do/iso8601.js/issues",
22
+ "licenses": [
23
+ {
24
+ "type": "MIT",
25
+ "url": "https://raw.github.com/Do/iso8601.js/master/LICENSE"
26
+ }
27
+ ],
28
+ "repositories": [
29
+ {
30
+ "type": "git",
31
+ "url": "https://github.com/Do/iso8601.js.git"
32
+ }
33
+ ],
34
+ "devDependencies": {
35
+ "coffee-script": "1.2.0",
36
+ "uglify-js": "1.2.2",
37
+ "mocha": "0.7.1",
38
+ "chai": "0.1.4"
39
+ }
40
+ }
@@ -0,0 +1,151 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6
+
7
+ <title>iso8601.js Tests</title>
8
+
9
+ <style type="text/css">
10
+ body {
11
+ font: 20px/1.5 "Helvetica Neue", Helvetica, Aria;, sans-serif;
12
+ padding: 60px 50px;
13
+ }
14
+
15
+ #mocha h1, h2 {
16
+ margin: 0;
17
+ }
18
+
19
+ #mocha h1 {
20
+ font-size: 1em;
21
+ font-weight: 200;
22
+ }
23
+
24
+ #mocha .suite .suite h1 {
25
+ font-size: .8em;
26
+ }
27
+
28
+ #mocha h2 {
29
+ font-size: 12px;
30
+ font-weight: normal;
31
+ cursor: pointer;
32
+ }
33
+
34
+ #mocha .suite {
35
+ margin-left: 15px;
36
+ }
37
+
38
+ #mocha .test {
39
+ margin-left: 15px;
40
+ }
41
+
42
+ #mocha .test:hover h2::after {
43
+ position: relative;
44
+ top: 0;
45
+ right: -10px;
46
+ content: '(view source)';
47
+ font-size: 12px;
48
+ color: #888;
49
+ }
50
+
51
+ #mocha .test.pass::before {
52
+ content: '✓';
53
+ font-size: 12px;
54
+ display: block;
55
+ float: left;
56
+ margin-right: 5px;
57
+ color: #00c41c;
58
+ }
59
+
60
+ #mocha .test.pending {
61
+ color: #0b97c4;
62
+ }
63
+
64
+ #mocha .test.pending::before {
65
+ content: '◦';
66
+ color: #0b97c4;
67
+ }
68
+
69
+ #mocha .test.fail {
70
+ color: #c00;
71
+ }
72
+
73
+ #mocha .test.fail pre {
74
+ color: black;
75
+ }
76
+
77
+ #mocha .test.fail::before {
78
+ content: '✖';
79
+ font-size: 12px;
80
+ display: block;
81
+ float: left;
82
+ margin-right: 5px;
83
+ color: #c00;
84
+ }
85
+
86
+ #mocha .test pre.error {
87
+ color: #c00;
88
+ }
89
+
90
+ #mocha .test pre {
91
+ display: inline-block;
92
+ font: 12px/1.5 monaco, monospace;
93
+ margin: 5px;
94
+ padding: 15px;
95
+ border: 1px solid #eee;
96
+ border-bottom-color: #ddd;
97
+ -webkit-border-radius: 3px;
98
+ -webkit-box-shadow: 0 1px 3px #eee;
99
+ }
100
+
101
+ #error {
102
+ color: #c00;
103
+ font-size: 1.5 em;
104
+ font-weight: 100;
105
+ letter-spacing: 1px;
106
+ }
107
+
108
+ #stats {
109
+ position: fixed;
110
+ top: 30px;
111
+ right: 30px;
112
+ font-size: 12px;
113
+ margin: 0;
114
+ color: #888;
115
+ }
116
+
117
+ #stats .progress {
118
+ margin-bottom: 10px;
119
+ }
120
+
121
+ #stats em {
122
+ color: black;
123
+ }
124
+
125
+ #stats li {
126
+ list-style: none;
127
+ }
128
+ </style>
129
+
130
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
131
+ <script src="https://raw.github.com/visionmedia/mocha/0.7.1/mocha.js" type="text/javascript"></script>
132
+ <script src="https://raw.github.com/logicalparadox/chai/0.1.4/chai.js" type="text/javascript"></script>
133
+ <script src="https://raw.github.com/jashkenas/coffee-script/1.2.0/extras/coffee-script.js" type="text/javascript"></script>
134
+
135
+ <!-- Initialize mocha -->
136
+ <script type="text/coffeescript">mocha.setup('bdd')</script>
137
+
138
+ <!-- Load library under test -->
139
+ <script src="../../lib/iso8601.coffee" type="text/coffeescript"></script>
140
+
141
+ <!-- Load test cases -->
142
+ <script src="../test.date.coffee" type="text/coffeescript"></script>
143
+
144
+ <!-- Run the tests! -->
145
+ <script type="text/coffeescript">$(-> mocha.run())</script>
146
+ </head>
147
+
148
+ <body>
149
+ <div id="mocha"></div>
150
+ </body>
151
+ </html>
@@ -0,0 +1,71 @@
1
+ # Tests for the polyfill parsing and formatting functions. Browser native
2
+ # support detection and usage untested.
3
+ #
4
+ # For proper testing of timezone offsets, the suite must be run in the PST (non
5
+ # daylight savings) timezone environment, e.g. TZ='PST+8'.
6
+ #
7
+
8
+ chai = @chai || require('chai')
9
+ assert = chai.assert
10
+ expect = chai.expect
11
+ require('../lib/iso8601') if require?
12
+
13
+ describe 'Date', ->
14
+
15
+ # Date fixture: Sat Jun 18, 2011 02:20:45.678 PST
16
+ date = new Date(1308392445678)
17
+
18
+ describe 'toISO8601String', ->
19
+
20
+ it 'defaults to UTC with date/time separators and milliseconds', ->
21
+ assert.equal '2011-06-18T10:20:45.678Z', date.toISO8601String()
22
+
23
+ it 'produces same output as toISOString', ->
24
+ assert.equal date.toISO8601String(), date.toISOString()
25
+
26
+ it 'can format without date/time separators', ->
27
+ assert.equal '20110618T102045.678Z', date.toISO8601String(false, false, true)
28
+
29
+ it 'can format without milliseconds', ->
30
+ assert.equal '2011-06-18T10:20:45Z', date.toISO8601String(false, true, false)
31
+
32
+ it 'can format without date/time separators and milliseconds', ->
33
+ assert.equal '20110618T102045Z', date.toISO8601String(false, false, false)
34
+
35
+ it 'can format in local timezone and include offset', ->
36
+ assert.equal '2011-06-18T02:20:45.678-08:00', date.toISO8601String(true, true, true)
37
+
38
+ it 'throws RangeError for Invalid Dates', ->
39
+ fn = -> new Date('not a date').toISO8601String()
40
+ expect(fn).to.throw RangeError
41
+
42
+
43
+ describe 'parseISO8601', ->
44
+
45
+ it 'parses UTC ISO 8601 strings', ->
46
+ assert.equal date.getTime(), Date.parseISO8601('2011-06-18T10:20:45.678Z', false).getTime()
47
+
48
+ it 'parses ISO 8601 strings with timezone offsets', ->
49
+ assert.equal date.getTime(), Date.parseISO8601('2011-06-18T02:20:45.678-08:00', false).getTime()
50
+
51
+ it 'returns the input if given a Date instance', ->
52
+ assert.equal date, Date.parseISO8601(date, false)
53
+
54
+ it 'returns undefined for non-String input', ->
55
+ assert.isUndefined Date.parseISO8601(2, false)
56
+ assert.isUndefined Date.parseISO8601((-> 1), false)
57
+
58
+ it 'returns undefined for invalid string inputs', ->
59
+ assert.isUndefined Date.parseISO8601('this is not a date', false)
60
+
61
+
62
+ describe 'parse', ->
63
+
64
+ it 'parses UTC ISO 8601 strings to epoch milliseconds', ->
65
+ assert.equal 1307834445456, Date.parse('2011-06-11T23:20:45.456Z')
66
+
67
+ it 'parses ISO 8601 strings with timezone offsets to epoch milliseconds', ->
68
+ assert.equal 1307859645456, Date.parse('2011-06-11T23:20:45.456-0700')
69
+
70
+ it 'falls back to native Date.parse for non ISO strings', ->
71
+ assert.equal 807926400000, Date.parse('Wed, 09 Aug 1995 00:00:00 GMT')
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iso8601-js
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gopal Patel
9
+ - David Yung
10
+ - Sai Tun
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-12-27 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: sprockets
18
+ requirement: &70341578450300 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '2.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70341578450300
27
+ - !ruby/object:Gem::Dependency
28
+ name: coffee-script
29
+ requirement: &70341578449500 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '2.2'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70341578449500
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ requirement: &70341578448740 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *70341578448740
49
+ description: Adds cross-browser ISO 8601 support to the JavaScript Date object based
50
+ on EC5.1. This is a Sprockets gem to simplify inclusion of the client-side library.
51
+ email:
52
+ - nixme@stillhope.com
53
+ - azethoth@do.com
54
+ - sai@do.com
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - .gitignore
60
+ - CHANGELOG.md
61
+ - Gemfile
62
+ - LICENSE
63
+ - Makefile
64
+ - README.md
65
+ - Rakefile
66
+ - iso8601-js.gemspec
67
+ - lib/iso8601-js.rb
68
+ - lib/iso8601-js/version.rb
69
+ - lib/iso8601.coffee
70
+ - package.json
71
+ - test/browser/index.html
72
+ - test/test.date.coffee
73
+ homepage: https://github.com/Do/iso8601.js
74
+ licenses:
75
+ - MIT
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.10
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Sprockets asset gem for the iso8601.js EC5.1 polyfill library
98
+ test_files:
99
+ - test/browser/index.html
100
+ - test/test.date.coffee