Skip to content

Commit

Permalink
Merge pull request #458 from pangyikhei/issue308
Browse files Browse the repository at this point in the history
Fix Issue #308
  • Loading branch information
jmrozanec committed Oct 27, 2020
2 parents 7937ce6 + 6ef01c0 commit b080eba
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 41 deletions.
Expand Up @@ -14,6 +14,7 @@
package com.cronutils.descriptor;

import com.cronutils.model.field.expression.Every;
import java.text.MessageFormat;
import java.time.DayOfWeek;
import java.time.Month;
import java.time.format.TextStyle;
Expand Down Expand Up @@ -83,7 +84,14 @@ public static DescriptionStrategy daysOfMonthInstance(final ResourceBundle bundl
return String
.format("%s %s %s ", bundle.getString("the_nearest_weekday_to_the"), on.getTime().getValue(), bundle.getString("of_the_month"));
case L:
return bundle.getString("last_day_of_month");
Integer daysBefore = on.getNth().getValue();
if (daysBefore > 1) {
return MessageFormat.format(bundle.getString("days_before_last_day_of_month"), daysBefore);
} else if (daysBefore == 1){
return bundle.getString("day_before_last_day_of_month");
} else {
return bundle.getString("last_day_of_month");
}
case LW:
return bundle.getString("last_weekday_of_month");
default:
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N.properties
Expand Up @@ -21,6 +21,8 @@ last=last
the_nearest_weekday_to_the=the nearest weekday to the
last_day_of_month=last day of month
last_weekday_of_month=last weekday of month
day_before_last_day_of_month=one day before the last day of the month
days_before_last_day_of_month={0} days before the last day of the month

pattern_every_seconds = {0} {1}
every_one=every
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/CronUtilsI18N_de.properties
Expand Up @@ -21,7 +21,8 @@ last=letzten
the_nearest_weekday_to_the=am n\ufffdchsten Werktag nach dem
last_day_of_month=letzten Tag des Monats
last_weekday_of_month=letzten Werktag des Monats

day_before_last_day_of_month=einen Tag vor dem letzten Tag des Monats
days_before_last_day_of_month={0} Tage vor dem letzten Tag des Monats

pattern_every_seconds = {0} {1}
every_one=jede
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_el.properties
Expand Up @@ -21,3 +21,5 @@ last=\u03C4\u03B5\u03BB\u03B1\u03C5\u03C4\u03B1\u03AF\u03BF
the_nearest_weekday_to_the=\u03B7 \u03BA\u03BF\u03BD\u03C4\u03B9\u03BD\u03CC\u03C4\u03B5\u03C1\u03B7 \u03B5\u03C1\u03B3\u03AC\u03C3\u03B9\u03BC\u03B7 \u03C3\u03C4\u03BF
last_day_of_month=\u03C4\u03B5\u03BB\u03B5\u03C5\u03C4\u03B1\u03AF\u03B1 \u03BC\u03AD\u03C1\u03B1 \u03C4\u03BF\u03C5 \u03BC\u03AE\u03BD\u03B1
last_weekday_of_month=\u03C4\u03B5\u03BB\u03B5\u03C5\u03C4\u03B1\u03AF\u03B1 \u03B5\u03C1\u03B3\u03AC\u03C3\u03B9\u03BC\u03B7 \u03C4\u03BF\u03C5 \u03BC\u03AE\u03BD\u03B1
day_before_last_day_of_month=\u03BC\u03AF\u03B1 \u03B7\u03BC\u03AD\u03C1\u03B1 \u03C0\u03C1\u03B9\u03BD \u03B1\u03C0\u03CC \u03C4\u03B7\u03BD \u03C4\u03B5\u03BB\u03B5\u03C5\u03C4\u03B1\u03AF\u03B1 \u03B7\u03BC\u03AD\u03C1\u03B1 \u03C4\u03BF\u03C5 \u03BC\u03AE\u03BD\u03B1
days_before_last_day_of_month={0} \u03B7\u03BC\u03AD\u03C1\u03B5\u03C2 \u03C0\u03C1\u03B9\u03BD \u03B1\u03C0\u03CC \u03C4\u03B7\u03BD \u03C4\u03B5\u03BB\u03B5\u03C5\u03C4\u03B1\u03AF\u03B1 \u03B7\u03BC\u03AD\u03C1\u03B1 \u03C4\u03BF\u03C5 \u03BC\u03AE\u03BD\u03B1
50 changes: 26 additions & 24 deletions src/main/resources/CronUtilsI18N_en.properties
@@ -1,24 +1,26 @@
between_x_and_y=between {0} and {1}
every=every
and=and
at=at
day=day
days=days
hour=hour
hours=hours
minute=minute
minutes=minutes
second=second
seconds=seconds
month=month
months=months
year=year
years=years
between=between
of_every_month=of every month
of_every_hour=of every hour
of_the_month=of the month
last=last
the_nearest_weekday_to_the=the nearest weekday to the
last_day_of_month=last day of month
last_weekday_of_month=last weekday of month
between_x_and_y=between {0} and {1}
every=every
and=and
at=at
day=day
days=days
hour=hour
hours=hours
minute=minute
minutes=minutes
second=second
seconds=seconds
month=month
months=months
year=year
years=years
between=between
of_every_month=of every month
of_every_hour=of every hour
of_the_month=of the month
last=last
the_nearest_weekday_to_the=the nearest weekday to the
last_day_of_month=last day of month
last_weekday_of_month=last weekday of month
day_before_last_day_of_month=one day before the last day of the month
days_before_last_day_of_month={0} days before the last day of the month
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_es.properties
Expand Up @@ -21,3 +21,5 @@ last=ultimo
the_nearest_weekday_to_the=dia de semana mas cercano a
last_day_of_month=ultimo dia del mes
last_weekday_of_month=ultimo dia de semana del mes
day_before_last_day_of_month=un día antes del último día del mes
days_before_last_day_of_month={0} días antes del último día del mes
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_fr.properties
Expand Up @@ -21,3 +21,5 @@ days=jours
months=les mois
years=les ann\u00e9es
last_weekday_of_month=derni\u00e8re semaine du mois
day_before_last_day_of_month=un jour avant le dernier jour du mois
days_before_last_day_of_month={0} jours avant le dernier jour du mois
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_id.properties
Expand Up @@ -21,3 +21,5 @@ last=terakhir
the_nearest_weekday_to_the=hari kerja terdekat ke
last_day_of_month=hari terakhir di bulan
last_weekday_of_month=hari kerja terakhir di bulan
day_before_last_day_of_month=satu hari sebelum hari terakhir bulan itu
days_before_last_day_of_month={0} hari sebelum hari terakhir setiap bulan
4 changes: 3 additions & 1 deletion src/main/resources/CronUtilsI18N_it.properties
Expand Up @@ -20,4 +20,6 @@ of_the_month=del mese
last=ultimo
the_nearest_weekday_to_the=il giorno della settimana più vicino a
last_day_of_month=ultimo giorno del mese
last_weekday_of_month=ultimo giorno della settimana nel mese
last_weekday_of_month=ultimo giorno della settimana nel mese
day_before_last_day_of_month=un giorno prima dell'ultimo giorno del mese
days_before_last_day_of_month={0} giorni prima dell'ultimo giorno del mese
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_ko.properties
Expand Up @@ -21,3 +21,5 @@ last=\uB9C8\uC9C0\uB9C9
the_nearest_weekday_to_the=\uAC00\uC7A5 \uAC00\uAE4C\uC6B4 \uD3C9\uC77C
last_day_of_month=\uB9D0\uC77C
last_weekday_of_month=\uB9C8\uC9C0\uB9C9 \uC8FC
day_before_last_day_of_month=\uB9E4\uC6D4 \uB9D0\uC77C \uD558\uB8E8 \uC804
days_before_last_day_of_month=\uB9E4\uC6D4 \uB9D0\uC77C {0} \uC77C \uC804
3 changes: 2 additions & 1 deletion src/main/resources/CronUtilsI18N_nl.properties
Expand Up @@ -21,7 +21,8 @@ last=laatste
the_nearest_weekday_to_the=de dichtsbijzijnde weekdag voor de
last_day_of_month=laaste dag van maand
last_weekday_of_month=laatste weekdag van maand

day_before_last_day_of_month=een dag voor de laatste dag van de maand
days_before_last_day_of_month={0} dagen voor de laatste dag van de maand

pattern_every_seconds = {0} {1}
every_one=elke
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/CronUtilsI18N_pl.properties
Expand Up @@ -20,4 +20,6 @@ of_the_month=miesi\u0105ca
last=ostatni
the_nearest_weekday_to_the=najbli\u017Cszy weekend
last_day_of_month=ostatni dzie\u0144 miesi\u0105ca
last_weekday_of_month=ostatni dzie\u0144 tygodnia w miesi\u0105cu
last_weekday_of_month=ostatni dzie\u0144 tygodnia w miesi\u0105cu
day_before_last_day_of_month=jeden dzie\u0144 przed ostatnim dniem miesi\u0105ca
days_before_last_day_of_month={0} dni przed ostatnim dniem miesi\u0105ca
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_pt.properties
Expand Up @@ -17,3 +17,5 @@ of_the_month=do m\u00eas
last=\u00faltima
the_nearest_weekday_to_the=o dia da semana mais pr\u00f3ximo do
last_day_of_month=\u00faltimo dia do m\u00eas
day_before_last_day_of_month=um dia antes do \u00FAltimo dia do m\u00EAs
days_before_last_day_of_month={0} dias antes do \u00FAltimo dia do m\u00EAs
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_ru.properties
Expand Up @@ -21,3 +21,5 @@ last=\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439
the_nearest_weekday_to_the=\u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0431\u0443\u0434\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043a
last_day_of_month=\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043c\u0435\u0441\u044f\u0446\u0430
last_weekday_of_month=\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0431\u0443\u0434\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043c\u0435\u0441\u044f\u0446\u0430
day_before_last_day_of_month=\u0437\u0430 \u0434\u0435\u043D\u044C \u0434\u043E \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u0435\u0433\u043E \u0434\u043D\u044F \u043C\u0435\u0441\u044F\u0446\u0430
days_before_last_day_of_month=\u0417\u0430 {0} \u0434\u043D\u044F \u0434\u043E \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u0435\u0433\u043E \u0434\u043D\u044F \u043C\u0435\u0441\u044F\u0446\u0430
3 changes: 3 additions & 0 deletions src/main/resources/CronUtilsI18N_sw.properties
Expand Up @@ -21,3 +21,6 @@ last=mwisho
the_nearest_weekday_to_the=siku ya juma iliyokaribu na
last_day_of_month=siku ya mwisho ya mwezi
last_weekday_of_month=siku ya juma ya mwisho ya mwezi
day_before_last_day_of_month=siku moja kabla ya siku ya mwisho ya mwezi
days_before_last_day_of_month=Siku {0} kabla ya siku ya mwisho ya mwezi

2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_tr.properties
Expand Up @@ -21,3 +21,5 @@ last=son
the_nearest_weekday_to_the=\u015Fu zamana en yak\u0131n hafta i\u00E7i g\u00FCn\u00FC
last_day_of_month=ay\u0131n son g\u00FCn\u00FC
last_weekday_of_month=ay\u0131n son hafta i\u00E7i g\u00FCn\u00FC
day_before_last_day_of_month=ay\u0131n son g\u00FCn\u00FCnden bir g\u00FCn \u00F6nce
days_before_last_day_of_month=Ay\u0131n son g\u00FCn\u00FCnden {0} g\u00FCn \u00F6nce
2 changes: 2 additions & 0 deletions src/main/resources/CronUtilsI18N_zh.properties
Expand Up @@ -21,3 +21,5 @@ last=\u6700\u540e\u7684
the_nearest_weekday_to_the=\u6700\u8fd1\u7684\u5de5\u4f5c\u65e5\u8ddd
last_day_of_month=\u6bcf\u6708\u6700\u540e\u4e00\u5929
last_weekday_of_month=\u6708\u4efd\u7684\u6700\u540e\u4e00\u5468
day_before_last_day_of_month=\u8BE5\u6708\u6700\u540E\u4E00\u5929\u7684\u524D\u4E00\u5929
days_before_last_day_of_month=\u8BE5\u6708\u6700\u540E\u4E00\u5929\u7684\u524D{0}\u5929
12 changes: 0 additions & 12 deletions src/test/java/com/cronutils/model/CronTest.java
Expand Up @@ -149,16 +149,4 @@ public void testSerialization() throws IOException, ClassNotFoundException {
}
}

