Fixed App.i18n.translateTimestamp() to work on browser with different timezones.
This commit is contained in:
parent
bc17d5c19b
commit
28dfddd612
2 changed files with 20 additions and 13 deletions
|
@ -19,10 +19,10 @@ class App.i18n
|
||||||
_instance ?= new _i18nSingleton
|
_instance ?= new _i18nSingleton
|
||||||
_instance.translateInline( string, args )
|
_instance.translateInline( string, args )
|
||||||
|
|
||||||
@translateTimestamp: ( args ) ->
|
@translateTimestamp: ( args, offset = 0 ) ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
_instance ?= new _i18nSingleton
|
_instance ?= new _i18nSingleton
|
||||||
_instance.timestamp( args )
|
_instance.timestamp( args, offset )
|
||||||
|
|
||||||
@get: ->
|
@get: ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
|
@ -170,13 +170,18 @@ class _i18nSingleton extends Spine.Module
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
.replace(/\x22/g, '"')
|
.replace(/\x22/g, '"')
|
||||||
|
|
||||||
timestamp: ( time ) =>
|
timestamp: ( time, offset ) =>
|
||||||
s = ( num, digits ) ->
|
s = ( num, digits ) ->
|
||||||
while num.toString().length < digits
|
while num.toString().length < digits
|
||||||
num = "0" + num
|
num = "0" + num
|
||||||
num
|
num
|
||||||
|
|
||||||
timeObject = new Date(time)
|
timeObject = new Date(time)
|
||||||
|
|
||||||
|
# add timezone diff, needed for unit tests
|
||||||
|
if offset
|
||||||
|
timeObject = new Date( timeObject.getTime() + (timeObject.getTimezoneOffset() * 60000) )
|
||||||
|
|
||||||
d = timeObject.getDate()
|
d = timeObject.getDate()
|
||||||
m = timeObject.getMonth() + 1
|
m = timeObject.getMonth() + 1
|
||||||
y = timeObject.getFullYear()
|
y = timeObject.getFullYear()
|
||||||
|
|
|
@ -207,17 +207,17 @@ App.Delay.set( function() {
|
||||||
test( "interval - test 1 - 1/2", function() {
|
test( "interval - test 1 - 1/2", function() {
|
||||||
|
|
||||||
// check
|
// check
|
||||||
equal( window.testInterval1, 3, 'interval - test 1' );
|
equal( window.testInterval1, 4, 'interval - test 1' );
|
||||||
App.Interval.clear('interval-test1')
|
App.Interval.clear('interval-test1')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
4400
|
5200
|
||||||
);
|
);
|
||||||
App.Delay.set( function() {
|
App.Delay.set( function() {
|
||||||
test( "interval - test 1 - 2/2", function() {
|
test( "interval - test 1 - 2/2", function() {
|
||||||
|
|
||||||
// check
|
// check
|
||||||
equal( window.testInterval1, 3, 'interval - test after clear' );
|
equal( window.testInterval1, 4, 'interval - test after clear' );
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
6500
|
6500
|
||||||
|
@ -237,17 +237,17 @@ App.Delay.set( function() {
|
||||||
test( "interval - test 2 - 1/2", function() {
|
test( "interval - test 2 - 1/2", function() {
|
||||||
|
|
||||||
// check
|
// check
|
||||||
equal( window.testInterval2, 3, 'interval - test 2' );
|
equal( window.testInterval2, 4, 'interval - test 2' );
|
||||||
App.Interval.clearLevel('someLevel')
|
App.Interval.clearLevel('someLevel')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
4500
|
5200
|
||||||
);
|
);
|
||||||
App.Delay.set( function() {
|
App.Delay.set( function() {
|
||||||
test( "interval - test 2 - 2/2", function() {
|
test( "interval - test 2 - 2/2", function() {
|
||||||
|
|
||||||
// check
|
// check
|
||||||
equal( window.testInterval2, 3, 'interval - test 2 - after clear' );
|
equal( window.testInterval2, 4, 'interval - test 2 - after clear' );
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
6900
|
6900
|
||||||
|
@ -265,8 +265,10 @@ test( "i18n", function() {
|
||||||
translated = App.i18n.translateContent('<test&now>//*äöüß');
|
translated = App.i18n.translateContent('<test&now>//*äöüß');
|
||||||
equal( translated, '<test&now>//*äöüß', 'de - <test&now>//*äöüß' );
|
equal( translated, '<test&now>//*äöüß', 'de - <test&now>//*äöüß' );
|
||||||
|
|
||||||
var timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z');
|
var time_local = new Date();
|
||||||
equal( timestamp, '06.11.2012 22:07', 'de - timestamp translated correctly' );
|
var offset = time_local.getTimezoneOffset();
|
||||||
|
var timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z', offset);
|
||||||
|
equal( timestamp, '06.11.2012 21:07', 'de - timestamp translated correctly' );
|
||||||
|
|
||||||
// en
|
// en
|
||||||
App.i18n.set('en');
|
App.i18n.set('en');
|
||||||
|
@ -276,8 +278,8 @@ test( "i18n", function() {
|
||||||
translated = App.i18n.translateContent('<test&now>');
|
translated = App.i18n.translateContent('<test&now>');
|
||||||
equal( translated, '<test&now>', 'en - <test&now>' );
|
equal( translated, '<test&now>', 'en - <test&now>' );
|
||||||
|
|
||||||
timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z');
|
timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z', offset);
|
||||||
equal( timestamp, '2012-11-06 22:07', 'en - timestamp translated correctly' );
|
equal( timestamp, '2012-11-06 21:07', 'en - timestamp translated correctly' );
|
||||||
});
|
});
|
||||||
|
|
||||||
// events
|
// events
|
||||||
|
|
Loading…
Reference in a new issue