fbmobile/lib/core/util/formatter_util.dart
Varakh b55e932204
All checks were successful
continuous-integration/drone/push Build is passing
Added proper linting #noissue
2023-01-04 21:17:54 +01:00

18 lines
595 B
Dart

import 'dart:math';
import 'package:intl/intl.dart';
class FormatterUtil {
/// Format epoch timestamp
static String formatEpoch(num millis) {
DateFormat dateFormat = DateFormat().add_yMEd().add_Hm();
return dateFormat.format(DateTime.fromMillisecondsSinceEpoch(millis as int));
}
static String formatBytes(int bytes, int decimals) {
if (bytes <= 0) return "0 B";
const suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var i = (log(bytes) / log(1024)).floor();
return '${(bytes / pow(1024, i)).toStringAsFixed(decimals)} ${suffixes[i]}';
}
}