Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eugene-drapoguz/8a1f13c47257bacc8138853cd4c39153 to your computer and use it in GitHub Desktop.
Save eugene-drapoguz/8a1f13c47257bacc8138853cd4c39153 to your computer and use it in GitHub Desktop.
private fun getWeekDate(): String {
val cal = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0)
clear(Calendar.MINUTE)
clear(Calendar.SECOND)
clear(Calendar.MILLISECOND)
}
cal.set(Calendar.DAY_OF_WEEK, cal.firstDayOfWeek)
val startWeek = cal.time
val startWeekMonth = cal.get(Calendar.MONTH)
cal.set(Calendar.DAY_OF_WEEK, cal.firstDayOfWeek)
cal.add(Calendar.DAY_OF_WEEK, 6)
val endWeek = cal.time
val endWeekMonth = cal.get(Calendar.MONTH)
val endWeekTemplate = if (startWeekMonth == endWeekMonth) {
_application.getString(R.string.dashboard_task_filter_template_week_date_2)
} else {
_application.getString(R.string.dashboard_task_filter_template_week_date_1)
}
val startWeekStr = SimpleDateFormat(
_application.getString(R.string.dashboard_task_filter_template_week_date_1),
Locale.getDefault()
).format(startWeek)
val endWeekStr = SimpleDateFormat(
endWeekTemplate,
Locale.getDefault()
).format(endWeek)
return "$startWeekStr - $endWeekStr"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment