Skip to content
Snippets Groups Projects
Commit 7fe4837e authored by Giildo's avatar Giildo
Browse files

:recycle:️ Can use date with a + symbol for positiv year

parent d2e26160
Branches
Tags 1.1.5-sr3
No related merge requests found
Pipeline #262183 passed with stage
in 14 seconds
......@@ -40,7 +40,7 @@ export class Day implements DayInterface {
}
if (typeof data === 'string') {
if (/^-?\d+-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}/.test(data)) {
if (/^[-+]?\d+-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}/.test(data)) {
const {
year,
month,
......@@ -49,7 +49,7 @@ export class Day implements DayInterface {
minute,
second,
millisecond,
} = /^(?<year>-?\d+)-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2}).(?<millisecond>\d{3})/.exec(data)!.groups!
} = /^(?<year>[-+]?\d+)-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2}).(?<millisecond>\d{3})/.exec(data)!.groups!
this.#Y = parseInt(year)
this.#M = parseInt(month)
this.#D = parseInt(day)
......@@ -60,7 +60,7 @@ export class Day implements DayInterface {
return
}
if (/^-?\d+-\d{2}-\d{2}$/.test(data)) {
if (/^[-+]?\d+-\d{2}-\d{2}$/.test(data)) {
const [year, month, day] = /^(-?\d{4})-(\d{2})-(\d{2})/.exec(data)!.slice(1)
this.#Y = parseInt(year)
this.#M = parseInt(month)
......@@ -68,7 +68,7 @@ export class Day implements DayInterface {
return
}
if (/^-?\d+\/\d{2}\/-?\d{2}$/.test(data)) {
if (/^[-+]?\d+\/\d{2}\/-?\d{2}$/.test(data)) {
const [year, month, day] = data.split('/')
this.#Y = parseInt(year)
this.#M = parseInt(month)
......@@ -125,7 +125,7 @@ export class Day implements DayInterface {
static utc(data: string): Day {
if (!data) throw new Error('Date is required')
if (!/^(-?\d+)-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})/.test(data)) {
if (!/^([-+]?\d+)-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})/.test(data)) {
throw new Error(`Invalid date format. Use "YYYY-MM-DDTHH:MM:SS.SSSZ", data received: ${data}`)
}
......@@ -138,7 +138,7 @@ export class Day implements DayInterface {
minute,
second,
millisecond,
] = /^(-?\d+)-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})/.exec(data)!
] = /^([-+]?\d+)-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})/.exec(data)!
return new Day({
year: parseInt(year),
month: parseInt(month),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment