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

Gerald Bauer <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAAxEZd8xGR4urN5SvFEXFD358kmwMuMvJNHP8tsXDLSX+1V=kA@mail.gmail.com>
Hello,

  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.
Example:

    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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.