diff --git a/packages/polytechcolloscopeclient/lib/src/consts.dart b/packages/polytechcolloscopeclient/lib/src/consts.dart index e4e6e9e6..3d7b5c04 100644 --- a/packages/polytechcolloscopeclient/lib/src/consts.dart +++ b/packages/polytechcolloscopeclient/lib/src/consts.dart @@ -16,19 +16,37 @@ class Consts { Year.first: "$_base?page=colles_1A&id_etudiant=:id", Year.second: "$_base?page=colles_2A&id_etudiant=:id" }; +} - static const Map monthsTranslation = { - "janvier": DateTime.january, - "février": DateTime.february, - "mars": DateTime.march, - "avril": DateTime.april, - "mai": DateTime.may, - "juin": DateTime.june, - "juillet": DateTime.july, - "août": DateTime.august, - "septembre": DateTime.september, - "octobre": DateTime.october, - "novembre": DateTime.november, - "décembre": DateTime.december - }; +extension MonthsTranslation on String { + int get asMonthNumber { + switch (this) { + case "janvier": + return DateTime.january; + case "février": + return DateTime.february; + case "mars": + return DateTime.march; + case "avril": + return DateTime.april; + case "mai": + return DateTime.may; + case "juin": + return DateTime.june; + case "juillet": + return DateTime.july; + case "août": + return DateTime.august; + case "septembre": + return DateTime.september; + case "octobre": + return DateTime.october; + case "novembre": + return DateTime.november; + case "décembre": + return DateTime.december; + default: + throw StateError("Invalid month"); + } + } } diff --git a/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart b/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart index 0a67ac9a..d36ff85e 100644 --- a/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart +++ b/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart @@ -106,7 +106,7 @@ class PolytechColloscopeClient { var dateParsed = RegExp(r"(\d{1,2}) (.{3,9})").firstMatch(date)!; var day = dateParsed.group(1)!; - var month = Consts.monthsTranslation[dateParsed.group(2)]; + var month = dateParsed.group(2)!.asMonthNumber; var hourAndMinutesParsed = RegExp(r"(\d{1,2}) h (\d{2})").firstMatch(hourAndMinute)!;