Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidate WeeklySchedule (closes #19) #27

Merged
merged 3 commits into from
May 9, 2020

Conversation

basil96
Copy link
Owner

@basil96 basil96 commented May 1, 2020

See changeset. Tested fully on Linux.

@basil96 basil96 requested a review from scliddle May 1, 2020 00:37
@basil96 basil96 changed the title consolidate weekly schedule (closes #19) consolidate WeeklySchedule (closes #19) May 1, 2020
@basil96 basil96 linked an issue May 1, 2020 that may be closed by this pull request
@basil96 basil96 added the refactor For refactoring work label May 1, 2020
Copy link
Collaborator

@scliddle scliddle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One type change request, the other is optional.

src/civilite/schedule.py Outdated Show resolved Hide resolved
src/civilite/schedule.py Outdated Show resolved Hide resolved
src/civilite/schedule.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@scliddle scliddle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is sufficient.

src/civilite/schedule.py Outdated Show resolved Hide resolved
@basil96 basil96 requested a review from scliddle May 8, 2020 14:43
@basil96
Copy link
Owner Author

basil96 commented May 8, 2020

GitHub complains about conflicts in this one now. I don't understand why. When I pull this to a separate clone and checkout this branch, I see no issues. I'd like to perform this merge as an interactive rebase from client side this time instead of using GH.

@basil96
Copy link
Owner Author

basil96 commented May 8, 2020

Ahh, nvm, I have to merge master into this branch first because master had a commit while this was in progress. Why isn't this workflow easier to grasp..

@basil96 basil96 self-assigned this May 8, 2020
@basil96 basil96 marked this pull request as draft May 8, 2020 17:36
@basil96
Copy link
Owner Author

basil96 commented May 8, 2020

Having no fun at all with resolving this merge conflict in GitKraken... this PR is on hold until I figure that out and merge master into this branch.

@basil96 basil96 marked this pull request as ready for review May 9, 2020 01:40
@basil96
Copy link
Owner Author

basil96 commented May 9, 2020

It's ready for review now.

Copy link
Collaborator

@scliddle scliddle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed with a debugger default run of schedule.py leaves tzinfo as None.

This still produces an appropriate sunsets.csv

maybe we didn't need timezonefinder and numpy?

Probably want to fix the else case or undo the timezonefinder change.

tzf = TimezoneFinder()
self.tzinfo = pytz.timezone(tzf.timezone_at(
lat=observer.latitude, lng=observer.longitude))
self.tzinfo = tzinfo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be in an else? seems like if tzinfo is one, we set self.tzinfo, then the next line resets it to None.

Is there a test for this? I'll look maybe I can write one

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! You're right, I made a bug. But after some investigation, I found something interesting..

In this context, calls like astral.sun.twilight() result in astral calling .astimezone(tzinfo) on the given datetime object. When tzinfo is None, the call effectively becomes something like:

>>> pytz.utc.localize(datetime.datetime.utcnow()).astimezone(None)

which returns:

datetime.datetime(2020, 5, 9, 1, 25, 52, 659647, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000), 'Eastern Daylight Time'))

According to Python docs on datetime.astimezone(), it picks up the timezone from the OS in that case:

"If called without arguments (or with tz=None) the system local timezone is assumed for the target timezone. The .tzinfo attribute of the converted datetime instance will be set to an instance of timezone with the zone name and offset obtained from the OS."

That's why it still produces the correct sunsets.csv.

Given this development, we don't need timezonefinder or its friend numpy. I think relying on the correct timezone/locale setup in a client's OS is faster and more reliable.

This means I can remove the entire if block and remove timezonefinder from the project.

There's no unit test for this, you should write one. My only quick test during development was to change lat/lng values significantly and then wondering why sunsets.csv was still the same.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thought: we could follow astral's convention and change the default tzinfo to pytz.utc. Then a caller would have to explicitly pass None if the local system timezone is desired.

* If timezone is not given, do not calculate it from location.  Default to UTC.  If `None` is given, Python will use the calling system's local timezone.

* Remove timezonefinder from project.
Copy link
Collaborator

@scliddle scliddle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because timezonefinder was merged and in master already, I think this Pull Request should be merged and then a new unit test issue opened and worked on from there.

@basil96 basil96 merged commit 3ccec62 into master May 9, 2020
@basil96
Copy link
Owner Author

basil96 commented May 9, 2020

Done, tzf is gone and #30 can be started.

@basil96 basil96 deleted the issue_19_consolidate_WeeklySchedule branch November 30, 2022 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor For refactoring work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

move module-level functions into WeeklySchedule as appropriate
2 participants