From 2c754ed9de956b303e12e82b9ad70debed3ee3cc Mon Sep 17 00:00:00 2001 From: Erik Oosterop Date: Sat, 24 Feb 2024 16:54:48 +0000 Subject: [PATCH] Fix date <> integer conversion --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- src/mimosa/dateswithoutdata.py | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dd4ac6..f37b047 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [0.4.2] 2024-02-23 +### Fixed +- Date conversion to integer and back + ## [0.4.1] 2024-02-23 ### Added - Functionality to get a list of date for which no data exists in the target diff --git a/pyproject.toml b/pyproject.toml index d00db65..9e971e2 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ disallow_incomplete_defs = true [tool.poetry] name = "ternyxmimosa" -version = "0.4.1" +version = "0.4.2" description = "A minimal modern data stack with working data pipelines in a single Docker container." authors = ["Erik Oosterop "] license = "MIT" diff --git a/src/mimosa/dateswithoutdata.py b/src/mimosa/dateswithoutdata.py index b8f5a33..9a733f5 100644 --- a/src/mimosa/dateswithoutdata.py +++ b/src/mimosa/dateswithoutdata.py @@ -5,13 +5,15 @@ import datetime import os -from datetime import date # F401 +from datetime import date, timedelta # F401 import duckdb from dotenv import find_dotenv, load_dotenv import mimosa.utilities as tern +DT_BASE = datetime.date(1900, 1, 1) + _ = load_dotenv(find_dotenv()) @@ -24,7 +26,7 @@ def date_to_integer(dt_time): Returns: int: The integer representation of the input date. """ - return 10000 * dt_time.year + 100 * dt_time.month + dt_time.day + return (dt_time - DT_BASE).days def integer_to_date(integer_value): @@ -36,9 +38,7 @@ def integer_to_date(integer_value): Returns: datetime.date: The date corresponding to the integer value. """ - year, remainder = divmod(integer_value, 10000) - month, day = divmod(remainder, 100) - return datetime.date(year, month, day) + return DT_BASE + timedelta(days=integer_value) def get_existing_dates_as_integer(start_dt=date(2018, 1, 1), end_dt=None):