{"id":13718242,"url":"https://github.com/edjcase/motoko_datetime","last_synced_at":"2026-01-22T20:33:16.268Z","repository":{"id":165632140,"uuid":"629562657","full_name":"edjCase/motoko_datetime","owner":"edjCase","description":"DateTime library for Motoko","archived":false,"fork":false,"pushed_at":"2025-09-06T21:45:32.000Z","size":4465,"stargazers_count":3,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-06T23:31:11.158Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Motoko","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/edjCase.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-04-18T15:02:57.000Z","updated_at":"2024-12-07T21:10:39.000Z","dependencies_parsed_at":"2023-11-20T01:30:49.547Z","dependency_job_id":"d10cefbf-aa43-4c74-901d-978e7b90c8b7","html_url":"https://github.com/edjCase/motoko_datetime","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"edjCase/motoko-library-template","purl":"pkg:github/edjCase/motoko_datetime","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_datetime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_datetime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_datetime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_datetime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edjCase","download_url":"https://codeload.github.com/edjCase/motoko_datetime/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_datetime/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28670381,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T19:36:09.361Z","status":"ssl_error","status_checked_at":"2026-01-22T19:36:05.567Z","response_time":144,"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":[],"created_at":"2024-08-03T00:08:22.935Z","updated_at":"2026-01-22T20:33:16.248Z","avatar_url":"https://github.com/edjCase.png","language":"Motoko","funding_links":[],"categories":["Libraries"],"sub_categories":["Data structures"],"readme":"# Funding\n\nThis library was originally incentivized by ICDevs. You can view more about the bounty on the forum or website. The bounty was funded by The ICDevs.org commuity and the award paid to @Gekctek. If you use this library and gain value from it, please consider a donation to ICDevs.\n\n# Overview\n\nThis is a library that handles DateTime creation, modification, parsing, and formatting.\n\nSee full [API documentation here](./docs/index.md)\n\n# Package installation\n\n## MOPS\n\n### CLI\n\nRun `mops install datetime`\n\n### Or manually:\n\nModify the `mops.toml` file to add:\n\n```\n[dependencies]\ndatetime = \"{version}\"\n```\n\nwhere `{version}` is the version number you want to use\n\nSee detailed MOPS documentation [here](https://mops.one/docs/install)\n\n# Quickstart\n\n## Types Overview\n\n- `DateTime` - A type that represents a UTC date and time. Has no context of local timezones (just UTC) and should be used as the default type unless timezones are required.\n- `LocalDateTime` - A type that represents a local date and time. Has context of local timezone and is more complicated than `DateTime`.\n- `Components` - A more general concept of a date and time. Does not have context of timezones and is not an 'instance in time' like `DateTime` and `LocalDateTime`. It is useful for storing of date and time information and can be used to construct `DateTime` and `LocalDateTime` types.\n- `TimeZone` - A type that represents either a fixed offset (e.g. UTC+3) or a named IANA timezone (e.g. America/New_York).\n- `IanaTimeZone` - An implementation of `TimeZone` that represents a named IANA timezone.\n\n## From Time\n\n```motoko\nimport DateTime \"mo:datetime/DateTime\";\nlet time = 123_456_789_000_000; // Nano seconds since epoch\nlet date = DateTime(time);\n```\n\n## From Text\n\n```motoko\nimport DateTime \"mo:datetime/DateTime\";\nlet text = \"2020-02-01T00:00:00Z;\nlet format = \"YYYY-MM-DDTHH:mm:ssZ\";\nlet ?date = DateTime.fromText(text, format) else return #error(\"Failed to parse datetime\");\n```\n\n## From Components\n\n```motoko\n\nimport DateTime \"mo:datetime/DateTime\";\nlet components = {\n  year = 2020;\n  month = 2;\n  day = 1;\n  hour = 0;\n  minute = 0;\n  nanosecond = 0;\n};\nlet date = DateTime.fromComponents(components);\n```\n\n## Manipulation\n\n```motoko\nimport DateTime \"mo:datetime/DateTime\";\nlet date = DateTime.now();\n// Can chain multiple calls together\ndate.add(#seconds(-1)).add(#minutes(2)).add(#hours(-3)).add(#days(4)).add(#months(-5)).add(#years(6));\n```\n\n## TimeZone\n\n### Fixed\n\n```motoko\nlet fixedTimeZone = #fixed(#hours(-7));\n```\n\n### Dynamic/IANA\n\nLocation based timezones that change with daylights savings\n\n```motoko\n// For specific timezones, can just reference directly\n// NOTE: This method is preferred as it is more efficient as it only loads the timezone data for the specific timezone\n\nimport AmericaTimeZones \"../iana/timezones/America\";\nlet pstTimeZone = IanaTimeZone(AmericaTimeZones.Los_Angeles.data);\n```\n\nOR\n\n```motoko\n// For timezone lookup\n// NOTE: This method requires loading in all the timezones and will cause a larger canister size\n\nimport TimeZoneFinder \"../iana/TimeZoneFinder\";\nlet timeZone = TimeZoneFinder.find(\"America/Los_Angeles\");\n```\n\n## LocalDateTime\n\n```motoko\nimport LocalDateTime \"mo:datetime/LocalDateTime\";\nlet components = {\n  year = 2020;\n  month = 2;\n  day = 1;\n  hour = 0;\n  minute = 0;\n  nanosecond = 0;\n};\nlet timeZone = #fixed(#hours(-7));\nLocalDateTime(components, timeZone);\n```\n\n# First time setup\n\nTo build the library, the `MOPS` library must be installed. It is used to pull down packages and running tests.\n\nMOPS install instructions: https://mops.one/docs/install\n\n# Testing\n\nTo run tests, use the `make test` command or run manually with `mops test`.\nThe tests use MOPS test framework\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_datetime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedjcase%2Fmotoko_datetime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_datetime/lists"}