Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sa-/mo-time
It's time for a time pkg in 🔥 Mojo
https://github.com/sa-/mo-time
Last synced: 27 days ago
JSON representation
It's time for a time pkg in 🔥 Mojo
- Host: GitHub
- URL: https://github.com/sa-/mo-time
- Owner: sa-
- License: apache-2.0
- Created: 2023-09-14T06:35:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-03T10:35:14.000Z (about 1 year ago)
- Last Synced: 2024-02-11T18:46:36.749Z (10 months ago)
- Language: Makefile
- Homepage:
- Size: 34.2 KB
- Stars: 19
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mojo - mo-time - It's time for a time pkg in Mojo🔥. (🗂️ Libraries / Date & Time)
README
![](https://img.shields.io/badge/status-alpha-orange)
Please don't put negative numbers in `plus_*` functions yet 😬
## Usage
Grab a `.mojopkg` from the releases, or clone this repo and run `make build`
```python
from mo_time import Instant, DateTimeLocal# Instantiate with the .now static methods
DateTimeLocal.now_utc()
DateTimeLocal.now()# or from an Instant
let instant = Instant.now()
DateTimeLocal.from_instant(instant)
DateTimeLocal.from_instant_utc(instant)# or with the constructor
DateTimeLocal(2023, 9, 14, 0, 0, 0)# convert back and forth between python and mojo
let py_dt = DateTimeLocal.now().to_py()
let mojo_dt = DateTimeLocal.from_py(py_dt)
let dt = DateTimeLocal.now_utc()
print(dt.__str__())# Supports basic arithmetic
dt.plus_years(1)
dt.plus_months(12)
dt.plus_days(366)
dt.plus_hours(8784)
dt.plus_minutes(527040)
dt.plus_seconds(31622400)
```Coming up
- Types
- `DateTimeOffset`
- `DateTimeZoned`
- `Date`
- `Time`
- `Duration`
- `TimeZone`## Testing
`make test`