Skip to content

Reverse Conversion: Create datetime from vector#10

Merged
kitsuyui merged 2 commits into
mainfrom
vec-to-time
Jan 26, 2023
Merged

Reverse Conversion: Create datetime from vector#10
kitsuyui merged 2 commits into
mainfrom
vec-to-time

Conversation

@kitsuyui

Copy link
Copy Markdown
Owner

We can create year_vec and day_vec to represent the position in the year and the position in the day.
Then, we can create datetime from them.

import timevec.builtin_math as tv
import datetime
dt = datetime.datetime.now()
yv = tv.year_vec(dt)
dv = tv.day_vec(dt)
dt2 = tv.datetime_from_vec(dt.year, yv, dv)
assert dt == dt2  # This is true (but there may be a small floating point error)

We can create year_vec and day_vec to represent the position in the year and the position in the day.
Then, we can create datetime from them.

```python
import timevec.builtin_math as tv
import datetime
dt = datetime.datetime.now()
yv = tv.year_vec(dt)
dv = tv.day_vec(dt)
dt2 = tv.datetime_from_vec(dt.year, yv, dv)
assert dt == dt2  # This is true (but there may be a small floating point error)
```
@kitsuyui kitsuyui merged commit 902fcff into main Jan 26, 2023
@kitsuyui kitsuyui deleted the vec-to-time branch January 26, 2023 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant