chansen / p5-time-moment

Time::Moment represents an exact moment in time.
32 stars 8 forks source link

Correct the lenient example #20

Open dnmfarrell opened 8 years ago

dnmfarrell commented 8 years ago

In the main module documentation the lenient example appears to be wrong:

$tm = Time::Moment->from_string($string [, lenient => false]);

Should it be:

$tm = Time::Moment->from_string($string, lenient => 0);

?

E.g.

$ perl -MTime::Moment -E 'say Time::Moment->from_string("2016-01-27T00:00:02-0800", [lenient => 1])'
Odd number of elements in named parameters at -e line 1.

$ perl -MTime::Moment -wE 'say Time::Moment->from_string("2016-01-27T00:00:02-0800", lenient => 1)'
2016-01-27T00:00:02-08:00
chansen commented 8 years ago

Parameters enclosed in the [ and ] notation are optional and can be omitted. I have tried to use this notation consistently in Time::Moment where the value of the named parameter shows the default:

$tm = Time::Moment->from_string($string [, lenient => false]);
$tm = Time::Moment->from_epoch($seconds [, nanosecond => 0] [, precision => 6]);
$tm = Time::Moment->from_rd($rd [, offset => 0] [, precision => 3] [, epoch => 0]);
$tm = Time::Moment->from_jd($jd [, precision => 3] [, epoch => -1721424.5]);
$tm = Time::Moment->from_mjd($mjd [, precision => 3] [, epoch => 678576]);

I'm open for ideas how to improve the notation or clarify the current notation.

ccakes commented 7 years ago

I think @dnmfarrell was pointing out the use of the bareword false rather than the square brackets. I believe that should be 0.

Just saw a project that depends on Time::Moment using boolean to get the false object which doesn't appear to be needed, this works fine:

perl -MTime::Moment \
  -e 'print Time::Moment->from_string("2017-03-27 04:53:03.452374Z", lenient => 1)'