modifiers
In the previous article, I left some parts of the modifiers in this article I covered it.
#CODE
import pendulum
dt = pendulum.datetime(2022, 1, 31, 12, 0, 0)
print(dt.start_of('week'))
print(dt.day_of_week == pendulum.MONDAY)
print(dt.end_of('week'))
print(dt.day_of_week == pendulum.SUNDAY)
print(dt.next(pendulum.WEDNESDAY))
print(dt.day_of_week == pendulum.WEDNESDAY)
dt = pendulum.datetime(2022, 1, 1, 12, 0, 0)
print(dt.next())
print(dt.next(keep_time=True))
dt = pendulum.datetime(2022, 1, 31, 12, 0, 0)
print(dt.previous(pendulum.WEDNESDAY))
print(dt.day_of_week == pendulum.WEDNESDAY)
dt = pendulum.datetime(2022, 1, 1, 12, 0, 0)
print(dt.previous())
print(dt.previous(keep_time=True))
start = pendulum.datetime(2024, 1, 1)
end = pendulum.datetime(2024, 1, 30)
print(start.average(end))
# others that are defined that are similar
# and tha accept month, quarter and year units
# first_of(), last_of(), nth_of()
#OUTPUT
2022-01-31T00:00:00+00:00
True
2022-02-06T23:59:59.999999+00:00
False
2022-02-02T00:00:00+00:00
False
2022-01-08T00:00:00+00:00
2022-01-08T12:00:00+00:00
2022-01-26T00:00:00+00:00
False
2021-12-25T00:00:00+00:00
2021-12-25T12:00:00+00:00
2024-01-15T12:00:00+00:00
Comments