Skip to content

Releases: mojoto/morrow.mojo

v0.4.0

01 Oct 13:57
Compare
Choose a tag to compare

What's Changed

  • Adapt to mojo v24.5
  • Update constants.mojo for 24.2 StaticTuple changes by @thatstoasty in #9

New Contributors

Full Changelog: v0.3.1...v0.4.0

v0.3.1

11 Mar 13:33
Compare
Choose a tag to compare

Features

  • ✨ Adapt to mojo v24.1.0.

Internal

  • βœ… Supports make format to format the project.

v0.3.0

17 Feb 12:13
8ff075a
Compare
Choose a tag to compare

πŸŽ‰ Celebration! The third version of Morrow is released.

Features

  • For Morrow

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

24 Oct 14:03
Compare
Choose a tag to compare

πŸŽ‰ Celebration! The second version of Morrow is released.

Features

  • For Morrow
    • ✨ Add fromordinal() which constructs a Morrow from a proleptic Gregorian ordinal.
    • ✨ The underlying implementation of strptime() has been replaced from Python to libc.
    • ✨ Add to_py() and from_py() to which can convert between Morrow and Python datetime.
  • For TimeDelta
    • ✨ Add many methods, such as total_seconds(), __add__(), __radd_(), __sub__(), __rsub__() and so on.
    • ✨ Add 3 new TimeDelta constants in morrow.timedelta: Min, Max, Resolution.
    • ✨ The __init__() method supports weeks, hours, minutes, milliseconds.

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

17 Oct 13:02
Compare
Choose a tag to compare

πŸŽ‰ 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