Skip to content

Instantly share code, notes, and snippets.

@V-Abhilash-1999
Created October 30, 2023 16:14
Show Gist options
  • Select an option

  • Save V-Abhilash-1999/a4b2a56673450176b7448410457742da to your computer and use it in GitHub Desktop.

Select an option

Save V-Abhilash-1999/a4b2a56673450176b7448410457742da to your computer and use it in GitHub Desktop.
Week Day Text
(0..6).forEach { weekDay ->
val dayIndex = (weekDay + (firstDayOfWeek - 1)) % 7
val currentDay = Calendar.getInstance(locale).apply {
set(2023, 0, 1 + dayIndex)
}
val weekText = remember(weekDay, locale) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val dayOrdinal = if (dayIndex == 0) 7 else dayIndex
DayOfWeek.of(dayOrdinal).getDisplayName(java.time.format.TextStyle.NARROW, locale).toString()
} else {
val dateFormat = SimpleDateFormat("EEEEE", locale)
dateFormat.format(currentDay.time)
}.toString()
}
Text(
modifier = Modifier.weight(1f),
text = weekText,
textAlign = TextAlign.Center,
style = dateTextStyle.weekDayTextStyle
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment