Files
learn-python3/notebooks/beginner/exercises/15_std_lib1_exercise.ipynb
2023-04-22 14:55:42 +03:00

107 lines
2.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Playing with datetimes\n",
"You're given a naive datetime, see `NAIVE_DT` variable below. Although this variable is naive, you happen to know that the time specified by `NAIVE_DT` is in UTC.\n",
"\n",
"Based on this information, your task is to create new datetime variables by converting `NAIVE_DT` to UTC and then to time in Sydney and Los Angeles. Use the following variable names: `utc_dt`, `sydney_dt`, and `la_dt`. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": false
},
"outputs": [],
"source": [
"import datetime as dt\n",
"from zoneinfo import ZoneInfo, available_timezones\n",
"\n",
"NAIVE_DT = dt.datetime(2000, 1, 1, 10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you don't know the timezone name you're looking for, this may be helpful:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": false
},
"outputs": [],
"source": [
"for tz in available_timezones():\n",
" print(tz)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now create `utc_dt`, `sydney_dt`, and `la_dt`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your implementation here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's verify that the solution is correct."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": false
},
"outputs": [],
"source": [
"assert utc_dt.isoformat() == \"2000-01-01T10:00:00+00:00\"\n",
"assert sydney_dt.isoformat() == \"2000-01-01T21:00:00+11:00\"\n",
"assert la_dt.isoformat() == \"2000-01-01T02:00:00-08:00\"\n",
"\n",
"print(\"All good!\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}