{"id":15957210,"url":"https://github.com/mamantoha/time_duration","last_synced_at":"2026-03-04T05:01:12.451Z","repository":{"id":175796884,"uuid":"654487827","full_name":"mamantoha/time_duration","owner":"mamantoha","description":"Provides a structured and convenient way to work with durations of time in the Crystal programming language","archived":false,"fork":false,"pushed_at":"2024-08-14T09:35:44.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-10T19:41:03.967Z","etag":null,"topics":["crystal","time"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mamantoha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-16T08:33:10.000Z","updated_at":"2024-08-14T09:35:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"3070b3e8-8e46-40cf-a6b0-08594a2145c1","html_url":"https://github.com/mamantoha/time_duration","commit_stats":null,"previous_names":["mamantoha/time_duration"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mamantoha/time_duration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamantoha%2Ftime_duration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamantoha%2Ftime_duration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamantoha%2Ftime_duration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamantoha%2Ftime_duration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mamantoha","download_url":"https://codeload.github.com/mamantoha/time_duration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamantoha%2Ftime_duration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30071895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T03:25:38.285Z","status":"ssl_error","status_checked_at":"2026-03-04T03:25:05.086Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","time"],"created_at":"2024-10-07T13:40:49.942Z","updated_at":"2026-03-04T05:01:12.433Z","avatar_url":"https://github.com/mamantoha.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Time::Duration\n\n[![Crystal CI](https://github.com/mamantoha/time_duration/actions/workflows/crystal.yml/badge.svg)](https://github.com/mamantoha/time_duration/actions/workflows/crystal.yml)\n[![GitHub release](https://img.shields.io/github/release/mamantoha/time_duration.svg)](https://github.com/mamantoha/time_duration/releases)\n[![License](https://img.shields.io/github/license/mamantoha/time_duration.svg)](https://github.com/mamantoha/time_duration/blob/main/LICENSE)\n\nThe `Time::Duration` library provides a structured and convenient way to work with durations of time in the Crystal programming language. It allows the creation of duration instances from various units of time such as seconds, minutes, hours, days, weeks, months, and years, and also supports duration operations like addition, subtraction, multiplication, and division.\n\nThis library is inspired by the [ActiveSupport::Duration](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html) library from the Ruby on Rails framework.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     time_duration:\n       github: mamantoha/time_duration\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"time_duration\"\n```\n\n### Initialization\n\nInitialize a duration from a float value representing seconds:\n\n```crystal\nduration = Time::Duration.new(3600.0) # Creates a duration of 1 hour.\n```\nYou can also create durations directly from various units of time:\n\n```crystal\nhour = Time::Duration.hours(1)    # Creates a duration of 1 hour.\nday = Time::Duration.days(1)      # Creates a duration of 1 day.\nweek = Time::Duration.weeks(1)    # Creates a duration of 1 week.\nmonth = Time::Duration.months(1)  # Creates a duration of 1 month.\nyear = Time::Duration.years(1)    # Creates a duration of 1 year.\n```\n\n### Operations\n\nThe library supports standard mathematical operations for durations:\n\n```crystal\ntotal = day + hour      # Addition\ndifference = day - hour # Subtraction\ndoubled = day * 2       # Multiplication\nhalved = day / 2        # Division\n```\n\nYou can also compare two durations:\n\n```crystal\nif day \u003e hour\n  puts \"A day is longer than an hour.\"\nend\n```\n\n### Conversion\n\nYou can convert a duration into various units of time:\n\n```crystal\nputs \"In seconds: #{hour.in_seconds}\"\nputs \"In minutes: #{hour.in_minutes}\"\nputs \"In hours: #{hour.in_hours}\"\nputs \"In days: #{day.in_days}\"\nputs \"In weeks: #{week.in_weeks}\"\nputs \"In months: #{month.in_months}\"\nputs \"In years: #{year.in_years}\"\n```\n\n### Time\n\nCalculate a time in the past or future based on a duration:\n\n```crystal\nduration = Time::Duration.hours(1)\n\nputs duration.ago   # prints the time 1 hour ago\nputs duration.since # prints the time 1 hour in the future\n```\n\nYou can also use it with a specific time:\n\n```crystal\nspecific_time = Time.new(2023, 1, 1)\n\nputs duration.ago(specific_time)   # prints the time 1 hour before the specific_time\nputs duration.since(specific_time) # prints the time 1 hour after the specific_time\n```\n## Contributing\n\n1. Fork it (\u003chttps://github.com/mamantoha/time_duration/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Anton Maminov](https://github.com/mamantoha) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmamantoha%2Ftime_duration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmamantoha%2Ftime_duration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmamantoha%2Ftime_duration/lists"}