[Question] Boundaries of the week and month #293
-
|
Hello! First of all — great project, and thanks for the fresh take on the problem. I’ve started replacing usage the standard library in my codebase with whenever and gradually throwing away a bunch of my own hacky helpers. However, I have an example I couldn’t immediately replace: functions that return the “boundaries”, "spans" of weeks and months — the first and last days of a week, and the first and last days of a month. Of course, once you’ve got deltas, nothing is impossible, but my current solution still looks like something I came up with while using the standard library: now = whenever.Date.today_in_system_tz()
first_day_of_month = now.replace(day=1)
last_day_of_month = first_day_of_month + months(1) - days(1)
monday_of_week = now - days(now.day_of_week().value - 1)
sunday_of_week = monday_of_week + days(6)Maybe I’ve missed something in the documentation and there’s a more idiomatic way to do this? Thanks in advance. P.S. Really waiting for ranges and intervals too! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @treylav thanks for posting. I have given this some thought, although my focus at the moment is on getting the last breaking changes out (also relating to deltas). For your use case, I do expect to improve support. Note that I will take some time to get this API right, as I want to avoid having too many methods, which is confusing and error-prone |
Beta Was this translation helpful? Give feedback.
Hi @treylav thanks for posting. I have given this some thought, although my focus at the moment is on getting the last breaking changes out (also relating to deltas).
For your use case, I do expect to improve support. Note that
round()already does what you want for hours/minutes/seconds. For years/months/days it gets a bit more complicated, that's why there's no support yet. I might integrate them intoround(), or add methodsstart_of(<unit>)andend_of(<unit>). There'd have to a separate API for the next weekday case.I will take some time to get this API right, as I want to avoid having too many methods, which is confusing and error-prone