@Ignore
@Test
public void testIssue308(){
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronParser parser = new CronParser(cronDefinition);
Cron quartzCron = parser.parse("0 0 11 L-2 * ?");
CronDescriptor descriptor = CronDescriptor.instance(Locale.ENGLISH);
String description = descriptor.describe(quartzCron);

// not sure what the exact string 'should' be ..
assertEquals( "at 11:00 two days before the last day of month", description);
}
}
20 changes: 20 additions & 0 deletions src/test/java/com/cronutils/utils/descriptor/TestDescriptor.java
Expand Up @@ -361,7 +361,27 @@ public void testAtTimeMultipleWeekdaysOfMultipleSpecificMonths() {
assertEquals("at 16:00:00pm, every Monday, Thursday and Saturday of the month, in January, May and December", descriptor.describe(cron));
}

@Test
public void testTwoDaysBeforeLastDayOfMonth(){
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronParser parser = new CronParser(cronDefinition);
Cron quartzCron = parser.parse("0 0 11 L-2 * ?");
CronDescriptor descriptor = CronDescriptor.instance(Locale.ENGLISH);
String description = descriptor.describe(quartzCron);

assertEquals( "at 11:00 2 days before the last day of the month", description);
}

@Test
public void testOneDayBeforeLastDayOfMonth(){
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronParser parser = new CronParser(cronDefinition);
Cron quartzCron = parser.parse("0 0 11 L-1 * ?");
CronDescriptor descriptor = CronDescriptor.instance(Locale.ENGLISH);
String description = descriptor.describe(quartzCron);

assertEquals( "at 11:00 one day before the last day of the month", description);
}


}

0 comments on commit b080eba

Please sign in to comment.