Created
October 30, 2023 16:14
-
-
Save V-Abhilash-1999/a4b2a56673450176b7448410457742da to your computer and use it in GitHub Desktop.
Week Day Text
This file contains hidden or 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
| (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