Skip to content

Format "m/d/Y h:i a" changes hour onBlur #596

@Sparkmasterflex

Description

@Sparkmasterflex

I've recently upgraded to v2.5.4 and am now using the npm package and a strange bug has popped up that I cannot find any reason for. When the user selects a time and date the plugin populates the proper time/date in the input but when they click outside that input the time changes to an hour earlier.

I've changed the format to have no space between the time and the "AM" or "PM" and instead of changing the hour it changes from "PM" to "AM", every time.

Here's the code:

$('input.select-datetime').datetimepicker({
  format: "m/d/Y h:i a",
  formatTime: 'h:i a',
  formatDate: 'm/d/Y',
  step: 15,
  style: "min-width: 310px",
  onShow: function(current, $input) {
    var arr, date, options;
    if ($input.data('year') != null) {
      options = {};
      arr = $input.data('date').split('-');
      date = (arr[0] + "/" + (arr[1] - 1)) || "12/01";
      if ($input.data('year').min != null) {
        $.extend(options, {
          minDate: "-" + (1970 - $input.data('year').min) + "/" + date
        });
      }
      if ($input.data('year').max != null) {
        $.extend(options, {
          maxDate: "+" + (1970 + $input.data('year').max) + "/" + date
        });
      }
      return this.setOptions(options);
    }
  }
});

I've tried taking out the onShow and changing the formatTime/Date. The only thing that works is taking out the format option but this uses/inserts European format which does not work for my situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions