Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timerage

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timerage

  • 2.3.0
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

Timerage

Time Ranges that are actually useful.

Installation

Add this line to your application's Gemfile:

gem 'timerage'

And then execute:

$ bundle

Or install it yourself as:

$ gem install timerage

Usage

require 'timerage'
a_time = Timerage("2016-01-18T22:25:37Z")
# => 2016-01-18 22:25:37 +0000

Timerage(a_time)
# => 2016-01-18 22:25:37 +0000

Timerage("2016-01-18T21:25:37+00:00/2016-01-18T22:25:37+00:00")
# => 2016-01-18 21:25:37 +0000...2016-01-18 22:25:37 +0000

interval = Timerage((a_time-3600)...a_time)
# => 2016-01-18 21:25:37 +0000...2016-01-18 22:25:37 +0000

Stepping over a time inteval

interval.step(30*60).map { |time| time }
# => [2016-01-18 21:25:37 +0000, 2016-01-18 21:55:37 +0000]

Slicing a time interval

interval.slice(30*60).map { |time| time }
# => [2016-01-18 21:25:37 UTC...2016-01-18 21:55:37 UTC, 2016-01-18 21:55:37 UTC...2016-01-18 22:25:37 UTC]

ISO 8601 output

interval.iso8601
# => "2016-01-18T21:25:37+00:00/2016-01-18T22:25:37+00:00"

Comparisons

Supports most range/set comparisons

  • #overlap?
  • #cover?
  • #adjacent_to?
  • #==

Concatenation

interval + Timerage("2016-01-18T20:25:37+00:00/2016-01-18T21:25:37+00:00")
# => 2016-01-18 20:25:37 UTC..2016-01-18 22:25:37 UTC

Duration

interval.duration
# => 3600.0

Gotchas

This doesn't fix the #each method to do anything useful, you still can't blindly iterate over a range of time. You can use the #step(seconds) method however, which makes more sense anyway. (what does it even mean to iterate over a time range? What is the next time after "now"? How many steps should we take?)

Contributing

  1. Fork it ( http://github.com/cschneid/timerage/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 08 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc