Created
March 11, 2020 13:29
-
-
Save eugene-drapoguz/8a1f13c47257bacc8138853cd4c39153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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