|
|
|
|
@ -40,7 +40,6 @@ class AppDateUtils {
|
|
|
|
|
|
|
|
|
|
static DateTime getDateTimeFromServerFormat(String str) {
|
|
|
|
|
DateTime date = DateTime.now();
|
|
|
|
|
if (str != null) {
|
|
|
|
|
const start = "/Date(";
|
|
|
|
|
|
|
|
|
|
const end = "+0300)";
|
|
|
|
|
@ -52,12 +51,8 @@ class AppDateUtils {
|
|
|
|
|
date = new DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
|
int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
} else {
|
|
|
|
|
date = DateTime.now();
|
|
|
|
|
date = DateTime.parse(str);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
date = DateTime.parse(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -333,6 +328,7 @@ class AppDateUtils {
|
|
|
|
|
/// get data formatted like 10:45 PM
|
|
|
|
|
/// [dateTime] convert DateTime to data formatted
|
|
|
|
|
static String getHour(DateTime dateTime) {
|
|
|
|
|
print("the time is ${DateFormat('hh:mm a').format(dateTime)}");
|
|
|
|
|
return DateFormat('hh:mm a').format(dateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -343,23 +339,45 @@ class AppDateUtils {
|
|
|
|
|
if (birthOfDate.contains("/Date")) {
|
|
|
|
|
birthDate = AppDateUtils.getDateTimeFromServerFormat(birthOfDate);
|
|
|
|
|
} else {
|
|
|
|
|
birthDate = DateTime.parse(birthOfDate);
|
|
|
|
|
try {
|
|
|
|
|
birthDate = DateTime.parse(birthOfDate);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print("Error parsing birth date: $e");
|
|
|
|
|
return "Invalid Date"; // Or return an empty string
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (birthDate == null) {
|
|
|
|
|
return "Invalid Date";
|
|
|
|
|
}
|
|
|
|
|
final now = DateTime.now();
|
|
|
|
|
|
|
|
|
|
final DateTime now = DateTime.now();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int years = now.year - birthDate.year;
|
|
|
|
|
int months = now.month - birthDate.month;
|
|
|
|
|
int days = now.day - birthDate.day;
|
|
|
|
|
if (months < 0 || (months == 0 && days < 0)) {
|
|
|
|
|
years--;
|
|
|
|
|
months += (days < 0 ? 11 : 12);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (days < 0) {
|
|
|
|
|
final monthAgo = new DateTime(now.year, now.month - 1, birthDate.day);
|
|
|
|
|
days = now.difference(monthAgo).inDays + 1;
|
|
|
|
|
final int lastDayOfPreviousMonth = DateTime(now.year, now.month, 0).day;
|
|
|
|
|
days += lastDayOfPreviousMonth;
|
|
|
|
|
months--;
|
|
|
|
|
}
|
|
|
|
|
return "$years ${TranslationBase.of(context).years} $months ${TranslationBase.of(context).months} $days ${TranslationBase.of(context).days}";
|
|
|
|
|
|
|
|
|
|
if (months < 0) {
|
|
|
|
|
months += 12;
|
|
|
|
|
years--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final yearsString = "$years ${TranslationBase.of(context).years}";
|
|
|
|
|
final monthsString = "$months ${TranslationBase.of(context).months}";
|
|
|
|
|
final daysString = "$days ${TranslationBase.of(context).days}";
|
|
|
|
|
|
|
|
|
|
return "$yearsString $monthsString $daysString";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool isToday(DateTime dateTime) {
|
|
|
|
|
DateTime todayDate = DateTime.now().toUtc();
|
|
|
|
|
if (dateTime.day == todayDate.day &&
|
|
|
|
|
|