Skip to content

Commit

Permalink
Merge pull request #6 from EJOOSTEROP:fix_integerdate
Browse files Browse the repository at this point in the history
Fix date <> integer conversion
  • Loading branch information
EJOOSTEROP authored Feb 24, 2024
2 parents e279eaa + 2c754ed commit f67cc10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
<!-- insertion marker -->
## [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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
license = "MIT"
Expand Down
10 changes: 5 additions & 5 deletions src/mimosa/dateswithoutdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())


Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit f67cc10

Please sign in to comment.