Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util.convert): epoch times stored as strings convert correctly, unit test fixup, parse iso dates in local tz #699

Merged
merged 12 commits into from
Oct 5, 2020

Conversation

strazto
Copy link
Contributor

@strazto strazto commented Sep 30, 2020

Fixes #698
Fixes #697
Fixes #663

Squash preferred.

Please feel free to delete examples/timeline/testOffset.html before merging, there's no need to request I do it, I really don't mind.

ISO dates in local tz:

ISO date strings with no time/timezone are now parsed to midnight that date, in local time #663 .

This is consistent with handling of ISO datetime strings that include time, but omit timezone (also treated as local time).

This difference is demonstrated in new file: examples/timeline/testOffset.html.

This file is intended to demonstrate this bug fix only - Please feel free to delete examples/timeline/testOffset.html before merging.

While writing tests for this, I realized that previous test cases for parsers were not correctly capturing when parsing failed #697 .

Unit test fixup + treat numeric strings as epoch timestamps

This exposed another bug - the broken testcases implied that the following should be equivalent:

  • util.convert("111111", "Date)
  • util.convert(111111, "Date")

Once fixed, they exposed a (potential) bug, that util.convert("111111", "Date) yields and invalid date ( #698 ).

This is now handled

Small changes - refactor, and more specific error throwing / handling

Additional refactor for DRY in util.convert - util.convert(object, "Date") now calls util.convert(object, "Moment").toDate(). (Previously duplicated logic.

for type in ["Date", "Moment"]: util.convert(object, type)will return aTypeError, ( "Cannot convert object of type " + getType(object) + " to type " + type) , rather than a more general Error`.

Previously stated "Unable to convert to Date"

Now states "Unable to convert to moment"
Previously, "Date" & "Moment" had identical switch branches, but
each return statement in "Date" had `moment(...).toDate()`.

Now, Date branch is just `convert(object, "Moment").toDate()`.

Also, each now throw TypeErrors, & Date branch catches "TypeError" & rethrows
its own.
yotamberk
yotamberk previously approved these changes Oct 3, 2020
Copy link
Member

@yotamberk yotamberk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work! I would like you though to remove testOffset.html before merging.

@strazto
Copy link
Contributor Author

strazto commented Oct 5, 2020

Should be ready to pull @yotamberk

@yotamberk yotamberk merged commit 3363147 into visjs:master Oct 5, 2020
@vis-bot
Copy link
Collaborator

vis-bot commented Oct 5, 2020

🎉 This PR is included in version 7.3.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment