Esh
Esh

Reputation: 856

override first day of the week in joda?

Is it possible to override the firstday of Joda week to sunday ? since Joda uses Monday as its firstday of the week . Can any one please explain me if there is a way .

I referred the below Topic in SOF

Joda Time: First day of week?

Thanks

Upvotes: 4

Views: 2264

Answers (1)

benjamin
benjamin

Reputation: 1066

No.

First of all, overriding the first day of the week to sunday would require overwriting all other weekdays as well. But these final constants are defined in the class DateTimeConstants, which are impossible to overwrite. But you wouldn't want to override theses values anyways because it would mess up joda-time's ISO-compliance.

At the same time I wonder why you would want to override it in the first place? Can you provide a use case?

public static DateTime getUSFirstDayOfWeek(DateTime dateTime) {
    return dateTime.withDayOfWeek(DateTimeConstants.MONDAY).minusDays(1);
}

This simple helper method would probably do the job. Notice that I didn't use SUNDAYbecause it would be in the future, which is - in US notion - the next week already.

Upvotes: 3

Related Questions