简体   繁体   English

日期范围选取器(Bootstrap的JavaScript组件)在特定日期选择错误的日期

[英]Date Range Picker (JavaScript Component for Bootstrap) picks the wrong date on specific day

Currently I have been working with code which I am not the author and the user spotted a very specific problem I couldn't find an answer to at all. 目前我一直在使用代码,我不是作者,用户发现了一个非常具体的问题,我根本找不到答案。

The page in question uses the Date Range Picker component to pick two dates (start and end). 有问题的页面使用日期范围选取器组件来选择两个日期(开始和结束)。

Whenever someone clicks specifically on the day 16/10/2016 it is automatically shifted to 17/10/2016 . 每当有人在当天专门点击16/10/2016自动过渡到17/10/2016

This was tested in multiple computers and browsers to no effect, I couldn't trace down the issue with the debugger either. 这在多台计算机和浏览器中测试无效,我无法用调试器追查问题。

Any other day, of any month, on any year, returns no problem at all. 任何一天,任何一个月,任何一年,都没有任何问题。 It only happens on the day 16/10/2016 , and only if that date is the End date, it can be the Start date with no issues. 它仅发生在16/10/2016年10月16日,并且只有当该日期是结束日期时,它才可以是没有问题的开始日期。

The current version: 2.1.24 当前版本:2.1.24

Here is the code used: 这是使用的代码:

<section class="col-md-4"> <!-- Selecionar Datas-->
    <div class="form-group has-feedback has-feedback-right">
        <input type="hidden" id="dt_inicio_afastamento">
        <input type="hidden" id="dt_fim_afastamento">
        <label class="control-label">Escolha o intervalo de datas</label>
        <i class="form-control-feedback glyphicon glyphicon-calendar"></i>
        <input id="escolhe_data" name="escolhe_data" class="input-mini form-control" type="text">
    </div>
</section>

And the Script: 和脚本:

    $('input[name="escolhe_data"]').daterangepicker({
        showDropdowns: true,
        autoApply: true,
        autoUpdateInput: true,
        locale: {
            "format": "DD/MM/YYYY",
            "separator": " - ",
            "applyLabel": "Aplicar",
            "cancelLabel": "Cancelar",
            "fromLabel": "De",
            "toLabel": "Até",
            "customRangeLabel": "Outro",
            "weekLabel": "S",
            "daysOfWeek": ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"],
            "monthNames": ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" ],
            "firstDay": 1
        },
        alwaysShowCalendars: true
    },
    function(start, end, label) {
      //console.log($('#escolhe_data').data());

    });

    $('#escolhe_data').on('apply.daterangepicker', function(ev, picker) {
        $('#dt_inicio_afastamento').val(picker.startDate.format('YYYY-MM-DD'));
        $('#dt_fim_afastamento').val(picker.endDate.format('YYYY-MM-DD'));
    });

Based on the links posted by chiliNUT I was able to pinpoint the problem. 根据chiliNUT发布的链接,我能够找出问题所在。 It was related to the end of daylight savings. 这与夏令时的结束有关。 Having the user select the hour as well fixed the issue. 让用户选择小时也解决问题。 This can be done using the option "timePicker": true in the $().daterangepicker({ }) configuration. 这可以使用选项"timePicker": true $().daterangepicker({ })配置中的"timePicker": true来完成。

Thanks chiliNUT and everyone that helped! 谢谢辣椒和所有帮助过的人!

Going to add to this..in case it helps but i did +1 the OP answer. 要添加到这个..如果它有帮助,但我做了OP答案。

Here is some other features you can add as well. 您还可以添加其他一些功能。 That does not use autoupdate and time zone will not affect it even if wrongly set. 这不使用自动更新,即使设置错误,时区也不会影响它。

$(function() {
    $('input[name="escolhe_data"]').daterangepicker({
        timePicker: true,
        timePickerIncrement: 30,
        locale: {
            format: 'MM/DD/YYYY h:mm A'
        },
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    });

    $(window).scroll(function() {
        if ($('input[name="daterange"]').length) {
            $('input[name="daterange"]').daterangepicker("close");
      }
    });
});

DEMO: https://jsfiddle.net/norcaljohnny/kensoubf/ 演示: https//jsfiddle.net/norcaljohnny/kensoubf/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM