Skip to content

"Now" Button returning 'pm' in the 'am', in 12 hour format #396

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

Open
ncramer opened this issue Jul 28, 2012 · 4 comments
Open

"Now" Button returning 'pm' in the 'am', in 12 hour format #396

ncramer opened this issue Jul 28, 2012 · 4 comments

Comments

@ncramer
Copy link

ncramer commented Jul 28, 2012

Example:

At 1:40AM click the Now button in example 2 - http://trentrichardson.com/examples/timepicker/
"Show time in AM/PM 12 hour format"
$('#example2').datetimepicker({ampm: true});

Expected result:
07/28/2012 01:40 am
Actual result:
07/28/2012 01:40 pm

Issue:

Default time format for ampm is hh::ss tt (lowercase am/pm)

But, at line 973 we state:
ampm = $.inArray(treg[order.t], o.amNames) !== -1 ? 'AM' : 'PM';

And the default regional codes fo are caps:
amNames: ['AM', 'A'],
pmNames: ['PM', 'P'],

So since 'am' is not in ['AM', 'A'], PM is always returned

At a minimum I would make the defaults consistent. Better, I'd compare in a case-insensitive manner or use the value directly.

justinvp added a commit to justinvp/jQuery-Timepicker-Addon that referenced this issue Jul 28, 2012
Fixes trentrichardson#396 by comparing in a case-insensitive manner.
@jlbriggs
Copy link

The input field is populated with the correct am/pm designation, but the picker itself still displays 'pm' when you use the 'now' option.

@jlbriggs
Copy link

I take that back...it does not populate correctly.
Does anyone have a solution to the 'now' button always jumping to PM?
Any help would be appreciated.

@ncramer
Copy link
Author

ncramer commented Aug 27, 2012

Several different quick solutions that may work and don't require a ton of code review, not familiar enough with the full codebase to confirm there are no unintended consequences:

  1. Add 'a', 'am' to amNames and 'p', 'pm' to pmNames?
  2. strtoupper treg[order.t] at line 973 so that it will match case w/ the existing default values
    ampm = $.inArray(treg[order.t], o.amNames) !== -1 ? 'AM' : 'PM';
  3. In the same line as line above, simply output treg[order.t] instead of doing a comparison and conditionally displaying a static 'AM' or 'PM'.

I don't know that any of these are "right" but hopefully will point you in the right direction.

@jlbriggs
Copy link

  1. Add 'a', 'am' to amNames and 'p', 'pm' to pmNames?

that worked for me. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants