|
|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:hmg_flutter_template/generated/locale_keys.g.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
|
|
|
|
class AppDateUtils {
|
|
|
|
|
static String convertDateToFormat(DateTime dateTime, String dateFormat) {
|
|
|
|
|
@ -18,10 +17,11 @@ class AppDateUtils {
|
|
|
|
|
|
|
|
|
|
static String convertStringToDateFormat(String date, String dateFormat) {
|
|
|
|
|
DateTime dateTime;
|
|
|
|
|
if (date.contains("/Date"))
|
|
|
|
|
if (date.contains("/Date")) {
|
|
|
|
|
dateTime = getDateTimeFromServerFormat(date);
|
|
|
|
|
else
|
|
|
|
|
} else {
|
|
|
|
|
dateTime = DateTime.parse(date);
|
|
|
|
|
}
|
|
|
|
|
return convertDateToFormat(dateTime, dateFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -50,7 +50,7 @@ class AppDateUtils {
|
|
|
|
|
|
|
|
|
|
final endIndex = str.indexOf(end, startIndex + start.length);
|
|
|
|
|
|
|
|
|
|
date = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
date = DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
} else {
|
|
|
|
|
date = DateTime.now();
|
|
|
|
|
}
|
|
|
|
|
@ -95,10 +95,7 @@ class AppDateUtils {
|
|
|
|
|
|
|
|
|
|
double hoursInOneDay = difference.inHours / difference.inDays;
|
|
|
|
|
|
|
|
|
|
return (isShowDays ? (days > 0 ? "$days ${LocaleKeys.days.tr()}," : '') : "") +
|
|
|
|
|
(hours > 0 ? "$hours ${LocaleKeys.hr.tr()}," : "") +
|
|
|
|
|
" $minutes ${LocaleKeys.min.tr()}" +
|
|
|
|
|
(isShowSecond ? ", $second Sec" : "");
|
|
|
|
|
return "${isShowDays ? (days > 0 ? "$days ${LocaleKeys.days.tr()}," : '') : ""}${hours > 0 ? "$hours ${LocaleKeys.hr.tr()}," : ""} $minutes ${LocaleKeys.min.tr()}${isShowSecond ? ", $second Sec" : ""}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String differenceBetweenServerDateAndCurrent(String str, BuildContext context) {
|
|
|
|
|
@ -110,7 +107,7 @@ class AppDateUtils {
|
|
|
|
|
|
|
|
|
|
final endIndex = str.indexOf(end, startIndex + start.length);
|
|
|
|
|
|
|
|
|
|
var date = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
var date = DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
return differenceBetweenDateAndCurrent(date, context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|