chansen / p5-time-moment

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

Add numification to fractional epoch seconds #3

Open dagolden opened 10 years ago

dagolden commented 10 years ago

In many instances, code needs to check if $time2 is some seconds after $time1.

While a duration object might be ideal to do that cleanly with very high resolution, in many common cases, it would be nice to be able to do this and have it DWIM:

if ( $time2 - $time1 > 300 ) { ... }

That works particularly nicely with time() (integer or fractional from Time::HiRes), avoiding having to generate/destroy a "now" object just for a simple comparison:

if ( $moment - time() > 300 ) { ... }

# versus this (which isn't even fractional epoch seconds)

if ( $moment - Time::Moment->now_utc->epoch > 300 ) { ... }