Skip to content

Commit

Permalink
Updated releaseWizard.py to use timezone-aware objects to represent d…
Browse files Browse the repository at this point in the history
…atetimes in UTC (#14102)


Co-authored-by: Shubham Sharma <[email protected]>
  • Loading branch information
shubhamsrkdev and Shubham Sharma authored Jan 9, 2025
1 parent 0169c1e commit 3fad719
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions dev-tools/scripts/releaseWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from collections import OrderedDict
from datetime import datetime
from datetime import timedelta
from datetime import timezone

try:
import holidays
Expand Down Expand Up @@ -99,7 +100,7 @@ def expand_jinja(text, vars=None):
'state': state,
'gpg_key' : state.get_gpg_key(),
'gradle_cmd' : 'gradlew.bat' if is_windows() else './gradlew',
'epoch': unix_time_millis(datetime.utcnow()),
'epoch': unix_time_millis(datetime.now(tz=timezone.utc)),
'get_next_version': state.get_next_version(),
'current_git_rev': state.get_current_git_rev(),
'keys_downloaded': keys_downloaded(),
Expand Down Expand Up @@ -199,7 +200,7 @@ def check_prerequisites(todo=None):
return True


epoch = datetime.utcfromtimestamp(0)
epoch = datetime.fromtimestamp(timestamp=0, tz=timezone.utc)


def unix_time_millis(dt):
Expand Down Expand Up @@ -279,7 +280,7 @@ def __init__(self, config_path, release_version, script_version):
self.latest_version = None
self.previous_rcs = {}
self.rc_number = 1
self.start_date = unix_time_millis(datetime.utcnow())
self.start_date = unix_time_millis(datetime.now(tz=timezone.utc))
self.script_branch = run("git rev-parse --abbrev-ref HEAD").strip()
self.mirrored_versions = None
try:
Expand Down Expand Up @@ -741,7 +742,7 @@ def get_vars(self):

def set_done(self, is_done):
if is_done:
self.state['done_date'] = unix_time_millis(datetime.utcnow())
self.state['done_date'] = unix_time_millis(datetime.now(tz=timezone.utc))
if self.persist_vars:
for k in self.persist_vars:
self.state[k] = self.get_vars()[k]
Expand Down Expand Up @@ -935,7 +936,7 @@ def expand_multiline(cmd_txt, indent=0):


def unix_to_datetime(unix_stamp):
return datetime.utcfromtimestamp(unix_stamp / 1000)
return datetime.fromtimestamp(timestamp=unix_stamp / 1000, tz=timezone.utc)


def generate_asciidoc():
Expand All @@ -949,7 +950,7 @@ def generate_asciidoc():

fh.write("= Lucene Release %s\n\n" % state.release_version)
fh.write("(_Generated by releaseWizard.py v%s at %s_)\n\n"
% (getScriptVersion(), datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC")))
% (getScriptVersion(), datetime.now(tz=timezone.utc).strftime("%Y-%m-%d %H:%M UTC")))
fh.write(":numbered:\n\n")
fh.write("%s\n\n" % template('help'))
for group in state.todo_groups:
Expand Down Expand Up @@ -1839,17 +1840,17 @@ def create_ical(todo): # pylint: disable=unused-argument
return True


today = datetime.utcnow().date()
today = datetime.now(tz=timezone.utc).date()
sundays = {(today + timedelta(days=x)): 'Sunday' for x in range(10) if (today + timedelta(days=x)).weekday() == 6}
y = datetime.utcnow().year
y = datetime.now(tz=timezone.utc).year
years = [y, y+1]
non_working = holidays.CA(years=years) + holidays.US(years=years) + holidays.UK(years=years) \
+ holidays.DE(years=years) + holidays.NO(years=years) + holidays.IN(years=years) + holidays.RU(years=years)


def vote_close_72h_date():
# Voting open at least 72 hours according to ASF policy
return datetime.utcnow() + timedelta(hours=73)
return datetime.now(tz=timezone.utc) + timedelta(hours=73)


def vote_close_72h_holidays():
Expand Down

0 comments on commit 3fad719

Please sign in to comment.