Skip to content

Commit

Permalink
Create utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 29, 2022
1 parent 8e96b73 commit 0f0d1dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions panel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ def value_as_date(value):
return value


def datetime_as_utctimestamp(value):
"""
Converts a datetime to a UTC timestamp used by Bokeh interally.
"""
return value.replace(tzinfo=dt.timezone.utc).timestamp() * 1000


def is_number(s):
try:
float(s)
Expand Down
9 changes: 5 additions & 4 deletions panel/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from ..config import config
from ..io import state
from ..util import (
edit_readonly, param_reprs, value_as_datetime, value_as_date
datetime_as_utctimestamp, edit_readonly, param_reprs,
value_as_datetime, value_as_date
)
from ..viewable import Layoutable
from ..layout import Column, Row
Expand Down Expand Up @@ -191,7 +192,7 @@ def _process_param_change(self, msg):
if 'value' in msg:
value = msg['value']
if isinstance(value, dt.datetime):
value = value.replace(tzinfo=dt.timezone.utc).timestamp() * 1000
value = datetime_as_utctimestamp(value)
msg['value'] = value
return msg

Expand Down Expand Up @@ -480,9 +481,9 @@ def _process_param_change(self, msg):
elif 'value' in msg:
v1, v2 = msg['value']
if isinstance(v1, dt.datetime):
v1 = v1.replace(tzinfo=dt.timezone.utc).timestamp() * 1000
v1 = datetime_as_utctimestamp(v1)
if isinstance(v2, dt.datetime):
v2 = v2.replace(tzinfo=dt.timezone.utc).timestamp() * 1000
v2 = datetime_as_utctimestamp(v2)
msg['value'] = (v1, v2)
if msg.get('value_throttled') == (None, None):
del msg['value_throttled']
Expand Down

0 comments on commit 0f0d1dc

Please sign in to comment.