
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
NaturalTime outputs a duration in natural language.
The to_sentence
method will output the duration in time in natural language
and formatted like a sentence.
NaturalTime.to_sentence(65) #=> "1 minute and 5 seconds"
NaturalTime.to_sentence(120) #=> "2 minutes"
NaturalTime.to_sentence(10000) #=> "2 hours, 46 minutes, and 40 seconds"
The to_s
command will separate the units with commas but with no "and":
NaturalTime.to_s(65) #=> "1 minute, 5 seconds"
NaturalTime.to_s(10000) #=> "2 hours, 46 minutes, 40 seconds"
NaturalTime instances can also be output to an array with to_array
:
NaturalTime.to_array(65) #=> ["1 minutes", "5 seconds"]
NaturalTime.to_array(120) #=> ["2 minutes"]
NaturalTime can return the amount of time to a specific precision. If all you want is the greatest unit:
NaturalTime.to_sentence(65, precision: 1) #=> "1 minute"
NaturalTime.to_sentence(10000, precision: 1) #=> "2 hours"
NaturalTime.to_sentence(10000, precision: 2) #=> "2 hours and 46 minutes"
If you want to use NaturalTime to show an elapsed time and you don't care if
it's in the past or the future, use the natural_time
or to_sentence
methods, or the to_a
method if you need the units in an array.
If you're measuring distances that may be in the past or the future, the
distance
method will return a sentence indicating how long ago or in
the future is your duration.
NaturalTime.distance(65) #=> "1 minute and 5 seconds from now"
NaturalTime.distance(-65) #=> "1 minute and 5 seconds ago"
It works with :precision
too:
NaturalTime.distance(10000, precision: 1) #=> "2 hours from now"
NaturalTime.distance(-10000, precision: 2) #=> "2 hours and 46 minutes ago"
Documentation can be generated with:
yard doc -m markdown
Copyright (c) 2018 Isaac Priestley. See LICENSE for details.
FAQs
Unknown package
We found that natural_time 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 clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.