Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: mozdownload/timezones.py

Issue 1451373002: Updating mozdownload (excluding tests) (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/mozdownload@master
Patch Set: Updated README.md Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mozdownload/scraper.py ('k') | mozdownload/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 """Module for providing specific timezones""" 5 """Module for providing specific timezones"""
6 6
7 from datetime import datetime, timedelta, tzinfo 7 from datetime import datetime, timedelta, tzinfo
8 8
9 9
10 class PacificTimezone(tzinfo): 10 class PacificTimezone(tzinfo):
11 """Class to set the timezone to PST/PDT and automatically adjusts 11 """Class to set the timezone to PST/PDT and automatically adjusts
12 for daylight saving. 12 for daylight saving.
13 """ 13 """
14 14
15 def utcoffset(self, dt): 15 def utcoffset(self, dt):
16 return timedelta(hours=-8) + self.dst(dt) 16 return timedelta(hours=-8) + self.dst(dt)
17 17
18
19 def tzname(self, dt): 18 def tzname(self, dt):
20 return "Pacific" 19 return "Pacific"
21 20
22
23 def dst(self, dt): 21 def dst(self, dt):
24 # Daylight saving starts on the second Sunday of March at 2AM standard 22 # Daylight saving starts on the second Sunday of March at 2AM standard
25 dst_start_date = self.first_sunday(dt.year, 3) + timedelta(days=7) \ 23 dst_start_date = self.first_sunday(dt.year, 3) + timedelta(days=7) \
26 + timedelta(hours=2) 24 + timedelta(hours=2)
27 # Daylight saving ends on the first Sunday of November at 2AM standard 25 # Daylight saving ends on the first Sunday of November at 2AM standard
28 dst_end_date = self.first_sunday(dt.year, 11) + timedelta(hours=2) 26 dst_end_date = self.first_sunday(dt.year, 11) + timedelta(hours=2)
29 27
30 if dst_start_date <= dt.replace(tzinfo=None) < dst_end_date: 28 if dst_start_date <= dt.replace(tzinfo=None) < dst_end_date:
31 return timedelta(hours=1) 29 return timedelta(hours=1)
32 else: 30 else:
33 return timedelta(0) 31 return timedelta(0)
34 32
35
36 def first_sunday(self, year, month): 33 def first_sunday(self, year, month):
37 date = datetime(year, month, 1, 0) 34 date = datetime(year, month, 1, 0)
38 days_until_sunday = 6 - date.weekday() 35 days_until_sunday = 6 - date.weekday()
39 36
40 return date + timedelta(days=days_until_sunday) 37 return date + timedelta(days=days_until_sunday)
OLDNEW
« no previous file with comments | « mozdownload/scraper.py ('k') | mozdownload/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698