units-time library / gem v1.0 - units of time (in epoch time) for secure ruby (sruby)

(Gerald Bauer) #1


  I've put together a "standalone" library / gem for
units of time (in epoch time) incl. seconds, minutes, hours, days, weeks,
fortnights, years and more.

   The units-time library / gem [1] includes two new types too, that is,
  Timestamp and Timedelta.

  You can add and subtract durations from Timestamp or Timedelta objects.

    Timestamp.now + 2.hours #=> <Timestamp seconds= >
    1.week + 1.day #=> <Timedelta seconds= >
    2.minutes - 1.second #=> <TimeDelta seconds= >

Note: You CANNOT add or subtract integers to `Timestamp` or
`Timedelta` objects and vice versa.

    # Bad
    10 + 1.minute #=> Boom! <TypeError>
    1.minute + 10 #=> Boom! <TypeError>

    # Good
    10.seconds + 1.minute #=> <Timedelta seconds=70>
    1.minute.to_i + 10 #=> Integer

Note: Multiply an integer with `1.hour` or `1.minute` or `1.second` and so on
to convert to a time unit.

    100*1.hour #=> <Timedelta seconds=360_000>

  Happy coding with (secure) ruby. Cheers. Prost.

PS: The new units-time 1.0 library is part of the safe data structures
series. [2]

[1] https://github.com/s6ruby/units-time
[2] https://github.com/s6ruby/safestruct