{"id":13536853,"url":"https://github.com/sebj/time","last_synced_at":"2025-04-12T17:52:24.598Z","repository":{"id":38094495,"uuid":"482646821","full_name":"sebj/time","owner":"sebj","description":"⏱ Type-safe time periods for the Kotlinx-datetime multiplatform date/time library","archived":false,"fork":false,"pushed_at":"2025-03-20T18:29:53.000Z","size":1532,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T20:01:24.843Z","etag":null,"topics":["android","clock","date","datetime","ios","kmp","kotlin","kotlin-library","kotlin-multiplatform","kotlin-native","time"],"latest_commit_sha":null,"homepage":"https://sebj.github.io/time/time/[root]/index.html","language":"Kotlin","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/sebj.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":"2022-04-17T22:26:16.000Z","updated_at":"2025-03-20T18:28:34.000Z","dependencies_parsed_at":"2023-10-11T21:54:45.694Z","dependency_job_id":"b1941e0e-db4b-4753-a620-04b9198e5056","html_url":"https://github.com/sebj/time","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebj%2Ftime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebj%2Ftime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebj%2Ftime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebj%2Ftime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebj","download_url":"https://codeload.github.com/sebj/time/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610407,"owners_count":21132920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["android","clock","date","datetime","ios","kmp","kotlin","kotlin-library","kotlin-multiplatform","kotlin-native","time"],"created_at":"2024-08-01T09:00:50.599Z","updated_at":"2025-04-12T17:52:24.573Z","avatar_url":"https://github.com/sebj.png","language":"Kotlin","funding_links":[],"categories":["Libraries"],"sub_categories":["Utility"],"readme":"# ⏱ Time\n\n[![MIT License](https://img.shields.io/github/license/sebj/time?color=lightgray)](LICENSE)\n[![Version 0.4.10](https://img.shields.io/github/v/release/sebj/time)](https://github.com/sebj/time/releases)\n[![Build, Test \u0026 Deploy Documentation](https://github.com/sebj/time/workflows/Build%2C%20Test%20and%20Deploy%20Documentation/badge.svg)](https://github.com/sebj/time/actions/workflows/build-test-documentation.yaml)\n[![Follow @sebj@mastodon.social](https://img.shields.io/mastodon/follow/000921252?domain=https%3A%2F%2Fmastodon.social\u0026style=plastic)](https://mastodon.social/@sebj)\n\nA Kotlin multiplatform library filling in the gaps of [`kotlinx-datetime`](https://github.com/Kotlin/kotlinx-datetime) with additional type-safe APIs for time periods, as equivalents to those found in the Swift library of the same name([`time`](https://github.com/davedelong/time)).\n\nSupported targets:\n* Apple\n  * iOS\n  * macOS\n  * tvOS\n  * watchOS\n* JVM\n* Linux\n\nSupported `TimePeriod` units:\n* Year\n* Month\n* Day\n* Hour\n* Minute\n* Second\n* Nanosecond\n\n## ⬇️ Installation\n\nAdd the dependency to your Gradle build file:\n```\ndependencies {\n    implementation(\"me.sebj:time:0.4.10\")\n}\n```\n\n## 💡 Usage Examples\n\n### Fetching The Current Time Period\n\n```kotlin\nval clock = Clock.System\nval now: Instant = clock.thisInstant()\nval today: TimePeriod\u003cTimeUnit.Day\u003e = clock.today()\nval month: TimePeriod\u003cTimeUnit.Month\u003e = clock.thisMonth()\n```\n\n### Retrieving Components\n\nRetrieve component values for a time period:\n```kotlin\nval today: TimePeriod\u003cTimeUnit.Day\u003e = Clock.System.today()\nval year = today.year // Ex: 2022\nval month = today.month // Ex: APRIL\nval day = today.day // Ex: 18\n```\n\n### Retrieving TimePeriods\n\nRetrieve larger less-precise time periods for a time period:\n```kotlin\nval today: TimePeriod\u003cTimeUnit.Day\u003e = Clock.System.today()\nval month: TimePeriod\u003cTimeUnit.Month\u003e = today.monthPeriod\nval year: TimePeriod\u003cTimeUnit.Year\u003e = today.yearPeriod\n```\n\nRetrieve smaller more-precise time periods for a time period:\n```kotlin\nval clock = Clock.System\n\nval firstDayOfMonth: TimePeriod\u003cTimeUnit.Day\u003e = clock.thisMonth().firstDay\nval lastHourOfDay: TimePeriod\u003cTimeUnit.Hour\u003e = clock.today().lastHour\nval firstDayOfYear: TimePeriod\u003cTimeUnit.Day\u003e = clock.thisYear().firstDay\n```\n\n### Iterating Over TimePeriods\n\n```kotlin\nval clock = Clock.System\n\nval thisMonth: TimePeriod\u003cTimeUnit.Month\u003e = clock.thisMonth()\nval daysInThisMonth = thisMonth.days\n\nfor (day in daysInThisMonth) {\n    // …\n}\n\nval thisHour: TimePeriod\u003cTimeUnit.Hour\u003e = clock.thisHour()\nval minutesInThisHour = thisHour.minutes\n\nfor (minute in minutesInThisHour) {\n    // …\n}\n```\n\n### Determining The Relationship Between TimePeriods\n\n```kotlin\nval clock = Clock.System\n\nval dayA: TimePeriod\u003cTimeUnit.Day\u003e = ...\nval dayB: TimePeriod\u003cTimeUnit.Day\u003e = ...\nval ..: Boolean = dayA.after(dayB)\n// Also: `before`, `overlaps`, or compare specific relationship using `relation` (see Relations.kt)\n\nval thisMonth = clock.thisMonth()\nval ..: Boolean = dayA.during(thisMonth) // Equivalent to `thisMonth.contains(dayA)`\n```\n\n### Adjusting TimePeriods\n```kotlin\nval today = Clock.System.today()\nval dayAfterTomorrow = today + TimeDifference.days(2)\n_ = today + TimeDifference.hours(1) // Compiler error – not implemented, as this is invalid\n_ = today + TimeDifference.minutes(1) // Compiler error – not implemented, as this is invalid\n\nval thisMonth = today.monthPeriod\nval monthBeforeLast = thisMonth - TimeDifference.months(2)\n_ = today - TimeDifference.nanoseconds(1) // Compiler error – not implemented, as this is invalid\n_ = today - TimeDifference.seconds(1) // Compiler error – not implemented, as this is invalid\n```\n\n## ⚖️ License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebj%2Ftime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebj%2Ftime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebj%2Ftime/lists"}