jayvdb added a comment.
Note this task was created in May, when py3 support was not available.
I have tested generate_user_files now using py3.3 & py3.4 on Windows 7, and it works correctly except for a py3 bug in the terminal interface (T76236)
TASK DETAIL
https://phabricator.wikimedia.org/T67675
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: jayvdb
Cc: pywikipedia-bugs, valhallasw, XZise, jayvdb, Xqt
jayvdb added a comment.
There is also the very useful https://labix.org/python-dateutil
If we want our own implementation, the core problem is getting the number of days in the month, and there are a few ways to achieve that in python
http://stackoverflow.com/questions/42950/get-last-day-of-the-month-in-python
Once that algorithm is in core, the ability to do month operations is simple.
TASK DETAIL
https://phabricator.wikimedia.org/T73124
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: jayvdb
Cc: pywikipedia-bugs, Legoktm, jayvdb, XZise, Multichill, Xqt
gerritbot added a project: Patch-For-Review.
gerritbot added a comment.
Change 176349 had a related patch set uploaded (by XZise):
[FEAT] Date: Add/subtract months from a date
[[https://gerrit.wikimedia.org/r/176349]]
#patch-for-review
TASK DETAIL
https://phabricator.wikimedia.org/T73124
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: gerritbot
Cc: pywikipedia-bugs, Legoktm, jayvdb, XZise, Multichill, Xqt
XZise added a comment.
Okay here is one flexible solution which does work with any month length and any number of months (> 1) in a year:
```
def month_delta(date, month_delta=1):
if int(month_delta) != month_delta:
raise ValueError('Month delta must be an integer')
delta = -1 if month_delta < 0 else +1
month = date.month
target_day = date.day
while date.day != target_day or month_delta != 0:
date += datetime.timedelta(days=delta)
if date.month != month:
# month number has changed
month_delta -= delta
month = date.month
return date
```
It's basically adding or removing one day and checks if the month number changes. If that is the case it reduces the number of months by one until no delta is left. Then it checks if the day number is equal to the original day number and stops if that is the case.
You could speed that up if you rely on the fact a month has at least N days and a year has always M months:
```
min_day_per_month = 28
months_per_year = 12
def month_delta2(date, month_delta=1):
if int(month_delta) != month_delta:
raise ValueError('Month delta must be an integer')
delta = -1 if month_delta < 0 else +1
new_date = date + datetime.timedelta(days=min_day_per_month * month_delta)
# figure out how many months have been skipped
month_delta -= (new_date.year - date.year) * months_per_year - date.month + new_date.month
month = new_date.month
while new_date.day != date.day or month_delta != 0:
new_date += datetime.timedelta(days=delta)
if new_date.month != month:
# month number has changed
month_delta -= delta
month = new_date.month
import time; time.sleep(2)
return new_date
```
This already skips "month_delta * N" days, so you only need to add a few (`<= |4*month_delta|`).
TASK DETAIL
https://phabricator.wikimedia.org/T73124
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: XZise
Cc: pywikipedia-bugs, Legoktm, jayvdb, XZise, Multichill, Xqt
XZise edited the task description.
XZise removed a subscriber: Unknown Object (????).
XZise removed a project: Patch-For-Review.
XZise set Security to none.
TASK DETAIL
https://phabricator.wikimedia.org/T71015
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: XZise
Cc: pywikipedia-bugs, XZise, jayvdb, Mpaa, Xqt
XZise closed this task as "Resolved".
XZise claimed this task.
XZise added a comment.
Ops, didn't saw it was marked for easy :/
TASK DETAIL
https://phabricator.wikimedia.org/T71015
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: XZise
Cc: pywikipedia-bugs, XZise, jayvdb, Mpaa, Xqt
XZise closed blocking task T71015: cfd assumes family wikipedia as "Resolved".
TASK DETAIL
https://phabricator.wikimedia.org/T71069
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: XZise
Cc: pywikipedia-bugs, zhuyifei1999, Ricordisamoa, jayvdb
XZise closed this task as "Resolved".
XZise added a comment.
Okay here is what happens in Python 3.3:
```
Python 3.3.0 (default, Aug 28 2014, 16:59:28)
[GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0700
File "<stdin>", line 1
0700
^
SyntaxError: invalid token
```
Which is exactly the error described, as that is fixed this bug is fixed (at least the result you describe). If it still does not work on Windows with Python 3 feel free to reopen the bug with the actual error message.
TASK DETAIL
https://phabricator.wikimedia.org/T67675
REPLY HANDLER ACTIONS
Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
To: jayvdb, XZise
Cc: pywikipedia-bugs, valhallasw, XZise, jayvdb, Xqt