cake_wallet/lib/utils/date_formatter.dart

24 lines
957 B
Dart
Raw Normal View History

2020-09-21 11:50:26 +00:00
import 'package:intl/intl.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/store/settings_store.dart';
class DateFormatter {
static String currentLocalFormat({bool hasTime = true, bool reverse = false}) {
2020-09-28 15:47:43 +00:00
final isUSA = getIt.get<SettingsStore>().languageCode.toLowerCase() == 'en';
2020-10-22 15:11:52 +00:00
final format =
isUSA ? usaStyleFormat(hasTime, reverse) : regularStyleFormat(hasTime, reverse);
2020-09-21 11:50:26 +00:00
return format;
}
static DateFormat withCurrentLocal({bool hasTime = true, bool reverse = false}) => DateFormat(
currentLocalFormat(hasTime: hasTime, reverse: reverse),
2020-10-22 15:11:52 +00:00
getIt.get<SettingsStore>().languageCode);
static String usaStyleFormat(bool hasTime, bool reverse) =>
hasTime ? (reverse ? 'HH:mm yyyy.MM.dd' : 'yyyy.MM.dd, HH:mm') : 'yyyy.MM.dd';
2020-10-22 15:11:52 +00:00
static String regularStyleFormat(bool hasTime, bool reverse) =>
hasTime ? (reverse ? 'HH:mm dd.MM.yyyy' : 'dd.MM.yyyy, HH:mm') : 'dd.MM.yyyy';
2020-09-21 11:50:26 +00:00
}