dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
2.3 KiB
2.3 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69162d64f96574d9bb629f03 | Challenge 118: Date Formatter | 29 | challenge-118 |
--description--
Given a date in the format "Month day, year", return the date in the format "YYYY-MM-DD".
- The given month will be the full English month name. For example:
"January","February", etc. - In the return value, pad the month and day with leading zeros if necessary to ensure two digits.
For example, given "December 6, 2025", return "2025-12-06".
--hints--
format_date("December 6, 2025") should return "2025-12-06".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(format_date("December 6, 2025"), "2025-12-06")`)
}})
format_date("January 1, 2000") should return "2000-01-01".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(format_date("January 1, 2000"), "2000-01-01")`)
}})
format_date("November 11, 1111") should return "1111-11-11".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(format_date("November 11, 1111"), "1111-11-11")`)
}})
format_date("September 7, 512") should return "512-09-07".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(format_date("September 7, 512"), "512-09-07")`)
}})
format_date("May 4, 1950") should return "1950-05-04".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(format_date("May 4, 1950"), "1950-05-04")`)
}})
format_date("February 29, 1992") should return "1992-02-29".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(format_date("February 29, 1992"), "1992-02-29")`)
}})
--seed--
--seed-contents--
def format_date(date_string):
return date_string
--solutions--
def format_date(date_string):
months = {
"January": "01",
"February": "02",
"March": "03",
"April": "04",
"May": "05",
"June": "06",
"July": "07",
"August": "08",
"September": "09",
"October": "10",
"November": "11",
"December": "12"
}
month, day, year = date_string.replace(",", "").split(" ")
day = day.zfill(2)
return f"{year}-{months[month]}-{day}"