Setting timezoneOffset gives incorrect time when parsing relative time
See original GitHub issueprocess.env.TZ='utc';
var relative = chrono.parse("in two minutes");
relative[0].start.assign('timezoneOffset', 120);
console.log(relative[0].start.date()); //2017-02-09T07:21:17.000Z
var absolute_date = new Date();
absolute_date.setMinutes(absolute_date.getMinutes()+2);
var absolute = chrono.parse(`${absolute_date.getHours()}:${absolute_date.getMinutes()}`);
relative[0].start.assign('timezoneOffset', 120);
console.log(absolute[0].start.date()); //2017-02-09T09:21:00.000Z
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Parser.parse changes to wrong time zone - Stack Overflow
I am using from dateutil import parser to parse an input but for some reason it is giving me back the wrong timezone....
Read more >Handling Time Zone in JavaScript - TOAST UI - Medium
The difference of time between UTC standard time and the local time is called “offset”, which is expressed in this way: +09:00 ,...
Read more >How to handle Time Zones in JavaScript - Bits and Pieces
ISOString — It can parse a text containing any time zone's numeric UTC offset. The output Date object does not keep the original...
Read more >Converting between DateTime and DateTimeOffset
LocalDateTime property to perform both a type and a time zone conversion. The sample output is for a machine set to the Pacific...
Read more >Demystifying DateTime Manipulation in JavaScript - Toptal
This problem of managing two different versions of the time, relative to the ... Once you know how to parse a date and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you @wanasit for the clear and detailed response. The inner workings of your library are much clearer now after reading this. Respectfully, I still feel that there is a bug in specific cases where the implied values are derived from system time. In these cases, specifying a timezone will result in a time shift. Logically, I understand how this case occurs and it very well may be a case of ‘working as designed’
To give you some background, I’m processing text from all over the world. I do know ahead of time which timezone the text will originate from, so I feel comfortable using a refiner as you suggested to set a known value for
timezoneOffeset
However, if I do set this, then situations like ‘now’ still present a problem because it appears that the implied time values originate from system time. So it will imply the system hour, minute, second based on the system time.When I then tell it that I have a known timezone, it’s still using the implied values that originated from my system, combined with a known timezone offset, which results in a time shift.
The implication of this is that I would need to conditionally apply the
timezoneOffset
value only in cases where the implied values are not derived from system time. Since I don’t know the nature of the text ahead of time, an ideal situation would allow me to notify the parser to expect inputs to be in specified timezone, and then situations like ‘now’ or ‘in two minutes’, where timezone is irrelevant, would simply ignore that value.I’ve also provided a runkit notebook to illustrate the problem. https://runkit.com/pthoresen/5944c4065e466600126d5001
I think you miss understand the Chrono’s
ParsedComponents
andassign('timezoneOffset', ..)
.The component is machine’s timezone independent. The component’s
timezoneOffset
is the parsed timezone or the timezone mentioned in the input.The
date()
function create Javascript Date object from the component, which includes adjusting the parsed timezone into your local system (The Date object is also actually machine independent timestamp, but we still need to adjust the mentioned timezone into correct timestamp). If the component doesn’t have timezone then, only that point, it assume that the parsed timezone is the same as the current timezone.So, if you know that all of your text/input will come from a specific timezone, you could write a refiner that assign the timezone to all the results.
But, if you are thinking about using
assign('timezoneOffset', ..)
to transform the output to into a specific timezone, then you are doing it wrong.Again, ‘timezoneOffset’ is all about the timezone mentioned in the text, not output or machine timezone.