From dc4c2804f6eae12c7ceff27ebfbcae5226b86cc9 Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Sat, 10 Jun 2023 11:35:49 -0400 Subject: [PATCH 1/3] Auto-converts PlotLine.value from datetime to numeric. Closes #58 --- highcharts_core/options/axes/plot_bands.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/highcharts_core/options/axes/plot_bands.py b/highcharts_core/options/axes/plot_bands.py index 4c276af1..b2bfabe6 100644 --- a/highcharts_core/options/axes/plot_bands.py +++ b/highcharts_core/options/axes/plot_bands.py @@ -349,6 +349,9 @@ def value(self) -> Optional[int | float | Decimal]: @value.setter def value(self, value): + if hasattr(value, 'timestamp'): + value = value.timestamp() * 1000 + self._value = validators.numeric(value, allow_empty = True) @property From d86da20650316e9940479a9199778dcd7aaaef34 Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Sat, 10 Jun 2023 11:36:25 -0400 Subject: [PATCH 2/3] Updated serialization of datetime to milliseconds rather than seconds. Closes #61. --- highcharts_core/js_literal_functions.py | 2 +- highcharts_core/options/plot_options/series.py | 4 ++-- highcharts_core/options/plot_options/treegraph.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/highcharts_core/js_literal_functions.py b/highcharts_core/js_literal_functions.py index 15019c50..914fba01 100644 --- a/highcharts_core/js_literal_functions.py +++ b/highcharts_core/js_literal_functions.py @@ -49,7 +49,7 @@ def serialize_to_js_literal(item, encoding = 'utf-8') -> Optional[str]: elif checkers.is_datetime(item): if not item.tzinfo: item = item.replace(tzinfo = datetime.timezone.utc) - return item.timestamp() + return item.timestamp()*1000 elif checkers.is_date(item): return f'Date.UTC({item.year}, {item.month - 1}, {item.day})' elif checkers.is_time(item): diff --git a/highcharts_core/options/plot_options/series.py b/highcharts_core/options/plot_options/series.py index 9f2074b6..04a0de72 100644 --- a/highcharts_core/options/plot_options/series.py +++ b/highcharts_core/options/plot_options/series.py @@ -797,10 +797,10 @@ def point_start(self, value): value = validators.datetime(value) if hasattr(value, 'timestamp') and value.tzinfo is not None: - self._point_start = value.timestamp() + self._point_start = value.timestamp()*1000 elif hasattr(value, 'timestamp'): value = value.replace(tzinfo = datetime.timezone.utc) - value = value.timestamp() + value = value.timestamp()*1000 else: raise error diff --git a/highcharts_core/options/plot_options/treegraph.py b/highcharts_core/options/plot_options/treegraph.py index 6d85957f..8797c8b5 100644 --- a/highcharts_core/options/plot_options/treegraph.py +++ b/highcharts_core/options/plot_options/treegraph.py @@ -491,10 +491,10 @@ def point_start(self, value): value = validators.datetime(value) if hasattr(value, 'timestamp') and value.tzinfo is not None: - self._point_start = value.timestamp() + self._point_start = value.timestamp()*1000 elif hasattr(value, 'timestamp'): value = value.replace(tzinfo = datetime.timezone.utc) - value = value.timestamp() + value = value.timestamp()*1000 else: raise error From 80d21d476acd8215b329a814000fad74fb8ec456 Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Sat, 10 Jun 2023 11:36:36 -0400 Subject: [PATCH 3/3] Bumped version number and updated changelog. --- CHANGES.rst | 10 ++++++++++ highcharts_core/__version__.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index a45504d5..a6c783ef 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,11 @@ +Release 1.2.1 +========================================= + +* **ENHANCEMENT:** Added autoconversion of ``plotLine.value`` from ``datetime.datetime`` to POSIX timestamp (#58). +* **BUGFIX:** Fixed incorrect ``datetime`` serialization to SECONDS from Unix epoch. Now serializing to JS-compatible MILLISECONDS from Unix epoch (#61). + +------------------ + Release 1.2.0 ========================================= @@ -25,6 +33,8 @@ Release 1.1.1 * **FIXED:** Problem when producing a JS literal, with the JS code inserting an unnecessary ``new`` (#42 and #43). * **ENHANCEMENT:** Added more elegant error handling when something goes wrong displaying a chart in Jupyter (#43). +------------- + Release 1.1.0 ========================================= diff --git a/highcharts_core/__version__.py b/highcharts_core/__version__.py index e916218b..ce34e913 100644 --- a/highcharts_core/__version__.py +++ b/highcharts_core/__version__.py @@ -1 +1 @@ -__version__ = '1.2.0' \ No newline at end of file +__version__ = '1.2.1' \ No newline at end of file