Script.apex icon indicating copy to clipboard operation
Script.apex copied to clipboard

TimeNode test fails in GMT

Open aranwe opened this issue 4 years ago • 1 comments

Test JsepTest.timeTest() fails on line 204 for User with GMT timezone:

JsepTest.cls

...
        node = (Jsep.TimeNode )new Jsep(s4).parse();
        System.assertEquals(true, node.value!=v); // line 204
        System.assertEquals(node.getType(), Jsep.JSEP_TIME);
...

Repro

Given you execute anonymously:

String s = '01:08:54.474';
String s4= '1:8:54.474Z';
Time v = (Time)JSON.deserialize('"' + s + '"', Time.class);
Jsep.TimeNode node = (Jsep.TimeNode )new Jsep(s4).parse();

System.debug(node.value!=v);
System.debug(node.value);
System.debug(v);

Then for User with timezone "Africa/Brazzaville" prints:

05:54:42.68 (80498067)|USER_DEBUG|[6]|DEBUG|true
05:54:42.68 (80559117)|USER_DEBUG|[7]|DEBUG|01:08:54.474Z
05:54:42.68 (80574435)|USER_DEBUG|[8]|DEBUG|09:08:54.474Z

For User with timezone "GMT" (or any other GMT+00:00) prints:

12:58:44.88 (100847623)|USER_DEBUG|[6]|DEBUG|false
12:58:44.88 (100898952)|USER_DEBUG|[7]|DEBUG|01:08:54.474Z
12:58:44.88 (100916055)|USER_DEBUG|[8]|DEBUG|01:08:54.474Z

aranwe avatar Sep 29 '21 13:09 aranwe

I think that the test is bad, not the behaviour as s and subsequently v is in local timezone however s4 is always in GMT -> the test assumes that the user is not in GMT.

However I've tried to play with the offset and I am not sure I am getting the behaviour:

String s = '02:08:54.474';
String s4= '2:8:54.474Z';
Time v = (Time)JSON.deserialize('"' + s + '"', Time.class);

Jsep.TimeNode node = (Jsep.TimeNode )new Jsep(s4).parse();

DateTime now = DateTime.now();
Integer offset = (DateTime.newInstance(now.date(), now.time()).getTime()
    - DateTime.newInstance(now.dateGmt(), now.timeGmt()).getTime()).intValue();

System.debug(offset);
System.debug(node.value==v.addMilliseconds(offset));
System.debug(node.value);
System.debug(v);
System.debug(v.addMilliseconds(offset));

when in (GMT+10:30) Lord Howe Standard Time (Australia/Lord_Howe) TZ prints:

23:47:47.137 (157712680)|USER_DEBUG|[11]|DEBUG|37800000
23:47:47.137 (157845796)|USER_DEBUG|[12]|DEBUG|false
23:47:47.137 (157881363)|USER_DEBUG|[13]|DEBUG|02:08:54.474Z
23:47:47.137 (157909553)|USER_DEBUG|[14]|DEBUG|16:08:54.474Z
23:47:47.137 (157968698)|USER_DEBUG|[15]|DEBUG|02:38:54.474Z

-> it's half an hour off however 37800000 is indeed 10:30hrs. This leaves me to think there is something else at play here.

aranwe avatar Sep 29 '21 13:09 aranwe