https://github.com/abarrak/expiry_calculator
A ruby library that determines how much time left till certain date and time.
https://github.com/abarrak/expiry_calculator
datetime gem ruby
Last synced: 5 months ago
JSON representation
A ruby library that determines how much time left till certain date and time.
- Host: GitHub
- URL: https://github.com/abarrak/expiry_calculator
- Owner: abarrak
- Created: 2025-03-15T21:26:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-14T11:18:01.000Z (over 1 year ago)
- Last Synced: 2025-04-14T12:27:28.502Z (over 1 year ago)
- Topics: datetime, gem, ruby
- Language: Ruby
- Homepage: https://rubygems.org/gems/expiry_calculator
- Size: 46.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Expiry Calculator
[](https://rubygems.org/gems/expiry_calculator)
[](https://github.com/abarrak/expiry_calculator/actions/workflows/ci.yml)
[](https://qlty.sh/gh/abarrak/projects/expiry_calculator)
[](https://qlty.sh/gh/abarrak/projects/expiry_calculator)
[](https://opensource.org/licenses/MIT)
A ruby library that determines how much time left till certain date and time.
> Extracted from [license manager app](https://github.com/abarrak/license-manager/).
## Installation
Install the gem and add to the application's Gemfile by executing:
```bash
bundle add expiry_calculator
```
If bundler is not being used to manage dependencies, install the gem by executing:
```bash
gem install expiry_calculator
```
## Usage
Add the library if gem auto loading is not available.
```ruby
require "expiry_calculator"
```
You can use the the extendable module method:
```ruby
ExpiryCalculator.calculate(2025, 10, 10)
# => 201
```
Or mix in to use the calcuate function directly:
```ruby
include ExpiryCalculator
calculate Date.new(2025, 10, 10)
# => 201
```
```ruby
calculate "2025-01-10"
# => 0
```
Active record models and be called with the date field needed to calculate:
```ruby
user = User.first
calculate user, :birth_day
# => 15
```
The supported objects:
- `Date`
- `DateTime`
- `string`: attempted to be parsed as datetime object.
- `ActiveRecord`: given an attribute of of the model to read as date object.
## API Docs
The gem specs can [be found at RubyDocs.](https://www.rubydoc.info/gems/expiry_calculator)
## Contributing
Bug reports and pull requests are welcome [on GitHub](https://github.com/abarrak/expiry_calculator).