Skip to content

Commit

Permalink
Fix @ now getting overriden by timezone (#6581)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde authored Feb 4, 2025
1 parent 8e4e9bf commit ff0a8c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ let ParserRules = [
{"name": "grain_and_at_part", "symbols": [{"literal":"@"}, "_", "at_modifiers"], "postprocess": ([, , modifier]) => ({ modifier })},
{"name": "range_grain_modifier", "symbols": ["grain"], "postprocess": ([grain]) => ({ grain, isComplete: false })},
{"name": "range_grain_modifier", "symbols": [{"literal":"|"}, "_", "grain", "_", {"literal":"|"}], "postprocess": ([, ,grain]) => ({ grain, isComplete: true })},
{"name": "at_modifiers", "symbols": ["grain_modifier"], "postprocess": ([grain]) => ({ at: RillTimeAnchor.relative(grain) })},
{"name": "at_modifiers", "symbols": ["time_anchor_offset"], "postprocess": ([grain]) => ({ at: grain })},
{"name": "at_modifiers", "symbols": ["timezone_modifier"], "postprocess": ([timeZone]) => ({ timeZone })},
{"name": "at_modifiers", "symbols": ["grain_modifier", "_", "timezone_modifier"], "postprocess": ([grain, , timeZone]) => ({ at: RillTimeAnchor.relative(grain), timeZone })},
{"name": "at_modifiers", "symbols": ["time_anchor_offset", "_", "timezone_modifier"], "postprocess": ([grain, , timeZone]) => ({ at: grain, timeZone })},
{"name": "grain_modifier", "symbols": ["grain"], "postprocess": ([grain]) => ({ count: 0, grain })},
{"name": "grain_modifier", "symbols": ["int", "grain"], "postprocess": ([count, grain]) => ({ count, grain })},
{"name": "abs_time", "symbols": [/[\d]/, /[\d]/, /[\d]/, /[\d]/, /[\-]/, /[\d]/, /[\d]/, /[\-]/, /[\d]/, /[\d]/, "_", /[\d]/, /[\d]/, /[:]/, /[\d]/, /[\d]/], "postprocess": (args) => args.join("")},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ grain_and_at_part => ":" _ range_grain_modifier _ "@" _ at_modifiers {% ([, , gr
range_grain_modifier => grain {% ([grain]) => ({ grain, isComplete: false }) %}
| "|" _ grain _ "|" {% ([, ,grain]) => ({ grain, isComplete: true }) %}

at_modifiers => grain_modifier {% ([grain]) => ({ at: RillTimeAnchor.relative(grain) }) %}
| timezone_modifier {% ([timeZone]) => ({ timeZone }) %}
| grain_modifier _ timezone_modifier {% ([grain, , timeZone]) => ({ at: RillTimeAnchor.relative(grain), timeZone }) %}
at_modifiers => time_anchor_offset {% ([grain]) => ({ at: grain }) %}
| timezone_modifier {% ([timeZone]) => ({ timeZone }) %}
| time_anchor_offset _ timezone_modifier {% ([grain, , timeZone]) => ({ at: grain, timeZone }) %}

grain_modifier => grain {% ([grain]) => ({ count: 0, grain }) %}
| int grain {% ([count, grain]) => ({ count, grain }) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,21 @@ describe("rill time", () => {
});
}
});

describe("Update timezone", () => {
const Cases: [rillTime: string, timezone: string, replaced: string][] = [
["-6d, latest : |h|", "UTC", "-6d,latest:|h|@{UTC}"],
["-6d, latest : |h| @ {IST}", "UTC", "-6d,latest:|h|@{UTC}"],
["-6d, latest : |h| @ now", "UTC", "-6d,latest:|h|@now {UTC}"],
["-6d, latest : |h| @ now {IST}", "UTC", "-6d,latest:|h|@now {UTC}"],
];

for (const [rillTime, timezone, replaced] of Cases) {
it(`'${rillTime}'.addTimezone(${timezone})=${replaced}`, () => {
const rt = parseRillTime(rillTime);
rt.addTimezone(timezone);
expect(rt.toString()).toEqual(replaced);
});
}
});
});

0 comments on commit ff0a8c7

Please sign in to comment.