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

Added the nonMilitaryTime format support with a new format #243

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions js/foundation-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,17 @@
if(this.nonMilitaryTime){
if (target.text().indexOf("AM") >= 0){
hours = parseInt(target.text(), 10) || 0;
if (hours == 12)
{
hours = 0;
}
}
else{
hours = (parseInt(target.text(), 10) + 12 || 0);
hours = (parseInt(target.text(), 10) || 0);
if (hours < 12)
{
hours = hours + 12;
}
}
}
else{
Expand Down Expand Up @@ -1222,7 +1230,7 @@
getDaysInMonth: function(year, month) {
return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
},
validParts: /hh?|ii?|ss?|dd?|mm?|MM?|yy(?:yy)?/g,
validParts: /HH?|hh?|ii?|ss?|dd?|mm?|MM?|yy(?:yy)?|tt?/g,
nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
parseFormat: function(format) {
// IE treats \0 as a string end in inputs (truncating the value),
Expand Down Expand Up @@ -1359,17 +1367,20 @@
return '';
}
var val = {
h: date.getUTCHours(),
H: date.getUTCHours(),
h: date.getUTCHours() % 12,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbellet You will want to check date.getUTCHours == 0 this indicates 12:00 AM. right now when you select 12:00 am it displays as 00:00 AM.

Possible solution is:
h: (date.getUTCHours() == 0) ? 12 : date.getUTCHours() % 12

i: date.getUTCMinutes(),
s: date.getUTCSeconds(),
d: date.getUTCDate(),
m: date.getUTCMonth() + 1,
M: dates[language].monthsShort[date.getUTCMonth()],
MM: dates[language].months[date.getUTCMonth()],
yy: date.getUTCFullYear().toString().substring(2),
yyyy: date.getUTCFullYear()
yyyy: date.getUTCFullYear(),
tt: (date.getUTCHours() >= 12 && date.getUTCHours() <= 23) ? "PM" : "AM"
};
val.hh = (val.h < 10 ? '0' : '') + val.h;
val.HH = (val.H < 10 ? '0' : '') + val.H;
val.ii = (val.i < 10 ? '0' : '') + val.i;
val.ss = (val.s < 10 ? '0' : '') + val.s;
val.dd = (val.d < 10 ? '0' : '') + val.d;
Expand Down
Loading