Skip to content

Commit

Permalink
Merge pull request #35149 from dimagi/jt/ui-12-hour-time-bug
Browse files Browse the repository at this point in the history
Bug Fix - now() time showing PM when it should be AM
  • Loading branch information
Jtang-1 authored Oct 2, 2024
2 parents 20abb0f + 1ebd4c3 commit 8a2e7b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ hqDefine("cloudcare/js/form_entry/entries", [
this.templateType = 'time';
if (question.style) {
if (question.stylesContains(constants.TIME_12_HOUR)) {
this.clientFormat = 'h:mm T';
this.clientFormat = 'h:mm A';
}
}
DateTimeEntryBase.call(this, question, options);
Expand Down
7 changes: 4 additions & 3 deletions corehq/apps/cloudcare/static/cloudcare/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ hqDefine('cloudcare/js/utils', [
// TD does have a plugin to integrate with moment, but since other usages of TD in HQ
// don't need it, instead of enabling that, hack around this.
const _momentFormatToTempusFormat = function (momentFormat) {
return momentFormat.replaceAll("D", "d").replaceAll("Y", "y");
return momentFormat.replaceAll("D", "d").replaceAll("Y", "y").replaceAll("A", "T");
};

/** Coerce an input date string to a moment object */
Expand Down Expand Up @@ -393,6 +393,7 @@ hqDefine('cloudcare/js/utils', [
}

let date = moment(selectedTime, timeFormat);
const tempusTimeFormat = _momentFormatToTempusFormat(timeFormat);
let options = {
display: {
buttons: {
Expand All @@ -401,8 +402,8 @@ hqDefine('cloudcare/js/utils', [
},
},
localization: {
format: timeFormat,
hourCycle: timeFormat.indexOf('T') === -1 ? 'h23' : 'h12',
format: tempusTimeFormat,
hourCycle: tempusTimeFormat.indexOf('T') === -1 ? 'h23' : 'h12',
},
useCurrent: true,
};
Expand Down

0 comments on commit 8a2e7b7

Please sign in to comment.