Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

greeter.tsx fixes #44

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/greeter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export const getGreeting = (greetings: Array<IGreetingProps>): string => {
export const getExtension = (day: number) => {
let extension = "th";

if (day % 10 === 1) {
if (day % 10 === 1 && day !== 11) {
extension = "st";
} else if (day % 10 === 2) {
} else if (day % 10 === 2 && day !== 12) {
extension = "nd";
} else if (day % 10 === 3) {
} else if (day % 10 === 3 && day !== 13) {
extension = "rd";
}

Expand All @@ -93,9 +93,9 @@ export const getDateString = (
) => {
let currentDate = new Date();

let weekday = weekdays[currentDate.getUTCDay()];
let weekday = weekdays[currentDate.getDay()];
let day = currentDate.getDate();
let month = months[currentDate.getUTCMonth()];
let month = months[currentDate.getMonth()];
let extension = getExtension(day);
let year = currentDate.getFullYear();

Expand Down
27 changes: 27 additions & 0 deletions src/test/components/greeter.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,34 @@ it("getExtension test", () => {
expect(getExtension(1)).toEqual("st");
expect(getExtension(2)).toEqual("nd");
expect(getExtension(3)).toEqual("rd");
expect(getExtension(4)).toEqual("th");
expect(getExtension(5)).toEqual("th");
expect(getExtension(6)).toEqual("th");
expect(getExtension(7)).toEqual("th");
expect(getExtension(8)).toEqual("th");
expect(getExtension(9)).toEqual("th");
expect(getExtension(10)).toEqual("th");
expect(getExtension(11)).toEqual("th");
expect(getExtension(12)).toEqual("th");
expect(getExtension(13)).toEqual("th");
expect(getExtension(14)).toEqual("th");
expect(getExtension(15)).toEqual("th");
expect(getExtension(16)).toEqual("th");
expect(getExtension(17)).toEqual("th");
expect(getExtension(18)).toEqual("th");
expect(getExtension(19)).toEqual("th");
expect(getExtension(20)).toEqual("th");
expect(getExtension(21)).toEqual("st");
expect(getExtension(22)).toEqual("nd");
expect(getExtension(23)).toEqual("rd");
expect(getExtension(24)).toEqual("th");
expect(getExtension(25)).toEqual("th");
expect(getExtension(26)).toEqual("th");
expect(getExtension(27)).toEqual("th");
expect(getExtension(28)).toEqual("th");
expect(getExtension(29)).toEqual("th");
expect(getExtension(30)).toEqual("th");
expect(getExtension(31)).toEqual("st");
});

it("Greeter snapshot test", () => {
Expand Down