Skip to content

Commit

Permalink
Format full years separately
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkohei13 committed Jul 23, 2024
1 parent 5a06cca commit 0b8e212
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def make_challenge_html(challenge):

html += "<h1>" + challenge["title"] + "</h1>"
html += "<p>" + str(challenge["description"]) + "</p>"
html += "<p>Osallistumisaika: " + common_helpers.date_to_fi(challenge["date_begin"]) + " &ndash; " + common_helpers.date_to_fi(challenge["date_end"]) + "</p>"
html += "<p>Osallistumisaika: " + common_helpers.date_to_fi(challenge["date_begin"], challenge["date_end"]) + "</p>"

if challenge["status"] == "open":
html += "<p><strong>Tämä haaste on avoinna, tervetuloa osallistumaan!</strong></p>"
Expand Down
15 changes: 11 additions & 4 deletions app/helpers/common_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,14 @@ def get_participant_count(participations, target_count):

return count

# Function to convert date YYYY-MM-DD to Finnish date format, without leading zeroes
def date_to_fi(date):
date_parts = date.split("-")
return f"{ int(date_parts[2]) }.{ int(date_parts[1]) }.{ date_parts[0] }"
# Function to format a pair of dates to Finnish date format
def date_to_fi(date_begin, date_end):
date_begin_parts = date_begin.split("-")
date_end_parts = date_end.split("-")

# Check if whole year
if date_begin_parts[1] == "01" and date_begin_parts[2] == "01" and date_end_parts[1] == "12" and date_end_parts[2] == "31":
return f"koko vuosi { date_begin_parts[0] }"

# Else return formatted date range
return f"{ date_begin_parts[2] }.{ date_begin_parts[1] }.{ date_begin_parts[0] } &ndash; { date_end_parts[2] }.{ date_end_parts[1] }.{ date_end_parts[0] }"

0 comments on commit 0b8e212

Please sign in to comment.