|
|
|
@ -35,19 +35,54 @@ fun Double.toCurrency(): String { |
|
|
|
return "$ ${formatter.format(this)}" |
|
|
|
return "$ ${formatter.format(this)}" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calendar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return if the calendar dates are in the same month |
|
|
|
|
|
|
|
fun Calendar.isSameMonth(calendar: Calendar): Boolean { |
|
|
|
|
|
|
|
return calendar.get(Calendar.YEAR) == this.get(Calendar.YEAR) && |
|
|
|
|
|
|
|
calendar.get(Calendar.MONTH) == this.get(Calendar.MONTH) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Return if the calendar dates are in the same day |
|
|
|
|
|
|
|
fun Calendar.isSameDay(calendar: Calendar): Boolean { |
|
|
|
|
|
|
|
return calendar.get(Calendar.YEAR) == this.get(Calendar.YEAR) && |
|
|
|
|
|
|
|
calendar.get(Calendar.MONTH) == this.get(Calendar.MONTH) && |
|
|
|
|
|
|
|
calendar.get(Calendar.DAY_OF_MONTH) == this.get(Calendar.DAY_OF_MONTH) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Date |
|
|
|
// Date |
|
|
|
|
|
|
|
|
|
|
|
// Return a short string of the date |
|
|
|
// Return a short string of the date |
|
|
|
fun Date.short(): String { |
|
|
|
fun Date.shortDate(): String { |
|
|
|
|
|
|
|
return DateFormat.getDateInstance(DateFormat.SHORT).format(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Return a short string of the date |
|
|
|
|
|
|
|
fun Date.mediumDate(): String { |
|
|
|
|
|
|
|
return DateFormat.getDateInstance(DateFormat.MEDIUM).format(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Return a long string of the date |
|
|
|
|
|
|
|
fun Date.longDate(): String { |
|
|
|
|
|
|
|
return DateFormat.getDateInstance(DateFormat.LONG).format(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Return a short string of the date |
|
|
|
|
|
|
|
fun Date.fullDate(): String { |
|
|
|
|
|
|
|
return DateFormat.getDateInstance(DateFormat.FULL).format(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return a short string of the date & time |
|
|
|
|
|
|
|
fun Date.shortDateTime(): String { |
|
|
|
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(this) |
|
|
|
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(this) |
|
|
|
} |
|
|
|
} |
|
|
|
// Return a medium string of the date |
|
|
|
// Return a medium string of the date & time |
|
|
|
fun Date.medium(): String { |
|
|
|
fun Date.mediumDateTime(): String { |
|
|
|
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(this) |
|
|
|
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(this) |
|
|
|
} |
|
|
|
} |
|
|
|
// Return the full string of the date |
|
|
|
// Return a long string of the date & time |
|
|
|
fun Date.full(): String { |
|
|
|
fun Date.longDateTime(): String { |
|
|
|
|
|
|
|
return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Return the full string of the date & time |
|
|
|
|
|
|
|
fun Date.fullDateTime(): String { |
|
|
|
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(this) |
|
|
|
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(this) |
|
|
|
} |
|
|
|
} |
|
|
|
// Return the day number of the date |
|
|
|
// Return the day number of the date |
|
|
|
@ -58,6 +93,11 @@ fun Date.getDayNumber() : String { |
|
|
|
fun Date.getShortDayName() : String { |
|
|
|
fun Date.getShortDayName() : String { |
|
|
|
return SimpleDateFormat("EE", Locale.getDefault()).format(this) |
|
|
|
return SimpleDateFormat("EE", Locale.getDefault()).format(this) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Return the month & year of the date |
|
|
|
|
|
|
|
fun Date.getMonthAndYear(): String { |
|
|
|
|
|
|
|
return SimpleDateFormat("MMMM YYYY", Locale.getDefault()).format(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Return the duration between two dates |
|
|
|
// Return the duration between two dates |
|
|
|
fun Date.getDuration(context: Context, toDate: Date) : String { |
|
|
|
fun Date.getDuration(context: Context, toDate: Date) : String { |
|
|
|
val difference = (toDate.time - this.time).toInt() |
|
|
|
val difference = (toDate.time - this.time).toInt() |
|
|
|
|