File tree Expand file tree Collapse file tree 4 files changed +35
-14
lines changed Expand file tree Collapse file tree 4 files changed +35
-14
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,7 @@ window.load_screen_timeout = window.setTimeout(function()
220220<script src =" ./lib/nodelistprototype.js" />
221221<script src =" ./lib/objectnamespace.js" />
222222<script src =" ./lib/operanamespace.js" />
223+ <script src =" ./lib/datenamespace.js" />
223224<script src =" ./lib/stringprototype.js" />
224225<script src =" ./lib/stylesheetlistprototype.js" />
225226<script src =" ./lib/xmlhttprequestprototype.js" />
Original file line number Diff line number Diff line change @@ -430,21 +430,13 @@ cls.CookieManager.CookieManagerViewBase = function()
430430 // "domain" is val of [input] (with add_cookie service present), or runtimes .hostname
431431 var domain = domain_input && domain_input . value . trim ( ) || runtime && this . data . _rts [ runtime ] . hostname ;
432432
433- // Check if the value retrieved from datetime-local looks local (without trailing Z or +01:00)
434- var expires_is_local = / ^ \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } ( : \d { 2 } ( \. \d + ) ? ) ? $ / . test ( expires ) ;
435-
436433 // Remove "0" milliseconds to make sure Date can parse the string (see CORE-47780).
437434 // Milliseconds are always 0 for cookies.
438435 // This make sense even if we got a UTC value or a value with timezone-offset.
439- expires = expires . replace ( / \. 0 + / , "" ) ;
436+ expires = expires . replace ( / \. 0 + / , "" ) ;
440437
441- if ( expires_is_local )
442- expires = Date . fromLocaleISOString ( expires ) . getTime ( ) ;
443- else if ( expires )
444- expires = new Date ( expires ) . getTime ( ) ;
445- // If the value retrieved from datetime-local is "", the cookie expires when the session ends.
446- else
447- expires = 0 ;
438+ // Attempt to treat this as localeISOString first.
439+ expires = Date . fromLocaleISOString ( expires ) || Date . parse ( expires ) || 0 ;
448440
449441 var object_id = edit_tr . getAttribute ( "data-object-id" ) ;
450442 var old_cookie ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Local ISO strings, currently needed as datetime-local input values
3+ * http://dev.w3.org/html5/markup/input.datetime-local.html#input.datetime-local.attrs.value
4+ */
5+ Date . fromLocaleISOString = function ( localeISOString )
6+ {
7+ var is_local = / ^ \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } ( : \d { 2 } ( \. \d + ) ? ) ? $ / . test ( localeISOString ) ;
8+ if ( ! is_local )
9+ return NaN ;
10+
11+ var date = new Date ( localeISOString ) ;
12+
13+ // Test if Date parsed the value as a UTC string.
14+ // If it does, add the current timezone offset to get the local time.
15+ // When the current timezone offset is 0, this will be a false positive,
16+ // but that doesn't matter since we correct the value by 0 then.
17+ var milliseconds = date . getTime ( ) ;
18+ if ( milliseconds === new Date ( localeISOString + "Z" ) . getTime ( ) )
19+ {
20+ var timezone_offset = date . getTimezoneOffset ( ) * 1000 * 60 ;
21+ milliseconds += timezone_offset ;
22+ }
23+ return milliseconds ;
24+ } ;
Original file line number Diff line number Diff line change 44 < title > Dragonfly - Locale ISO strings</ title >
55 < link rel ="stylesheet " href ="qunit/qunit.css " media ="screen ">
66 < script src ="qunit/qunit.js "> </ script >
7- < script src ="../src/scripts/dom.js "> </ script >
7+ < script src ="../src/lib/dateprototype.js "> </ script >
8+ < script src ="../src/lib/datenamespace.js "> </ script >
89
910
1011< script >
2526
2627 // The outcome of toLocaleISOString depends on the timezone.
2728 // The expected moment needs to be adjusted.
28- var t = Date . fromLocaleISOString ( "2012-08-03T17:00" ) . getTime ( ) ;
29- equal ( t , 1344013200000 + TIMEZONE_OFFSET ) ;
29+ var ms = Date . fromLocaleISOString ( "2012-08-03T17:00" ) ;
30+ equal ( ms , 1344013200000 + TIMEZONE_OFFSET ) ;
31+
32+ var ms = Date . fromLocaleISOString ( "2012-08-03T17:00+02:00" ) ;
33+ equal ( isNaN ( ms ) , true ) ;
3034} ) ;
3135
3236
You can’t perform that action at this time.
0 commit comments