refactor: Use DateTime for weekday localization

This commit is contained in:
Malin Errenst 2023-05-16 10:18:09 +02:00
parent 06f399c76d
commit 650d878649
No known key found for this signature in database

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -59,22 +60,8 @@ extension DateTimeExtension on DateTime {
if (sameDay) { if (sameDay) {
return localizedTimeOfDay(context); return localizedTimeOfDay(context);
} else if (sameWeek) { } else if (sameWeek) {
switch (weekday) { return DateFormat.EEEE(Localizations.localeOf(context).languageCode)
case 1: .format(this);
return L10n.of(context)!.monday;
case 2:
return L10n.of(context)!.tuesday;
case 3:
return L10n.of(context)!.wednesday;
case 4:
return L10n.of(context)!.thursday;
case 5:
return L10n.of(context)!.friday;
case 6:
return L10n.of(context)!.saturday;
case 7:
return L10n.of(context)!.sunday;
}
} else if (sameYear) { } else if (sameYear) {
return L10n.of(context)!.dateWithoutYear( return L10n.of(context)!.dateWithoutYear(
month.toString().padLeft(2, '0'), month.toString().padLeft(2, '0'),