ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - abhidsm/time_diff: Gem which calculates the difference between two times
Gem which calculates the difference between two times - abhidsm/time_diff
Visit Site

GitHub - abhidsm/time_diff: Gem which calculates the difference between two times

GitHub - abhidsm/time_diff: Gem which calculates the difference between two times

= time_diff Gem which calculates the difference between two time

== Installation

gem install time_diff

== Usage

require 'time_diff'

time_diff_components = Time.diff(start_date_time, end_date_time)

This will return the hash of time difference in terms of years, month, week, day, hour, minute and second.

You can use the difference like:

time_diff_components[:year], time_diff_components[:month], time_diff_components[:week]

== Formatted Time difference

%y - year

%M - month

%w - week

%d - day

%H - hour

%N - minute

%S - second

%h - hour (without adding 'hour' text to the hours. eg: 3 for 3 hours)

%m - minute (without adding 'minute' text)

%s - second (without adding 'second' text)

By default the format is

'%y, %M, %w, %d and %h:%m:%s' 

this will return

'1 year, 2 months, 3 weeks, 4 days and 12:05:52'.

You will get the result from the output hash, time_diff_components[:diff]

You can pass your own format as third parameter to this function.

If you give '%d %h' as the third parameter to the Time.diff() method, then the difference(time_diff_components[:diff]) will be calculated only in days and hours.

== Examples

> Time.diff(Time.parse('2011-03-06'), Time.parse('2011-03-07'))
=> {:year => 0, :month => 0, :week => 0, :day => 1, :hour => 0, :minute => 0, :second => 0, :diff => '1 day and 00:00:00'}
> Time.diff(Time.parse('2010-03-06 12:30:00'), Time.parse('2011-03-07 12:30:30'), '%y, %d and %h:%m:%s')
=> {:year => 1, :month => 0, :week => 0, :day => 0, :hour => 18, :minute => 0, :second => 30, :diff => '1 year and 18:00:30'}
> Time.diff(Time.parse('2011-03-06 12:30:00'), Time.parse('2011-03-07 12:30:30'), '%H %N %S')
=> {:year => 0, :month => 0, :week => 0, :day => 1, :hour => 0, :minute => 0, :second => 30, :diff => '24 hours 0 minute 30 seconds'} 

== i18n support

Add locales for day, days, week, weeks, year, hour, hours, minute, minutes, second, and seconds in your YAML file. For eg: en: day: divasam days: divasangal

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory