Files
SDKmuta/lib/utils/format.dart
T
2026-11-27 14:37:44 +01:00

19 lines
779 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:intl/intl.dart';
import '../services/app_settings.dart';
/// Decimal number the way the language writes it: 8,49 (sl, de) or 8.49 (en).
String dec(double v, [int digits = 2]) {
final s = v.toStringAsFixed(digits);
return AppSettings.instance.language == 'English' ? s : s.replaceAll('.', ',');
}
/// Signed difference: "+0,21" / "−0,06".
String signedDec(double v, [int digits = 2]) => '${v >= 0 ? '+' : '−'}${dec(v.abs(), digits)}';
/// "čet, 12. 11." (or with the year): weekday without the locale's dot.
String dayDate(DateTime d, {bool year = false}) {
final s = AppSettings.instance;
final weekday = DateFormat('EEE', s.dateLocale).format(d).replaceAll('.', '');
return '$weekday, ${DateFormat(year ? 'd. M. yyyy' : 'd. M.').format(d)}';
}