Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bokeh DatePicker value format inconsistent #8015

Closed
martin-centerid opened this issue Jun 20, 2018 · 5 comments

Comments

@martin-centerid
Copy link

commented Jun 20, 2018

I have two DatePicker widgets and I am trying to pass the DatePicker values thru the URL when the user changes the DatePicker value, and I am seeing odd behavior. The DatePicker date format toggles between a string and an epoch when I change the other DatePicker. Best shown by example, here are two URLs that are produced when I change each DatePicker,

http://127.0.0.1:6800/?start_date=1529424998666&end_date=Tue%20Jun%2019%202018 http://127.0.0.1:6800/?start_date=Fri%20Jun%2008%202018&end_date=1529512006618

Browser: Chrome
Host OS: Windows 10
Python: 2.7.11

from datetime import datetime, timedelta
from bokeh.embed import components
from bokeh.models.widgets.inputs import DatePicker
from bokeh.models.callbacks import CustomJS
from bokeh.layouts import column

from flask import Flask

app = Flask(__name__)


@app.route("/", methods=['GET'])
def test():
    text = """<!DOCTYPE html>
    <html lang="en">
    <head>
        <link href="https://cdn.pydata.org/bokeh/release/bokeh-0.12.15.min.css" rel="stylesheet" type="text/css">
        <script src="https://cdn.pydata.org/bokeh/release/bokeh-0.12.15.min.js"></script>
        <link href="https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.15.min.css" rel="stylesheet" type="text/css">
        <script src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.15.min.js"></script>
        <meta charset="UTF-8">
    </head>
    <body>"""

    d_yesterday = datetime.today() - timedelta(days=1)
    d_year_ago = datetime.today() - timedelta(days=365)
    datepicker_start = DatePicker(title="Start Date", min_date=d_year_ago, max_date=datetime.now(), value=d_yesterday)
    datepicker_end = DatePicker(title="End Date", min_date=d_year_ago, max_date=datetime.today(), value=datetime.today())

    all_callback = CustomJS(args=dict(d_start=datepicker_start, d_end=datepicker_end), code="""
        function encodeQueryData(data) {
            let ret = [];
            for (let d in data)
                ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d]));
            return ret.join('&');
        }
        var params = {'start_date': d_start.value, 'end_date': d_end.value }
        var url = '/?' + encodeQueryData(params)
        window.location.replace(url);
    """)
    datepicker_start.callback = all_callback
    datepicker_end.callback = all_callback

    layout = column(datepicker_start, datepicker_end)
    _script, _div = components(layout)
    text += "{}{}".format(_script, _div)

    text += """
    </body></html>
    """

    return text

app.run(host="0.0.0.0", port=6800)
@mgagcode

This comment has been minimized.

Copy link

commented Jul 5, 2018

I also noticed that the datepicker can be one day off from what the user selected when using the callback.
And the date sliders also have inconsistent formats, epoch and string.

@bryevdv

This comment has been minimized.

Copy link
Member

commented Jul 9, 2018

Note: #8009 appears to be a dupe but verify any solution to this issue solves that as well.

@lukemcraig

This comment has been minimized.

Copy link
Contributor

commented Aug 2, 2018

In regards to the off-by-one-day bug, I've noticed that when I set my computer clock to UTC and restart my browser (Firefox) the displayed value in the datepicker is correct when set from the python server.

@bryevdv bryevdv modified the milestones: 0.13.x, short-term Sep 11, 2018

@bryevdv

This comment has been minimized.

Copy link
Member

commented Sep 18, 2018

I believe this issue also affects the dat3 range slider, which can return e.g. a date object as well as ms since epoch.

@bryevdv

This comment has been minimized.

Copy link
Member

commented Jul 13, 2019

I am fixing this in a PR for #8934

@bryevdv bryevdv referenced this issue Jul 13, 2019
2 of 3 tasks complete

@bryevdv bryevdv modified the milestones: short-term, 1.3 Jul 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.