|
|
|
@ -7,7 +7,7 @@ class AppDateUtils {
|
|
|
|
|
return DateFormat(dateFormat).format(dateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DateTime convertISOStringToDateTime(String date){
|
|
|
|
|
static DateTime convertISOStringToDateTime(String date) {
|
|
|
|
|
DateTime newDate;
|
|
|
|
|
|
|
|
|
|
newDate = DateTime.parse(date);
|
|
|
|
@ -27,22 +27,20 @@ class AppDateUtils {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DateTime getDateTimeFromServerFormat(String str) {
|
|
|
|
|
DateTime date= DateTime.now();
|
|
|
|
|
if (str!=null) {
|
|
|
|
|
DateTime date = DateTime.now();
|
|
|
|
|
if (str != null) {
|
|
|
|
|
const start = "/Date(";
|
|
|
|
|
|
|
|
|
|
const end = "+0300)";
|
|
|
|
|
if(str.contains("/Date")){
|
|
|
|
|
final startIndex = str.indexOf(start);
|
|
|
|
|
if (str.contains("/Date")) {
|
|
|
|
|
final startIndex = str.indexOf(start);
|
|
|
|
|
|
|
|
|
|
final endIndex = str.indexOf(end, startIndex + start.length);
|
|
|
|
|
|
|
|
|
|
date = new DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
|
int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
} else {
|
|
|
|
|
date = DateTime.now();
|
|
|
|
|
}
|
|
|
|
|
final endIndex = str.indexOf(end, startIndex + start.length);
|
|
|
|
|
|
|
|
|
|
date = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
} else {
|
|
|
|
|
date = DateTime.now();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
date = DateTime.parse(str);
|
|
|
|
|
}
|
|
|
|
@ -50,8 +48,7 @@ class AppDateUtils {
|
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String differenceBetweenDateAndCurrentInYearMonthDay(
|
|
|
|
|
DateTime firstDate, BuildContext context) {
|
|
|
|
|
static String differenceBetweenDateAndCurrentInYearMonthDay(DateTime firstDate, BuildContext context) {
|
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
|
// now = now.add(Duration(days: 400, minutes: 0));
|
|
|
|
|
var difference = firstDate.difference(now);
|
|
|
|
@ -71,15 +68,13 @@ class AppDateUtils {
|
|
|
|
|
return "$days ${TranslationBase.of(context).days}, $months ${TranslationBase.of(context).months}, $years ${TranslationBase.of(context).years}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String differenceBetweenDateAndCurrent(
|
|
|
|
|
DateTime firstDate, BuildContext context) {
|
|
|
|
|
static String differenceBetweenDateAndCurrent(DateTime firstDate, BuildContext context) {
|
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
|
// DateTime now = nows.add(Duration(days: 400, minutes: 25, hours: 0));
|
|
|
|
|
var difference = now.difference(firstDate);
|
|
|
|
|
|
|
|
|
|
int minutesInDays = difference.inMinutes;
|
|
|
|
|
int hoursInDays =
|
|
|
|
|
minutesInDays ~/ 60; // ~/ : truncating division to make the result int
|
|
|
|
|
int hoursInDays = minutesInDays ~/ 60; // ~/ : truncating division to make the result int
|
|
|
|
|
int minutes = minutesInDays % 60;
|
|
|
|
|
int days = hoursInDays ~/ 24;
|
|
|
|
|
int hours = hoursInDays % 24;
|
|
|
|
@ -89,8 +84,7 @@ class AppDateUtils {
|
|
|
|
|
return "$days ${TranslationBase.of(context).days}, $hours ${TranslationBase.of(context).hr}, $minutes ${TranslationBase.of(context).min}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String differenceBetweenServerDateAndCurrent(
|
|
|
|
|
String str, BuildContext context) {
|
|
|
|
|
static String differenceBetweenServerDateAndCurrent(String str, BuildContext context) {
|
|
|
|
|
const start = "/Date(";
|
|
|
|
|
|
|
|
|
|
const end = "+0300)";
|
|
|
|
@ -99,8 +93,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 = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
|
|
|
|
|
return differenceBetweenDateAndCurrent(date, context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -246,7 +239,10 @@ class AppDateUtils {
|
|
|
|
|
final startIndex = date.indexOf(start);
|
|
|
|
|
final endIndex = date.indexOf(end, startIndex + start.length);
|
|
|
|
|
DateTime newDate = DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
|
int.parse(date.substring(startIndex + start.length, endIndex),),);
|
|
|
|
|
int.parse(
|
|
|
|
|
date.substring(startIndex + start.length, endIndex),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return newDate;
|
|
|
|
|
} else
|
|
|
|
|
return DateTime.now();
|
|
|
|
@ -256,35 +252,30 @@ class AppDateUtils {
|
|
|
|
|
/// [dateTime] convert DateTime to data formatted Arabic
|
|
|
|
|
static String getMonthDayYearDateFormattedAr(DateTime dateTime) {
|
|
|
|
|
if (dateTime != null)
|
|
|
|
|
return getMonthArabic(dateTime.month) +
|
|
|
|
|
" " +
|
|
|
|
|
dateTime.day.toString() +
|
|
|
|
|
", " +
|
|
|
|
|
dateTime.year.toString();
|
|
|
|
|
return getMonthArabic(dateTime.month) + " " + dateTime.day.toString() + ", " + dateTime.year.toString();
|
|
|
|
|
else
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// get data formatted like Apr 26,2020
|
|
|
|
|
/// [dateTime] convert DateTime to data formatted
|
|
|
|
|
static String getMonthDayYearDateFormatted(DateTime dateTime,{bool isArabic = false}) {
|
|
|
|
|
static String getMonthDayYearDateFormatted(DateTime dateTime, {bool isArabic = false}) {
|
|
|
|
|
if (dateTime != null)
|
|
|
|
|
return isArabic? getMonthArabic(dateTime.month): getMonth(dateTime.month) +
|
|
|
|
|
" " +
|
|
|
|
|
dateTime.day.toString() +
|
|
|
|
|
", " +
|
|
|
|
|
dateTime.year.toString();
|
|
|
|
|
return isArabic
|
|
|
|
|
? getMonthArabic(dateTime.month)
|
|
|
|
|
: getMonth(dateTime.month) + " " + dateTime.day.toString() + ", " + dateTime.year.toString();
|
|
|
|
|
else
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// get data formatted like 26 Apr 2020
|
|
|
|
|
/// [dateTime] convert DateTime to data formatted
|
|
|
|
|
static String getDayMonthYearDateFormatted(DateTime dateTime,{bool isArabic = false}) {
|
|
|
|
|
static String getDayMonthYearDateFormatted(DateTime dateTime, {bool isArabic = false}) {
|
|
|
|
|
if (dateTime != null)
|
|
|
|
|
return dateTime.day.toString()+" "+ "${isArabic? getMonthArabic(dateTime.month): getMonth(dateTime.month) }"+
|
|
|
|
|
return dateTime.day.toString() +
|
|
|
|
|
" " +
|
|
|
|
|
"${isArabic ? getMonthArabic(dateTime.month) : getMonth(dateTime.month)}" +
|
|
|
|
|
" " +
|
|
|
|
|
|
|
|
|
|
dateTime.year.toString();
|
|
|
|
|
else
|
|
|
|
|
return "";
|
|
|
|
@ -292,9 +283,9 @@ class AppDateUtils {
|
|
|
|
|
|
|
|
|
|
/// get data formatted like 26/4/2020
|
|
|
|
|
/// [dateTime] convert DateTime to data formatted
|
|
|
|
|
static String getDayMonthYearDate(DateTime dateTime,{bool isArabic = false}) {
|
|
|
|
|
static String getDayMonthYearDate(DateTime dateTime, {bool isArabic = false}) {
|
|
|
|
|
if (dateTime != null)
|
|
|
|
|
return dateTime.day.toString()+"/"+ "${dateTime.month}"+ "/" + dateTime.year.toString();
|
|
|
|
|
return dateTime.day.toString() + "/" + "${dateTime.month}" + "/" + dateTime.year.toString();
|
|
|
|
|
else
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
@ -302,15 +293,15 @@ class AppDateUtils {
|
|
|
|
|
/// get data formatted like 10:45 PM
|
|
|
|
|
/// [dateTime] convert DateTime to data formatted
|
|
|
|
|
static String getHour(DateTime dateTime) {
|
|
|
|
|
return DateFormat('hh:mm a').format(dateTime);
|
|
|
|
|
return DateFormat('hh:mm a').format(dateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String getAgeByBirthday(String birthOfDate, BuildContext context, { bool isServerFormat = true}) {
|
|
|
|
|
static String getAgeByBirthday(String birthOfDate, BuildContext context, {bool isServerFormat = true}) {
|
|
|
|
|
// https://leechy.dev/calculate-dates-diff-in-dart
|
|
|
|
|
DateTime birthDate;
|
|
|
|
|
if(birthOfDate.contains("/Date")) {
|
|
|
|
|
if (birthOfDate.contains("/Date")) {
|
|
|
|
|
birthDate = AppDateUtils.getDateTimeFromServerFormat(birthOfDate);
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
birthDate = DateTime.parse(birthOfDate);
|
|
|
|
|
}
|
|
|
|
|
final now = DateTime.now();
|
|
|
|
@ -328,24 +319,18 @@ class AppDateUtils {
|
|
|
|
|
return "$years ${TranslationBase.of(context).years} $months ${TranslationBase.of(context).months} $days ${TranslationBase.of(context).days}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool isToday(DateTime dateTime){
|
|
|
|
|
|
|
|
|
|
static bool isToday(DateTime dateTime) {
|
|
|
|
|
DateTime todayDate = DateTime.now().toUtc();
|
|
|
|
|
if(dateTime.day == todayDate.day && dateTime.month == todayDate.month && dateTime.year == todayDate.year) {
|
|
|
|
|
if (dateTime.day == todayDate.day && dateTime.month == todayDate.month && dateTime.year == todayDate.year) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String getDate(DateTime dateTime) {
|
|
|
|
|
print(dateTime);
|
|
|
|
|
if (dateTime != null)
|
|
|
|
|
return getMonth(dateTime.month) +
|
|
|
|
|
" " +
|
|
|
|
|
dateTime.day.toString() +
|
|
|
|
|
"," +
|
|
|
|
|
dateTime.year.toString();
|
|
|
|
|
return getMonth(dateTime.month) + " " + dateTime.day.toString() + "," + dateTime.year.toString();
|
|
|
|
|
else
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
@ -353,28 +338,23 @@ class AppDateUtils {
|
|
|
|
|
static String getDateFormatted(DateTime dateTime) {
|
|
|
|
|
print(dateTime);
|
|
|
|
|
if (dateTime != null)
|
|
|
|
|
return dateTime.day.toString() +
|
|
|
|
|
"/" +
|
|
|
|
|
dateTime.month.toString() +
|
|
|
|
|
"/" +
|
|
|
|
|
dateTime.year.toString();
|
|
|
|
|
return dateTime.day.toString() + "/" + dateTime.month.toString() + "/" + dateTime.year.toString();
|
|
|
|
|
else
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String getTimeHHMMA(DateTime dateTime){
|
|
|
|
|
static String getTimeHHMMA(DateTime dateTime) {
|
|
|
|
|
return DateFormat('hh:mm a').format(dateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String getTimeHHMMA2 (DateTime dateTime){
|
|
|
|
|
static String getTimeHHMMA2(DateTime dateTime) {
|
|
|
|
|
return DateFormat('hh:mm').format(dateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String getStartTime(String dateTime){
|
|
|
|
|
String time=dateTime;
|
|
|
|
|
static String getStartTime(String dateTime) {
|
|
|
|
|
String time = dateTime;
|
|
|
|
|
|
|
|
|
|
if(dateTime.length>7)
|
|
|
|
|
time = dateTime.substring(0,5);
|
|
|
|
|
if (dateTime.length > 7) time = dateTime.substring(0, 5);
|
|
|
|
|
return time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|