Relative Time Formatter API - Ruby Gem
Relative Time Formatter is a tool for converting timestamps and dates to human-readable relative time formats like '2 hours ago' or 'in 3 days'. It supports multiple styles and custom reference times for flexible time representation.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_relativetimeformatter'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_relativetimeformatter
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_relativetimeformatter'
# Initialize the client
client = APIVerve::Relativetimeformatter::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({
timestamp: "1609459200",
reference: "2024-06-01T00:00:00Z",
style: "short"
})
# Print the response
puts response
Error Handling
begin
response = client.execute({ timestamp: "1609459200", reference: "2024-06-01T00:00:00Z", style: "short" })
puts response["data"]
rescue APIVerve::Relativetimeformatter::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Relativetimeformatter::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Relativetimeformatter::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"target_date": "2021-01-01T00:00:00Z",
"reference_date": "2025-12-16T22:28:24.459Z",
"relative_time": "4 years ago",
"is_past": true,
"is_future": false,
"difference_ms": -156464904459,
"primary_unit": "year",
"primary_value": 4,
"all_units": {
"years": 4,
"months": 59,
"weeks": 258,
"days": 1810,
"hours": 43462,
"minutes": 2607748,
"seconds": 156464904,
"milliseconds": 156464904459
},
"style": "short"
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/relativetimeformatter?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.