All Projects → josedonizetti → Ruby Duration

josedonizetti / Ruby Duration

Licence: mit
Immutable type that represents some amount of time with accuracy in seconds.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Ruby Duration

duration-humanizer
361000 becomes "6 minutes, 1 second"
Stars: ✭ 61 (-50%)
Mutual labels:  duration, time
As Duration
Extraction of ActiveSupport::Duration from Rails
Stars: ✭ 126 (+3.28%)
Mutual labels:  time, duration
Time
Windows tool for measuring command/program execution speed
Stars: ✭ 21 (-82.79%)
Mutual labels:  time, duration
Swift-ISO8601-DurationParser
Swift ISO8601 Parser
Stars: ✭ 24 (-80.33%)
Mutual labels:  duration, time
Time.dart
⏰ Type-safe DateTime and Duration calculations, powered by extensions.
Stars: ✭ 363 (+197.54%)
Mutual labels:  time, duration
Durafmt
🕗 Better time duration formatting in Go!
Stars: ✭ 362 (+196.72%)
Mutual labels:  time, duration
Humanizeduration.js
361000 becomes "6 minutes, 1 second"
Stars: ✭ 1,234 (+911.48%)
Mutual labels:  time, duration
Kairos
A non date-based time calculator
Stars: ✭ 100 (-18.03%)
Mutual labels:  time
Human time
Ruby time and date comparisons for humans
Stars: ✭ 113 (-7.38%)
Mutual labels:  time
Date And Time
A Minimalist DateTime utility for Node.js and the browser
Stars: ✭ 99 (-18.85%)
Mutual labels:  time
Redux Time
∞ High-performance declarative JS animation library for building games, data-viz experiences, and more w/ React, ThreeJS, Inferno, SnabbDOM and others...
Stars: ✭ 99 (-18.85%)
Mutual labels:  time
Timeoverflow
🏦 ⌛ A time banking system
Stars: ✭ 100 (-18.03%)
Mutual labels:  time
Use Timer
A timer hook for React
Stars: ✭ 113 (-7.38%)
Mutual labels:  time
Dateparse
GoLang Parse many date strings without knowing format in advance.
Stars: ✭ 1,365 (+1018.85%)
Mutual labels:  time
Chrono
Date and time library for Rust
Stars: ✭ 1,780 (+1359.02%)
Mutual labels:  time
Cron4s
Cross-platform CRON expression parsing for Scala
Stars: ✭ 99 (-18.85%)
Mutual labels:  time
Lora Serialization
LoraWAN serialization/deserialization library for The Things Network
Stars: ✭ 120 (-1.64%)
Mutual labels:  time
Date Fns Timezone
Parsing and formatting date strings using IANA time zones for date-fns.
Stars: ✭ 118 (-3.28%)
Mutual labels:  time
Calendar
📅 PHP Date & Time library that solves common problems in object oriented, immutable way.
Stars: ✭ 113 (-7.38%)
Mutual labels:  time
Timesincetextview
Android TextView for displaying the time since a date
Stars: ✭ 108 (-11.48%)
Mutual labels:  time

ruby-duration

Duration is an immutable type that represents some amount of time with accuracy in seconds.

A lot of the code and inspirations is borrowed from duration lib, which is a mutable Duration type with lot more features.

Help Wanted!

If you use ruby-duration and want to take over the project, let me know.

Maintainers Wanted

Features

  • Representation of time in weeks, days, hours, minutes and seconds.
  • Construtor can receive the amount of time in seconds or a Hash with unit and amount of time.
  • Format method to display the time with i18n support.
  • Mongoid serialization support. Use require 'duration/mongoid'.
  • Tested on mri 1.9.3 and jruby. Kudos to rvm!

Show me the code

constructor

Duration.new(100) => #<Duration: minutes=1, seconds=40, total=100>
Duration.new(:hours => 5, :minutes => 70) => #<Duration: hours=6, minutes=10, total=22200>

format

Duration.new(:weeks => 3, :days => 1).format("%w %~w and %d %~d") => "3 weeks and 1 day"
Duration.new(:weeks => 1, :days => 20).format("%w %~w and %d %~d") => "3 weeks and 6 days"

iso 8601

Duration.new(:weeks => 1, :days => 20).iso8601 => "P3W6DT0H0M0S"
Duration.new("P6DT5S") => #<Duration: days=6, seconds=5, total=518405>

Mongoid support

The current version of this gem supports Mongoid >= 3.0.0. For lower Mongoid versions try:

    require 'duration/mongoid'

    class MyModel
      include Mongoid::Document
      field :duration, type => Duration
    end

Dependencies

The current version of this gem runs only on Ruby Versions >= 1.9.3. If you are running a older version of Ruby try:

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

License

Copyright (c) 2010 Jose Peleteiro

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].