-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(date): move non-validation funcs to util, add tests
- Loading branch information
Showing
13 changed files
with
99 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/flows/beratungshilfeFormular/anwaltlicheVertretung/guards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/services/pdf/beratungshilfe/sections/__test__/footer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
addDays, | ||
addYears, | ||
dateUTCFromGermanDateString, | ||
toGermanDateFormat, | ||
today, | ||
} from "../date"; | ||
|
||
describe("date", () => { | ||
describe("today()", () => { | ||
it("should return an instance of Date", () => { | ||
expect(today()).toBeInstanceOf(Date); | ||
}); | ||
}); | ||
|
||
describe("toGermanDateFormat()", () => { | ||
it("formats correctly", () => { | ||
expect(toGermanDateFormat(new Date("2000-01-01"))).toEqual("01.01.2000"); | ||
}); | ||
}); | ||
|
||
describe("dateUTCFromGermanDateString()", () => { | ||
it("parses correctly", () => { | ||
expect(dateUTCFromGermanDateString("01.01.2000")).toEqual( | ||
new Date("2000-01-01"), | ||
); | ||
}); | ||
}); | ||
|
||
describe("addDays()", () => { | ||
it("adds and subtracts correctly", () => { | ||
expect(addDays(new Date("2000-01-01"), 1)).toEqual( | ||
new Date("2000-01-02"), | ||
); | ||
|
||
expect(addDays(new Date("2000-01-01"), -1)).toEqual( | ||
new Date("1999-12-31"), | ||
); | ||
}); | ||
}); | ||
|
||
describe("addYears()", () => { | ||
it("adds and subtracts correctly", () => { | ||
expect(addYears(new Date("2000-01-01"), 1)).toEqual( | ||
new Date("2001-01-01"), | ||
); | ||
|
||
expect(addYears(new Date("2000-01-01"), -1)).toEqual( | ||
new Date("1999-01-01"), | ||
); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export function addDays(date: Date, days: number) { | ||
const result = new Date(date); | ||
result.setDate(result.getDate() + days); | ||
return result; | ||
} | ||
|
||
export function addYears(date: Date, years: number) { | ||
const result = new Date(date); | ||
result.setFullYear(result.getFullYear() + years); | ||
return result; | ||
} | ||
|
||
export function today() { | ||
const today = new Date(); | ||
return new Date( | ||
Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate()), | ||
); | ||
} | ||
|
||
export function dateUTCFromGermanDateString(date: string) { | ||
const [day, month, year] = date.split("."); | ||
return new Date(Date.UTC(Number(year), Number(month) - 1, Number(day))); | ||
} | ||
|
||
export const toGermanDateFormat = (date: Date) => { | ||
return date.toLocaleDateString("de", { | ||
day: "2-digit", | ||
month: "2-digit", | ||
year: "numeric", | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters