Skip to content

Commit

Permalink
Fix sqlite3 year (metabase#11662) (metabase#11689)
Browse files Browse the repository at this point in the history
(cherry picked from commit 412c115)

Co-authored-by: Shuai Lin <[email protected]>
  • Loading branch information
2 people authored and tlrobinson committed Jan 13, 2020
1 parent d8caaca commit b912570
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/src/metabase/lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions frontend/test/metabase/lib/time.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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);
Expand All @@ -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", () => {
Expand Down

0 comments on commit b912570

Please sign in to comment.