bootstrap-datepicker icon indicating copy to clipboard operation
bootstrap-datepicker copied to clipboard

Add timepicker

Open rchavik opened this issue 10 years ago • 30 comments

This is based on bufferapp's fork applied on top of master. It has been rewritten to display seconds instead of meridiem.

Usage example:

    $('#NodeCreated').datepicker({
        showTime: true,
        autoclose: false, // when showTime is true, autoclose is ignored
        todayBtn: true,
        todayHighlight: true,
        clearBtn: true,
        format: 'yyyy-mm-dd H:i:s'
    });

Here's how it looks:

screenshot from 2014-04-23 19 52 47

rchavik avatar Apr 23 '14 12:04 rchavik

Are seconds optional? I typically never want to ask my users to enter seconds. And I do want to ask them meridian. So I think those should be options.

jeremyhaile avatar Apr 23 '14 15:04 jeremyhaile

@jeremyhaile i went for the easy route for now.

@kia84 yeah.. that was copied from the original.

i see travis failed for some tests as well, but before i fix these up, i'll wait @eternicode's comment whether this is potentially mergable or not.

rchavik avatar Apr 24 '14 06:04 rchavik

:+1: for this PR! This is a useful thing that we are waiting for a long time.

korun avatar Apr 28 '14 10:04 korun

i agree with kia84!

norbornen avatar Apr 28 '14 10:04 norbornen

Being able to set "steps" for the minute (and possible hour), or a min/max value would be useful as well.

I have a situation where I would like users to be only able to pick minutes that are 00, :15, :30 or :45, and restrict the hour to a range of 07 to 22.

Seconds I don't need, but could be a useful optional field.

tmorehouse avatar Apr 30 '14 22:04 tmorehouse

Maybe @eternicode will answer only after successful completion of tests?

korun avatar May 14 '14 07:05 korun

@korun and @rchavik Thank you for your code and time picker. From all the available forks, this one looked the best and actually worked. I also made few improvements in my fork (i forked from @rchavik) regarding to add-timepicker branch and made a full request. I also have few bugfixes ready that are related to master branch not timepicker. Since it doesn't look like @eternicode will answer i decided to merge this branch time-picker into master and i will continue some fixes there if anyone is interested. https://github.com/darklow/bootstrap-datepicker

darklow avatar Oct 03 '14 12:10 darklow

@rchavik @darklow First off , this is by far the most simple and easy to use time picker! Great job... I think I have found a bug in this fork regarding UTC time parsing but I'm not sure how to fix it yet.

The bug goes like this.

I'm in gmt+2 time zone and I set the date time picker with a date string like this:

$('#end-date').datepicker('update', '27/12/2014 23:59');

When I open the datepicker and I try to select a day back (the 26th) I can't because of the following line:

this._setDate(UTCDate(year, month, day, h, m, s));

year = 2014 , month = 11, day = 26 , h = 23 , m = 59 , s = 0 UTCDate(year, month, day, h, m, s) = Fri Dec 27 2013 01:59:00 GMT+020

the result is that nothing changes...

I tried playing with the date changing the timezone offset and what not without luck.

Any ideas?

guypaskar avatar Dec 15 '14 09:12 guypaskar

I created issue for this, thanks @guypaskar.

korun avatar Dec 15 '14 12:12 korun

@korun Thanks.

Have you also confirmed the bug?

guypaskar avatar Dec 15 '14 12:12 guypaskar

@korun is there a reason why you created an issue in your own fork and not in this issue tracker?

acrobat avatar Dec 15 '14 12:12 acrobat

@korun is there a reason why you created an issue in your own fork and not in this issue tracker?

@acrobat, I create issue in fork because I don't know will be this PR merged in original repo, or not.

korun avatar Dec 15 '14 12:12 korun

@korun oh ok. But this PR is planned for the 1.4.0 release, which is the next release after 1.3.1. And the 1.3.1 release will be ready and released around the end of this week i think. Then we start working on 1.4.0!

acrobat avatar Dec 15 '14 12:12 acrobat

Have you also confirmed the bug?

@guypaskar, I can't repeat this behavior yet. My results are very strange:

$('#q_occurred_at_lteq').datepicker('update', '27.12.2014 23:59');
// picker was set to "12/15/2014", ignore my format "dd.mm.yyyy"

I'll try something else later.

@acrobat, good news! :smiley: I'll try add some more tests, and, maybe, options on this weekend. I think it makes sense to create issue right here only after this PR has been accepted.

korun avatar Dec 15 '14 13:12 korun

@korun great! Maybe a good option to add is that the seconds picker is an optional field, but I will review still whole pull request soon!

acrobat avatar Dec 15 '14 13:12 acrobat

@korun did you manage to reproduce the bug?

guypaskar avatar Dec 17 '14 10:12 guypaskar

@korun did you manage to reproduce the bug?

@guypaskar, not yet, too busy now. I think I can do this at weekend.

korun avatar Dec 17 '14 10:12 korun

Cool. Thanks.

guypaskar avatar Dec 17 '14 10:12 guypaskar

@guypaskar I can reproduce bug, but I have no idea how to fix it right now. :(

korun avatar Dec 20 '14 18:12 korun

Ok. I found the issue. it's in the function contains of DateArray.

contains: function(d, ignoreTime){ // Array.indexOf is not cross-browser; // $.inArray doesn't work with Dates var val = d && d.valueOf(); ignoreTime = typeof(ignoreTime) === 'undefined';

            if (ignoreTime) {
                val = d.getFullYear().toString() + d.getMonth() + d.getDate();
            }
            for (var i=0, l=this.length; i < l; i++)
                if (ignoreTime) {
                    var t = this[i].getUTCFullYear().toString() + this[i].getUTCMonth() + this[i].getUTCDate();
                    if (t === val) {
                        return i;
                    }
                } else {
                    if (this[i].valueOf() === val)
                        return i;
                }
            return -1;
        },

it returns 0 even though the date is not found in this.dates. since

val = d.getFullYear().toString() + d.getMonth() + d.getDate(); and var t = this[i].getUTCFullYear().toString() + this[i].getUTCMonth() + this[i].getUTCDate();

one is UTC and one is not then it returns the same date for some hours selection. I think that the ignoreTime is there to solve it but no one is calling it with ignore time = false....

What do you think?

guypaskar avatar Dec 22 '14 14:12 guypaskar

@acrobat I see this is no longer on the 1.5.0 milestone. Do you need anything else to help land this?

Hoverbear avatar Apr 22 '15 18:04 Hoverbear

This would be a nice feature to have

russplaysguitar avatar May 13 '15 16:05 russplaysguitar

Yes indeed, I just think this PR needs some more fine tuining. For example the option to disabled/hide seconds

And we should check if @guypaskar's problem is solved

acrobat avatar May 13 '15 20:05 acrobat

@russplaysguitar I found this fork and am currently testing it out: http://www.malot.fr/bootstrap-datetimepicker/

nhouse avatar May 14 '15 19:05 nhouse

can we have this pulled into main repo please?

simplenotezy avatar Dec 23 '15 21:12 simplenotezy

I tried pulling in latest commit using:

"bootstrap-datepicker": "[email protected]:rchavik/bootstrap-datepicker.git#5d82d35f54c25b8cebda0c0f7493a39a80f1c4e8",

However the datetimepicker does not have a time field, even though i copied your example in first post. When I click at a date, it populates the input field like this:

2015-12-18 H:i:s

What am I doing wrong?

@rchavik

simplenotezy avatar Dec 23 '15 21:12 simplenotezy

It seems the latest commit / version does not contain any dist files other than:

dist/css/bootstrap-datepicker.standalone.css

The JS is missing from dist.

If I use this:

js/bootstrap-datepicker.js
dist/css/bootstrap-datepicker.standalone.css

Instead of:

dist/js/bootstrap-datepicker.min.js
dist/css/bootstrap-datepicker3.min.css

It works

simplenotezy avatar Dec 23 '15 21:12 simplenotezy

Also when changing the dates, the "time" is lost.

I am using commit:

5d82d35f54c25b8cebda0c0f7493a39a80f1c4e8

simplenotezy avatar Dec 23 '15 21:12 simplenotezy

Time support is something we would like to add in 2.0+

acrobat avatar Dec 24 '15 10:12 acrobat

I am still in need of the timepicker. I just have to use another library because of timepicker requirement.

Otherwise, I have all the options toDisplay toValue which I need in this library

deepakmahakale avatar Jul 21 '21 13:07 deepakmahakale