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

[i18n] fix masculine and feminine forms of the weekdays in PT #326

Merged
merged 1 commit into from
Oct 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/expressionDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ export class ExpressionDescriptor {
let format: string | null = null;
if (s.indexOf("#") > -1) {
let dayOfWeekOfMonthNumber: string = s.substring(s.indexOf("#") + 1);
format = this.i18n.commaOnThe(dayOfWeekOfMonthNumber).trim() + this.i18n.spaceX0OfTheMonth();
let dayOfWeek = s.substring(0, s.indexOf("#"));
format = this.i18n.commaOnThe(dayOfWeekOfMonthNumber, dayOfWeek).trim() + this.i18n.spaceX0OfTheMonth();
} else if (s.indexOf("L") > -1) {
format = this.i18n.commaOnTheLastX0OfTheMonth(s.replace("L", ""));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Locale {
third(s?: string): string;
fourth(s?: string): string;
fifth(s?: string): string;
commaOnThe(s?: string): string;
commaOnThe(s?: string, day?: string): string;
spaceX0OfTheMonth(): string;
lastDay(): string;
commaOnTheLastX0OfTheMonth(s?: string): string;
Expand Down
24 changes: 12 additions & 12 deletions src/i18n/locales/pt_BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class pt_BR implements Locale {
commaAndOnX0() {
return ", e de %s";
}
commaOnThe() {
return ", na ";
commaOnThe(s?: string, day?: string) {
return day === '6' || day === '0' ? ", no" : ", na ";
}
commaOnTheLastDayOfTheMonth() {
return ", no último dia do mês";
Expand Down Expand Up @@ -110,23 +110,23 @@ export class pt_BR implements Locale {
everyX0Seconds() {
return "a cada %s segundos";
}
fifth() {
return "quinta";
fifth(s?: string) {
return s === '6' || s === '0' ? "quinto" : "quinta";
}
first() {
return "primeira";
first(s?: string) {
return s === '6' || s === '0' ? "primeiro" : "primeira";
}
firstWeekday() {
return "primeiro dia da semana";
}
fourth() {
return "quarta";
fourth(s?: string) {
return s === '6' || s === '0' ? "quarto" : "quarta";
}
minutesX0ThroughX1PastTheHour() {
return "do minuto %s até %s de cada hora";
}
second() {
return "segunda";
second(s?: string) {
return s === '6' || s === '0' ? "segundo" : "segunda";
}
secondsX0ThroughX1PastTheMinute() {
return "No segundo %s até %s de cada minuto";
Expand All @@ -140,8 +140,8 @@ export class pt_BR implements Locale {
lastDay() {
return "o último dia";
}
third() {
return "terceira";
third(s?: string) {
return s === '6' || s === '0' ? "terceiro" : "terceira";
}
weekdayNearestDayX0() {
return "dia da semana mais próximo do dia %s";
Expand Down
24 changes: 12 additions & 12 deletions src/i18n/locales/pt_PT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class pt_PT implements Locale {
commaAndOnX0() {
return ", e de %s";
}
commaOnThe() {
return ", na ";
commaOnThe(s?: string, day?: string) {
return day === '6' || day === '0' ? ", no" : ", na ";
}
commaOnTheLastDayOfTheMonth() {
return ", no último dia do mês";
Expand Down Expand Up @@ -110,23 +110,23 @@ export class pt_PT implements Locale {
everyX0Seconds() {
return "a cada %s segundos";
}
fifth() {
return "quinta";
fifth(s?: string) {
return s === '6' || s === '0' ? "quinto" : "quinta";
}
first() {
return "primeira";
first(s?: string) {
return s === '6' || s === '0' ? "primeiro" : "primeira";
}
firstWeekday() {
return "primeiro dia da semana";
}
fourth() {
return "quarta";
fourth(s?: string) {
return s === '6' || s === '0' ? "quarto" : "quarta";
}
minutesX0ThroughX1PastTheHour() {
return "do minuto %s até %s de cada hora";
}
second() {
return "segunda";
second(s?: string) {
return s === '6' || s === '0' ? "segundo" : "segunda";
}
secondsX0ThroughX1PastTheMinute() {
return "No segundo %s até %s de cada minuto";
Expand All @@ -140,8 +140,8 @@ export class pt_PT implements Locale {
lastDay() {
return "o último dia";
}
third() {
return "terceira";
third(s?: string) {
return s === '6' || s === '0' ? "terceiro" : "terceira";
}
weekdayNearestDayX0() {
return "dia da semana mais próximo do dia %s";
Expand Down
43 changes: 43 additions & 0 deletions test/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,27 @@ describe("i18n", function () {
"A cada 5 minutos, entre 15:00 e 15:59, somente de segunda-feira a sexta-feira e domingo"
);
});

it("45 10 * * 6#2", function () {
assert.equal(
cronstrue.toString(this.test?.title as string, { locale: "pt_BR" }),
"Às 10:45, no segundo sábado do mês"
);
});

it("45 10 * * 0#3", function () {
assert.equal(
cronstrue.toString(this.test?.title as string, { locale: "pt_BR" }),
"Às 10:45, no terceiro domingo do mês"
);
});

it("45 10 * * 1#3", function () {
assert.equal(
cronstrue.toString(this.test?.title as string, { locale: "pt_BR" }),
"Às 10:45, na terceira segunda-feira do mês"
);
});
});


Expand All @@ -195,6 +216,28 @@ describe("i18n", function () {
"A cada 5 minutos, entre 15:00 e 15:59, de segunda-feira a sexta-feira"
);
});


it("45 10 * * 6#2", function () {
assert.equal(
cronstrue.toString(this.test?.title as string, { locale: "pt_BR" }),
"Às 10:45, no segundo sábado do mês"
);
});

it("45 10 * * 0#3", function () {
assert.equal(
cronstrue.toString(this.test?.title as string, { locale: "pt_BR" }),
"Às 10:45, no terceiro domingo do mês"
);
});

it("45 10 * * 1#3", function () {
assert.equal(
cronstrue.toString(this.test?.title as string, { locale: "pt_BR" }),
"Às 10:45, na terceira segunda-feira do mês"
);
});
});

describe("ro", function () {
Expand Down
Loading