Skip to content
Snippets Groups Projects
Unverified Commit a32e6a4e authored by Paul Rosenzweig's avatar Paul Rosenzweig Committed by GitHub
Browse files

show am/pm if locale uses 12-hour clock (#11049)

parent c0c74dba
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,13 @@ export function setLocalization(translationsObject) { ...@@ -25,6 +25,13 @@ export function setLocalization(translationsObject) {
moment.locale(locale); moment.locale(locale);
} }
// Format a fixed timestamp in local time to see if the current locale defaults
// to using a 24 hour clock.
export function isLocale24Hour() {
const formattedTime = moment("2000-01-01T13:00:00").format("LT");
return /^13:/.test(formattedTime);
}
// we delete msgid property since it's redundant, but have to add it back in to // we delete msgid property since it's redundant, but have to add it back in to
// make ttag happy // make ttag happy
function addMsgIds(translationsObject) { function addMsgIds(translationsObject) {
......
...@@ -2,6 +2,7 @@ import React from "react"; ...@@ -2,6 +2,7 @@ import React from "react";
import NumericInput from "metabase/components/NumericInput"; import NumericInput from "metabase/components/NumericInput";
import Icon from "metabase/components/Icon"; import Icon from "metabase/components/Icon";
import { isLocale24Hour } from "metabase/lib/i18n";
import cx from "classnames"; import cx from "classnames";
import moment from "moment"; import moment from "moment";
...@@ -12,7 +13,7 @@ const HoursMinutesInput = ({ ...@@ -12,7 +13,7 @@ const HoursMinutesInput = ({
onChangeHours, onChangeHours,
onChangeMinutes, onChangeMinutes,
onClear, onClear,
is24HourMode = false, is24HourMode = isLocale24Hour(),
}) => ( }) => (
<div className="flex align-center"> <div className="flex align-center">
<NumericInput <NumericInput
......
import moment from "moment";
import { isLocale24Hour } from "metabase/lib/i18n";
describe("isLocale24Hour", () => {
const testCases = [
["en", false],
["en-us", false],
["en-gb", true],
["fr", true],
["zh-cn", true],
];
for (const [locale, is24] of testCases) {
it(`should return ${is24} for '${locale}'`, () => {
// save locale before changing it
const startingLocale = moment.locale();
moment.locale(locale);
expect(isLocale24Hour()).toBe(is24);
// reset locale
moment.locale(startingLocale);
});
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment