[Python-Dev] dateutil (original) (raw)
Kevin Jacobs jacobs at theopalgroup.com
Mon Mar 15 07:54:22 EST 2004
- Previous message: [Python-Dev] dateutil
- Next message: [Python-Dev] dateutil
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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. endofmonth(d) forwardmonths(n, d) then to "go to the end of the month 3 months from now" would be endofmonth(forwardmonths(3, d)) or, if you prefer a method-chaining style, d.forwardmonths(3).endofmonth()
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
- Previous message: [Python-Dev] dateutil
- Next message: [Python-Dev] dateutil
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]