Minor code cleanup

This commit is contained in:
Bruno Bernardino
2024-03-30 18:10:06 +00:00
parent 87b94e9eec
commit d3a6f60d81

View File

@@ -567,7 +567,6 @@ const rRuleToFrequencyOrWeekDay = new Map<RRuleFrequency | RRuleWeekDay, string>
['SU', 'Sunday'], ['SU', 'Sunday'],
]); ]);
// check if multiple days and format either way
function convertRRuleDaysToWords(day: string | RRuleFrequency | RRuleWeekDay): string { function convertRRuleDaysToWords(day: string | RRuleFrequency | RRuleWeekDay): string {
if (day.includes(',')) { if (day.includes(',')) {
const days = day.split(',') as (typeof day)[]; const days = day.split(',') as (typeof day)[];
@@ -578,7 +577,6 @@ function convertRRuleDaysToWords(day: string | RRuleFrequency | RRuleWeekDay): s
return rRuleToFrequencyOrWeekDay.get(day as RRuleFrequency | RRuleWeekDay)!; return rRuleToFrequencyOrWeekDay.get(day as RRuleFrequency | RRuleWeekDay)!;
} }
// convert to ordinal number
function getOrdinalSuffix(number: number) { function getOrdinalSuffix(number: number) {
const text = ['th', 'st', 'nd', 'rd'] as const; const text = ['th', 'st', 'nd', 'rd'] as const;
const value = number % 100; const value = number % 100;
@@ -607,10 +605,6 @@ export function convertRRuleToWords(rRule: string): string {
const count = parsedRRule.COUNT; const count = parsedRRule.COUNT;
const interval = parsedRRule.INTERVAL; const interval = parsedRRule.INTERVAL;
// TODO: Remove this
console.log('==== File.method');
console.log(JSON.stringify({}, null, 2));
const words: string[] = []; const words: string[] = [];
if (frequency === 'DAILY') { if (frequency === 'DAILY') {
@@ -637,7 +631,7 @@ export function convertRRuleToWords(rRule: string): string {
if (frequency === 'WEEKLY') { if (frequency === 'WEEKLY') {
if (byDay) { if (byDay) {
if (interval && parseInt(interval) > 1) { if (interval && parseInt(interval, 10) > 1) {
words.push( words.push(
`Every ${interval} ${rRuleToFrequencyOrWeekDay.get(frequency)}s on ${convertRRuleDaysToWords(byDay)}`, `Every ${interval} ${rRuleToFrequencyOrWeekDay.get(frequency)}s on ${convertRRuleDaysToWords(byDay)}`,
); );
@@ -663,7 +657,7 @@ export function convertRRuleToWords(rRule: string): string {
// monthly // monthly
if (frequency === 'MONTHLY' && byMonthDay) { if (frequency === 'MONTHLY' && byMonthDay) {
if (interval && parseInt(interval) > 1) { if (interval && parseInt(interval, 10) > 1) {
words.push( words.push(
`Every ${interval} ${rRuleToFrequencyOrWeekDay.get(frequency)}s on the ${ `Every ${interval} ${rRuleToFrequencyOrWeekDay.get(frequency)}s on the ${
getOrdinalSuffix(parseInt(byMonthDay, 10)) getOrdinalSuffix(parseInt(byMonthDay, 10))