All Projects → allenan → Human_time

allenan / Human_time

Licence: mit
Ruby time and date comparisons for humans

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Human time

Luatz
Time, Date and Timezone library for lua
Stars: ✭ 92 (-18.58%)
Mutual labels:  time, datetime
Dateparse
GoLang Parse many date strings without knowing format in advance.
Stars: ✭ 1,365 (+1107.96%)
Mutual labels:  time, datetime
Vue Datetime
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
Stars: ✭ 928 (+721.24%)
Mutual labels:  time, datetime
Time Stamp
Get a formatted timestamp. Used in gulp, assemble, generate, and many others.
Stars: ✭ 104 (-7.96%)
Mutual labels:  time, datetime
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (-38.05%)
Mutual labels:  time, datetime
Carbon
A simple, semantic and developer-friendly golang package for datetime
Stars: ✭ 565 (+400%)
Mutual labels:  time, datetime
Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (+776.11%)
Mutual labels:  time, datetime
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (+160.18%)
Mutual labels:  time, datetime
When
A natural language date/time parser with pluggable rules
Stars: ✭ 1,113 (+884.96%)
Mutual labels:  time, datetime
Laydate
layDate(日期与时间组件) 是 layui 独立维护的三大组件之一
Stars: ✭ 1,066 (+843.36%)
Mutual labels:  time, datetime
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (+374.34%)
Mutual labels:  time, datetime
Graphql Java Datetime
GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphql-java.
Stars: ✭ 89 (-21.24%)
Mutual labels:  time, datetime
Pendulum
Python datetimes made easy
Stars: ✭ 4,639 (+4005.31%)
Mutual labels:  time, datetime
Period
PHP's time range API
Stars: ✭ 616 (+445.13%)
Mutual labels:  time, datetime
Time.dart
⏰ Type-safe DateTime and Duration calculations, powered by extensions.
Stars: ✭ 363 (+221.24%)
Mutual labels:  time, datetime
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+32973.45%)
Mutual labels:  time, datetime
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-68.14%)
Mutual labels:  time, datetime
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-78.76%)
Mutual labels:  time, datetime
Zulu
A drop-in replacement for native Python datetimes that embraces UTC.
Stars: ✭ 52 (-53.98%)
Mutual labels:  time, datetime
Carbon
A simple PHP API extension for DateTime
Stars: ✭ 75 (-33.63%)
Mutual labels:  time, datetime

human_time

Build Status Gem Version

Have you ever struggled to understand what a piece of code like this is trying to say?

some_time > another_time

It should be simple, but our brains don't think in terms of "greater than" or "less than" when it comes to times and dates.

human_time lets you express time comparison the way your human brain thinks:

some_time.more_recent_than?(another_time)

It also includes some synonyms so you can word it in a way that makes sense to your human brain:

some_time.newer_than?(another_time)
some_time.comes_after?(another_time)

For a complete list of expressions, see the 'Usage' section below.

Installation

Add this line to your application's Gemfile:

gem 'human_time'

And then execute:

$ bundle

Or install it yourself as:

$ gem install human_time

Usage

human_time simply adds aliases for the >, >=, < and <= methods on the Date, Time and DateTime classes.

older_date = Date.parse('2016-01-01')
newer_date = Date.parse('2016-01-02')

older_date < newer_date
# => true

older_date.older_than?(newer_date)
# => true

newer_date > older_date
# => true

newer_date.newer_than?(older_date)
# => true

> aliases

  • newer_than?
  • more_recent_than?
  • comes_after?
  • later_than?

>= aliases

  • newer_than_or_equal_to?
  • more_recent_than_or_equal_to?
  • after_or_equal_to?
  • later_than_or_equal_to?

< aliases

  • older_than?
  • comes_before?
  • earlier_than?

<= aliases

  • older_than_or_equal_to?
  • before_or_equal_to?
  • earlier_than_or_equal_to?

RSpec Matchers

human_time also provides RSpec matchers for more understandable time comparisons in your tests.

To use these, include the following in your spec_helper.rb file:

require 'human_time/rspec_matchers'

And then you can use the following matchers:

older_date = Date.parse('2016-01-01')
newer_date = Date.parse('2016-01-02')

expect(newer_date).to be_more_recent_than(older_date)
expect(newer_date).to be_newer_than(older_date)
expect(newer_date).to be_after(older_date)
expect(newer_date).to be_later_than(older_date)
expect(newer_date).to be_more_recent_than_or_equal_to(older_date)
expect(newer_date).to be_newer_than_or_equal_to(newer_date)
expect(newer_date).to be_later_than_or_equal_to(newer_date)
expect(older_date).to be_older_than(newer_date)
expect(older_date).to be_before(newer_date)
expect(older_date).to be_earlier_than(newer_date)
expect(older_date).to be_older_than_or_equal_to(older_date)
expect(older_date).to be_earlier_than_or_equal_to(older_date)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/allenan/human_time. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

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].