Greg Ewing wrote: >>>>>now.replace(month=2, day=30) >>>>> >>>>> >If I were designing something like this, I think I would approach it >quite differently, and provide a bunch of separate functions or >methods that transform dates in specific ways. e.g. > > end_of_month(d) > forward_months(n, d) > >then to "go to the end of the month 3 months from now" would >be > > end_of_month(forward_months(3, d)) > >or, if you prefer a method-chaining style, > > d.forward_months(3).end_of_month() > > After using such a system in a large system with non-trivial date manipulations, I think you'd change your mind about that approach -- it can be excessively verbose. Being able to change a full array of date and time components in one call is _very_ useful. However, in my datetime classes, I also have a very complete set of calls like: startOfMonth, endOfMonth, startOfYear, endOfYear, lastWeekday, nextWeekday, etc... That way your code that needs the power and benefits from the compactness of the powerful relative and absolute adjustment functions (with many parameters), but also has very readable simple adjustments for common cases and for novice programmers to get started. Best regards, -Kevin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4