Git Product home page Git Product logo

time-of-day's Introduction

TimeOfDay

A Ruby object that represents a given time-of-day separate from any Date information. Makes it easy to perform work time calculations.

Synopsis

Arithmetic

(TimeOfDay('1:12 PM') + 1) # => 1:13 PM

(TimeOfDay('1:12 PM') - 1) # => 1:11 PM

Range Support

(TimeOfDay('8:00 AM')..TimeOfDay('5:00 PM')).to_a # => [8:00 AM, 8:15 AM, 8:30 AM, ...]

Comparable

TimeOfDay('8:00 AM') < TimeOfDay('8:03 AM') # => true

# Can compare to Time objects
TimeOfDay.now == Time.now # true
TimeOfDay.now > Time.now # false

Pattern Matching

TimeOfDay('8:24 AM') in [hour, *]
hour # => 8

TimeOfDay('10:43 AM').round => min:
min # => 45

Rounding

TimeOfDay('8:17 AM').round # => 8:15 AM

TimeOfDay('8:17 AM').round(30) # => 8:30 AM

Rounded time calculations

TimeSeries('8:34 AM', '12:05 PM').hours.to_f # => 3.5

TimeSeries('8:34 AM', '12:05 PM', '1:34 PM', '5:23 PM').hours.to_f # => 7.5

TimeSeries('8:34 AM', '12:05 PM', '1:34 PM', '5:23 PM').interval_time.to_f # => 450.0 (in minutes)

TimeSeries('8:34 AM', '12:05 PM', '1:34 PM', '5:23 PM').gap_time.to_f # => 90.0 (in minutes)

Installation

Add this line to your application's Gemfile:

gem 'time-of-day'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install time-of-day

See Also

License

The gem is available as open source under the terms of the MIT License.

time-of-day's People

Contributors

delonnewman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.