Start of week for locale using Joda-Time

后端 未结 7 2151
旧时难觅i
旧时难觅i 2020-11-28 10:20

How do you determine which day of the week is considered the “start” according to a given Locale using Joda-Time?

Point: Most countries use the international standard

7条回答
  •  庸人自扰
    2020-11-28 10:48

    Here is how one might work around Joda time to get the U.S. first day of the week:

    DateTime getFirstDayOfWeek(DateTime other) {
      if(other.dayOfWeek.get == 7)
        return other;
      else
        return other.minusWeeks(1).withDayOfWeek(7);
    }
    

    Or in Scala

    def getFirstDayOfWeek(other: DateTime) = other.dayOfWeek.get match {
        case 7 => other
        case _ => other.minusWeeks(1).withDayOfWeek(7)
    }
    

提交回复
热议问题