bigeasy / timezone

Full-blown timezone aware date math and formatting for JavaScript in 2.7k.
http://bigeasy.github.io/timezone
MIT License
257 stars 27 forks source link

One of the examples returns [Function] instead of an integer. #320

Open detrout opened 4 years ago

detrout commented 4 years ago

I was turning the examples into a test and ran into an error.

var ok = require("assert");
var eq = require("assert").equal;
var tz = require("timezone");

var y2k = tz("2000-01-01");
eq( y2k, 946684800000 );
eq( y2k, Date.UTC(2000, 0, 1));

eq( tz("1970-01-01"), 0);
ok( tz("1969-7-21 02:56") < 0);

Thrown:
{ [AssertionError [ERR_ASSERTION]: false == true]
  generatedMessage: true,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '==' }
> tz("1969-7-21 02:56")
[Function]

I tried it both with a copy I was building for a Debian package, and a copy installed into a new directory with npm install timezone.

simevo commented 4 years ago

actually in the examples it's 1969-07-21 with 0: https://github.com/bigeasy/timezone/blob/master/src/synopsis.js#L75

if you change it this way, the code works

TBH I would have expected it to work without zero as well, so this issue could be worth considering for useability.

it's also a mystery why when fed 1969-7-21 02:56 without zero, it returns a function that when evaluated returns 1.0.22 (the module version number); it this input is to be really considered invalid (which I tend to disagree) I would expect an exception or some error.

detrout commented 4 years ago

Ah I did typo the example.

I too would've expected an exception for unparsable input as well. Returning a function that returns the version is pretty odd behavior.