{"id":21517578,"url":"https://github.com/tek/polysemy-time","last_synced_at":"2025-04-09T21:42:48.642Z","repository":{"id":56875009,"uuid":"300089781","full_name":"tek/polysemy-time","owner":"tek","description":"Polysemy effects for time","archived":false,"fork":false,"pushed_at":"2023-09-23T16:39:14.000Z","size":162,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-28T22:42:23.590Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tek.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-09-30T23:38:59.000Z","updated_at":"2024-05-27T22:14:50.855Z","dependencies_parsed_at":"2023-01-31T05:00:44.860Z","dependency_job_id":"f1216c53-51c7-4e8a-bad2-eaff64aeb035","html_url":"https://github.com/tek/polysemy-time","commit_stats":{"total_commits":94,"total_committers":2,"mean_commits":47.0,"dds":0.3829787234042553,"last_synced_commit":"facc5c431ddd86a05ed298bc4c43306195f2d78c"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tek%2Fpolysemy-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tek%2Fpolysemy-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tek%2Fpolysemy-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tek%2Fpolysemy-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tek","download_url":"https://codeload.github.com/tek/polysemy-time/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119088,"owners_count":21050751,"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":[],"created_at":"2024-11-24T00:43:02.664Z","updated_at":"2025-04-09T21:42:48.613Z","avatar_url":"https://github.com/tek.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nThis Haskell library provides a [Polysemy] effect for accessing the current time and date, and interpreters using\n[time] and [chronos].\n\n# Example\n\n```haskell\nimport Data.Time (UTCTime)\nimport Polysemy (Members, runM)\nimport Polysemy.Chronos (interpretTimeChronos)\nimport qualified Polysemy.Time as Time\nimport Polysemy.Time (MilliSeconds(MilliSeconds), Seconds(Seconds), Time, interpretTimeGhcAt, mkDatetime, year)\n\nprog ::\n  Ord t =\u003e\n  Members [Time t d, Embed IO] r =\u003e\n  Sem r ()\nprog = do\n  time1 \u003c- Time.now\n  Time.sleep (MilliSeconds 10)\n  time2 \u003c- Time.now\n  print (time1 \u003c time2)\n  -- True\n\ntestTime :: UTCTime\ntestTime =\n  mkDatetime 1845 12 31 23 59 59\n\nmain :: IO ()\nmain =\n  runM do\n    interpretTimeChronos prog\n    interpretTimeGhcAt testTime do\n      Time.sleep (Seconds 1)\n      time \u003c- Time.now\n      print (year time)\n      -- Years { unYear = 1846 }\n```\n\n# Effect\n\nThe only effect contained in **polysemy-time** is:\n\n```haskell\ndata Time (time :: Type) (date :: Type) :: Effect where\n  Now :: Time t d m t\n  Today :: Time t d m d\n  Sleep :: TimeUnit u =\u003e u -\u003e Time t d m ()\n  SetTime :: t -\u003e Time t d m ()\n  SetDate :: d -\u003e Time t d m ()\n```\n\nInterpreters are provided for the [time library](time) bundled with GHC and [chronos].\n\nThe type parameters correspond to the representations in the implementation,\nlike `Data.Time.UTCTime`/`Chronos.Time` and `Data.Time.Day`/`Chronos.Date`.\n\n`SetTime` and `SetDate` only have meaning when you're running in a testing context.\n\nA special interpreter variant suffixed with `At` exists for both\nimplementations, with which the current time is overridden to be relative to\nthe supplied override fixed at the start of interpretation.\nThis is useful for testing.\n\n# Utilities\n\nA set of newtypes representing timespans are provided for convenience.\nInternally, the interpreters operate on `NanoSecond`s.\n\nThe class `TimeUnit` ties those types, and the types `Chronos.Timespan` and\n`Data.Time.DiffTime`, together to allow you to convert between them with the\nfunction `convert`:\n\n```haskell\n\u003e\u003e\u003e convert (picosecondsToDiffTime 50000000) :: MicroSeconds\nMicroSeconds {unMicroSeconds = 50}\n\n\u003e\u003e\u003e convert (Days 5) :: Timespan\nTimespan {getTimespan = 432000000000000}\n```\n\nThe class `Calendar` allows you to construct `UTCTime` and `Chronos.Datetime`\nfrom integers with the function `mkDatetime`, as demonstrated in the first\nexample.\n\n[Polysemy]: https://hackage.haskell.org/package/polysemy\n[time]: https://hackage.haskell.org/package/time\n[chronos]: https://hackage.haskell.org/package/chronos\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftek%2Fpolysemy-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftek%2Fpolysemy-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftek%2Fpolysemy-time/lists"}