
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
gitlab_chronic_duration
Advanced tools
A simple Ruby natural language parser for elapsed time. (For example, 4 hours and 30 minutes, 6 minutes 4 seconds, 3 days, etc.) Returns all results in seconds. Will return an integer unless you get tricky and need a float. (4 minutes and 13.47 seconds, for example.)
The reverse can also be accomplished with the output method. So pass in seconds and you can get strings like 4 mins 31.51 secs (default format), 4h 3m 30s, or 4:01:29.
>> require 'gitlab_chronic_duration'
=> true
>> ChronicDuration.parse('4 minutes and 30 seconds')
=> 270
>> ChronicDuration.parse('0 seconds')
=> nil
>> ChronicDuration.parse('0 seconds', :keep_zero => true)
=> 0
>> ChronicDuration.output(270)
=> 4 mins 30 secs
>> ChronicDuration.output(0)
=> nil
>> ChronicDuration.output(0, :keep_zero => true)
=> 0 secs
>> ChronicDuration.output(270, :format => :short)
=> 4m 30s
>> ChronicDuration.output(270, :format => :long)
=> 4 minutes 30 seconds
>> ChronicDuration.output(270, :format => :chrono)
=> 4:30
>> ChronicDuration.output(1299600, :weeks => true)
=> 2 wks 1 day 1 hr
>> ChronicDuration.output(1299600, :weeks => true, :units => 2)
=> 2 wks 1 day
>> ChronicDuration.output(45*24*60*60 + 15*60, :limit_to_hours => true)
=> 1080 hrs 15 mins
>> ChronicDuration.output(1299600, :weeks => true, :units => 2, :joiner => ', ')
=> 2 wks, 1 day
>> ChronicDuration.output(1296000)
=> 15 days
Nil is returned if the string can't be parsed
Examples of parse-able strings:
ChronicDuration.raise_exceptions can be set to true to raise exceptions when the string can't be parsed.
>> ChronicDuration.raise_exceptions = true
=> true
>> ChronicDuration.parse('4 elephants and 3 Astroids')
ChronicDuration::DurationParseError: An invalid word "elephants" was used in the string to be parsed.
Fork and pull request after your specs are green. Add your handle to the list below. Also looking for additional maintainers.
errm,pdf, brianjlandau, jduff, olauzon, roboman, ianlevesque, bolandrm
FAQs
Unknown package
We found that gitlab_chronic_duration demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.