Module N::TimeUtils
In: lib/glue/time.rb

General time utilities collection

Implement as a module to avoid class polution. You can still Ruby‘s advanced features to include the module in your class. Passing the object to act upon allows to check for nil, which isn‘t possible if you use self.

TODO

  • SOS: add test units.
  • add aliases for those methods in Kernel ?

Methods

Constants

NOW = Time.now
NEVER = Time.mktime(2038)
ZERO = Time.mktime(1972)

Public Class methods

Convert the time to a nice String representation.

This method calculates the days extrema given two time objects. start time is the given time1 at 00:00:00 end time is the given time2 at 23:59:59:999

Input:

  • the two times (if only time1 is provided then you get an extrema of exactly one day extrema.

Output

  • the time range. you can get the start/end times using range methods.

Set time to end of day

Set time to start of day

Returns true only if day of time is included in the range (stime..etime). Only year days are checked.

[Validate]