srawlins / timezone

Time zone database and time zone aware DateTime object for Dart.
BSD 2-Clause "Simplified" License
102 stars 54 forks source link

TZDateTime should throw an explicit error when provided a null Location #30

Closed jsmarr closed 4 years ago

jsmarr commented 5 years ago

TZDateTime takes a Location argument, and internally it assumes it's non-null (e.g. https://github.com/srawlins/timezone/blob/master/lib/src/date_time.dart#L28) but it's not documented as such and does not null-check the argument early enough to avoid throwing what looks like an internal NPE without an obvious cause.

Given esp. that getLocation() will return null if you pass in an unrecognized timezone string name, I think TZDateTime should be more explicit in code/docs that it's the developer's job to null-check the Location before passing it into TZDateTime.