Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create intoduction for dig deeper in gigasecond exercise #3772

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions exercises/practice/gigasecond/.approaches/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"introduction": {
"authors": ["SNEAXIII"],
"contributors": []
}
}
22 changes: 22 additions & 0 deletions exercises/practice/gigasecond/.approaches/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dig deeper
There is only one correct and safe way to deal with date and datetime in python. We are going to use the built-in `datetime` module. A `datetime` object contains multiple attributes, like `year`, `month`, `day`, `hour`, `minute` and `second`.
But you can't update a `datetime` object directly like:
```py
from datetime import datetime
datetime_2000_01_25 = datetime(year = 2000, month = 1, day = 25)
wrong_date = datetime_2000_01_25 + "2 weeks" # This won't work at all
```
Instead, we have to use another one object, `timedelta`. It will be used to accomplish the same thing as shown in the previous example. This object is a time interval, which can be used to modify a `datetime` object. We can add or subtract the `timedelta` to a `datetime` object to create a new `datetime` object with the updated values.
```py
from datetime import timedelta, datetime
datetime_2000_01_01 = datetime(year = 2000, month = 1, day = 1)
delta = timedelta(weeks=2)
datetime_2000_01_15 = datetime_2000_01_01 + delta
```
In the exercise, we have one `datetime` parameter, so one of the correct answer is:
```py
from datetime import timedelta, datetime
def add(moment: datetime) -> datetime:
return moment + timedelta(seconds=10**9)
```
For more information, check the official [datetime documentation](https://docs.python.org/3/library/datetime.html#datetime.datetime.year)
Loading