I wonder how could I calculate start and end days of the current week ? I've found that this it not implemented in standard android libs or such lib as date4j.
If there some easy and plain way to implement this ? Or I have to implement bicycle again ?
Thanks.
It doesn't take much code to do this with date4j. An example of calculating the first day of the week:
private void firstDayOfThisWeek(){
DateTime today = DateTime.today(TimeZone.getDefault());
DateTime firstDayThisWeek = today; //start value
int todaysWeekday = today.getWeekDay();
int SUNDAY = 1;
if(todaysWeekday > SUNDAY){
int numDaysFromSunday = todaysWeekday - SUNDAY;
firstDayThisWeek = today.minusDays(numDaysFromSunday);
}
System.out.println("The first day of this week is : " + firstDayThisWeek);
}
The above follows the convention that Sunday is the start of the week. In some jurisdictions, that convention doesn't apply, so you would need to change the code for such cases.
Maybe MonthDisplayHelper could be of help for you.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With