Releases: mojoto/morrow.mojo
Releases Β· mojoto/morrow.mojo
v0.4.0
What's Changed
- Adapt to mojo v24.5
- Update constants.mojo for 24.2 StaticTuple changes by @thatstoasty in #9
New Contributors
- @thatstoasty made their first contribution in #9
Full Changelog: v0.3.1...v0.4.0
v0.3.1
v0.3.0
π Celebration! The third version of Morrow
is released.
Features
- For
Morrow
- β¨ Add format method, like Arrow api
Example
let m = Morrow(2024, 2, 1, 3, 4, 5, 123456)
m.format("YYYY-MM-DD HH:mm:ss.SSSSSS ZZ") # 2024-02-01 03:04:05.123 +00:00
m.format("dddd, DD MMM YYYY HH:mm:ss ZZZ") # Sunday, 01 Oct 2023 00:00:00 UTC
m.format("YYYY[Y]MM[M]DD[D]") # 2023Y10M01D, "[ ]" for escape replace
v0.2.0
π Celebration! The second version of Morrow
is released.
Features
- For
Morrow
- β¨ Add
fromordinal()
which constructs aMorrow
from a proleptic Gregorian ordinal. - β¨ The underlying implementation of
strptime()
has been replaced from Python to libc. - β¨ Add
to_py()
andfrom_py()
to which can convert between Morrow and Python datetime.
- β¨ Add
- For
TimeDelta
- β¨ Add many methods, such as
total_seconds()
,__add__()
,__radd_()
,__sub__()
,__rsub__()
and so on. - β¨ Add 3 new
TimeDelta
constants inmorrow.timedelta
:Min
,Max
,Resolution
. - β¨ The
__init__()
method supports weeks, hours, minutes, milliseconds.
- β¨ Add many methods, such as
Internal
- π§ Run tests only on pull_request.
Example
from morrow import Morrow
# Return proleptic Gregorian ordinal for the year, month and day.
let m = Morrow(2023, 10, 1)
let ordinal = m.toordinal()
print(ordinal) # 738794
# Construct a Morrow from a proleptic Gregorian ordinal.
let m2 = Morrow.fromordinal(ordinal)
print(m2.__str__()) # 2023-10-01T00:00:00.000000
# Convert Morrow to python datetime
let now = Morrow.now()
let py_dt = now.to_py()
print(dt.isoformat()) # 2023-10-01T20:10:25.188957
# Convert python datetime to Morrow
let m_from_py = Morrow.from_py(py_dt)
print(m_from_py.__str__()) # 2023-10-01T20:10:25.188957
v0.1.0
π Celebration! The first version of Morrow
is released.
Morrow is a Mojo library that provides human-friendly method for managing, formatting, and transforming dates, times, and timestamps.
Features
- β¨ TimeZone-aware and UTC by default
- β¨ Support format and parse strings
- β¨ Support for the ISO 8601 standard
Example
from morrow import Morrow, TimeZone
# Get local date and time.
let now = Morrow.now()
print(now.__str__()) # 2023-10-01T20:10:25.188957+08:00
# Get UTC date and time.
let utcnow = Morrow.utcnow()
print(utcnow.__str__()) # 2023-10-01T20:10:25.954638+00:00
# Get local time from POSIX timestamp.
let t = Morrow.fromtimestamp(1696089600)
print(t.__str__()) # 2023-10-01T00:00:00.000000+08:00
# Get UTC time from POSIX timestamp.
let utc_t = Morrow.utcfromtimestamp(1696089600)
print(utc_t.__str__()) # 2023-09-30T16:00:00.000000+00:00
# Get ISO format.
let m = Morrow(2023, 10, 1, 0, 0, 0, 1234)
print(m.isoformat()) # 2023-10-01T00:00:00.001234
# Get ISO format with time zone.
let m_beijing = Morrow(2023, 10, 1, 0, 0, 0, 1234, TimeZone(28800, 'Bejing'))
print(m_beijing.isoformat(timespec="seconds")) # 2023-10-01T00:00:00+08:00
# Get time zone offset.
print(TimeZone.from_utc('UTC+08:00').offset) # 28800
# Subtract two dates.
let timedelta = Morrow(2023, 10, 2, 10, 0, 0) - Morrow(2023, 10, 1, 10, 0, 0)
print(timedelta.__str__()) # 1 day 0:00:00