Skip to content
Snippets Groups Projects
Commit 412c1153 authored by Shuai Lin's avatar Shuai Lin Committed by Paul Rosenzweig
Browse files

Fix sqlite3 year (#11662)

parent 98a4197b
Branches
Tags
No related merge requests found
......@@ -47,7 +47,7 @@ export function parseTimestamp(value, unit) {
return value;
} else if (typeof value === "string" && /(Z|[+-]\d\d:?\d\d)$/.test(value)) {
return moment.parseZone(value);
} else if (unit in NUMERIC_UNIT_FORMATS) {
} else if (unit in NUMERIC_UNIT_FORMATS && typeof value == "number") {
return NUMERIC_UNIT_FORMATS[unit](value);
} else {
return moment.utc(value);
......
......@@ -9,6 +9,7 @@ describe("time", () => {
const TEST_CASES = [
["2015-01-01T00:00:00.000Z", 0, NY15_UTC],
["2015-01-01", 0, NY15_UTC],
["2015-01-01T00:00:00.000+00:00", 0, NY15_UTC],
["2015-01-01T00:00:00.000+0000", 0, NY15_UTC],
["2015-01-01T00:00:00Z", 0, NY15_UTC],
......@@ -27,9 +28,9 @@ describe("time", () => {
TEST_CASES.map(([str, expectedOffset, expectedMoment]) => {
it(
str +
" should be parsed as moment reprsenting" +
" should be parsed as moment reprsenting " +
expectedMoment +
"with the offset " +
" with the offset " +
expectedOffset,
() => {
const result = parseTimestamp(str);
......@@ -40,6 +41,13 @@ describe("time", () => {
},
);
});
// See https://github.com/metabase/metabase/issues/11615
it("parse sqlite date with unit=year correctly", () => {
const result = parseTimestamp("2015-01-01", "year");
expect(moment.isMoment(result)).toBe(true);
expect(result.unix()).toEqual(NY15_UTC.unix());
});
});
describe("parseTime", () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment