package o; import java.io.InvalidObjectException; import java.io.Serializable; import java.util.GregorianCalendar; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.threeten.bp.DateTimeException; /* loaded from: classes6.dex */ public final class gtS implements Serializable { private static final ConcurrentMap CACHE = new ConcurrentHashMap(4, 0.75f, 2); public static final gtS ISO = new gtS(EnumC15515gsk.MONDAY, 4); public static final gtS SUNDAY_START = of(EnumC15515gsk.SUNDAY, 1); private static final long serialVersionUID = -1177360819670808121L; private final EnumC15515gsk firstDayOfWeek; private final int minimalDays; private final transient InterfaceC15537gtP dayOfWeek = RVV.ofDayOfWeekField(this); private final transient InterfaceC15537gtP weekOfMonth = RVV.ofWeekOfMonthField(this); private final transient InterfaceC15537gtP weekOfYear = RVV.ofWeekOfYearField(this); private final transient InterfaceC15537gtP weekOfWeekBasedYear = RVV.ofWeekOfWeekBasedYearField(this); private final transient InterfaceC15537gtP weekBasedYear = RVV.ofWeekBasedYearField(this); public static gtS of(Locale locale) { gtG.requireNonNull(locale, "locale"); return of(EnumC15515gsk.SUNDAY.plus(r4.getFirstDayOfWeek() - 1), new GregorianCalendar(new Locale(locale.getLanguage(), locale.getCountry())).getMinimalDaysInFirstWeek()); } public static gtS of(EnumC15515gsk enumC15515gsk, int i) { StringBuilder sb = new StringBuilder(); sb.append(enumC15515gsk.toString()); sb.append(i); String obj = sb.toString(); ConcurrentMap concurrentMap = CACHE; gtS gts = concurrentMap.get(obj); if (gts != null) { return gts; } concurrentMap.putIfAbsent(obj, new gtS(enumC15515gsk, i)); return concurrentMap.get(obj); } private gtS(EnumC15515gsk enumC15515gsk, int i) { gtG.requireNonNull(enumC15515gsk, "firstDayOfWeek"); if (i <= 0 || i > 7) { throw new IllegalArgumentException("Minimal number of days is invalid"); } this.firstDayOfWeek = enumC15515gsk; this.minimalDays = i; } private Object readResolve() throws InvalidObjectException { try { return of(this.firstDayOfWeek, this.minimalDays); } catch (IllegalArgumentException e) { StringBuilder sb = new StringBuilder("Invalid WeekFields"); sb.append(e.getMessage()); throw new InvalidObjectException(sb.toString()); } } public final boolean equals(Object obj) { if (this == obj) { return true; } return (obj instanceof gtS) && hashCode() == obj.hashCode(); } public final int hashCode() { return (this.firstDayOfWeek.ordinal() * 7) + this.minimalDays; } public final String toString() { StringBuilder sb = new StringBuilder("WeekFields["); sb.append(this.firstDayOfWeek); sb.append(','); sb.append(this.minimalDays); sb.append(']'); return sb.toString(); } /* loaded from: classes6.dex */ static class RVV implements InterfaceC15537gtP { private final InterfaceC15539gtV baseUnit; private final String name; private final gtT range; private final InterfaceC15539gtV rangeUnit; private final gtS weekDef; private static final gtT DAY_OF_WEEK_RANGE = gtT.of(1, 7); private static final gtT WEEK_OF_MONTH_RANGE = gtT.of(0, 1, 4, 6); private static final gtT WEEK_OF_YEAR_RANGE = gtT.of(0, 1, 52, 54); private static final gtT WEEK_OF_WEEK_BASED_YEAR_RANGE = gtT.of(1, 52, 53); private static final gtT WEEK_BASED_YEAR_RANGE = EnumC15534gtD.YEAR.range(); @Override // o.InterfaceC15537gtP public boolean isDateBased() { return true; } @Override // o.InterfaceC15537gtP public boolean isTimeBased() { return false; } static RVV ofDayOfWeekField(gtS gts) { return new RVV("DayOfWeek", gts, gtH.DAYS, gtH.WEEKS, DAY_OF_WEEK_RANGE); } static RVV ofWeekOfMonthField(gtS gts) { return new RVV("WeekOfMonth", gts, gtH.WEEKS, gtH.MONTHS, WEEK_OF_MONTH_RANGE); } static RVV ofWeekOfYearField(gtS gts) { return new RVV("WeekOfYear", gts, gtH.WEEKS, gtH.YEARS, WEEK_OF_YEAR_RANGE); } static RVV ofWeekOfWeekBasedYearField(gtS gts) { return new RVV("WeekOfWeekBasedYear", gts, gtH.WEEKS, gtI.WEEK_BASED_YEARS, WEEK_OF_WEEK_BASED_YEAR_RANGE); } static RVV ofWeekBasedYearField(gtS gts) { return new RVV("WeekBasedYear", gts, gtI.WEEK_BASED_YEARS, gtH.FOREVER, WEEK_BASED_YEAR_RANGE); } private RVV(String str, gtS gts, InterfaceC15539gtV interfaceC15539gtV, InterfaceC15539gtV interfaceC15539gtV2, gtT gtt) { this.name = str; this.weekDef = gts; this.baseUnit = interfaceC15539gtV; this.rangeUnit = interfaceC15539gtV2; this.range = gtt; } @Override // o.InterfaceC15537gtP public long getFrom(gtK gtk) { int localizedWBY; int floorMod = gtG.floorMod(gtk.get(EnumC15534gtD.DAY_OF_WEEK) - this.weekDef.getFirstDayOfWeek().getValue(), 7) + 1; if (this.rangeUnit == gtH.WEEKS) { return floorMod; } if (this.rangeUnit == gtH.MONTHS) { int i = gtk.get(EnumC15534gtD.DAY_OF_MONTH); localizedWBY = computeWeek(startOfWeekOffset(i, floorMod), i); } else if (this.rangeUnit == gtH.YEARS) { int i2 = gtk.get(EnumC15534gtD.DAY_OF_YEAR); localizedWBY = computeWeek(startOfWeekOffset(i2, floorMod), i2); } else if (this.rangeUnit == gtI.WEEK_BASED_YEARS) { localizedWBY = localizedWOWBY(gtk); } else if (this.rangeUnit == gtH.FOREVER) { localizedWBY = localizedWBY(gtk); } else { throw new IllegalStateException("unreachable"); } return localizedWBY; } private int localizedDayOfWeek(gtK gtk, int i) { return gtG.floorMod(gtk.get(EnumC15534gtD.DAY_OF_WEEK) - i, 7) + 1; } private long localizedWeekOfMonth(gtK gtk, int i) { int i2 = gtk.get(EnumC15534gtD.DAY_OF_MONTH); return computeWeek(startOfWeekOffset(i2, i), i2); } private long localizedWeekOfYear(gtK gtk, int i) { int i2 = gtk.get(EnumC15534gtD.DAY_OF_YEAR); return computeWeek(startOfWeekOffset(i2, i), i2); } private int localizedWOWBY(gtK gtk) { int floorMod = gtG.floorMod(gtk.get(EnumC15534gtD.DAY_OF_WEEK) - this.weekDef.getFirstDayOfWeek().getValue(), 7) + 1; long localizedWeekOfYear = localizedWeekOfYear(gtk, floorMod); if (localizedWeekOfYear == 0) { return ((int) localizedWeekOfYear(gsR.from(gtk).date(gtk).minus(1L, (InterfaceC15539gtV) gtH.WEEKS), floorMod)) + 1; } if (localizedWeekOfYear >= 53) { if (localizedWeekOfYear >= computeWeek(startOfWeekOffset(gtk.get(EnumC15534gtD.DAY_OF_YEAR), floorMod), (gsF.isLeap((long) gtk.get(EnumC15534gtD.YEAR)) ? 366 : 365) + this.weekDef.getMinimalDaysInFirstWeek())) { return (int) (localizedWeekOfYear - (r6 - 1)); } } return (int) localizedWeekOfYear; } private int localizedWBY(gtK gtk) { int floorMod = gtG.floorMod(gtk.get(EnumC15534gtD.DAY_OF_WEEK) - this.weekDef.getFirstDayOfWeek().getValue(), 7) + 1; int i = gtk.get(EnumC15534gtD.YEAR); long localizedWeekOfYear = localizedWeekOfYear(gtk, floorMod); if (localizedWeekOfYear == 0) { return i - 1; } if (localizedWeekOfYear < 53) { return i; } return localizedWeekOfYear >= ((long) computeWeek(startOfWeekOffset(gtk.get(EnumC15534gtD.DAY_OF_YEAR), floorMod), (gsF.isLeap((long) i) ? 366 : 365) + this.weekDef.getMinimalDaysInFirstWeek())) ? i + 1 : i; } private int startOfWeekOffset(int i, int i2) { int floorMod = gtG.floorMod(i - i2, 7); return floorMod + 1 > this.weekDef.getMinimalDaysInFirstWeek() ? 7 - floorMod : -floorMod; } private int computeWeek(int i, int i2) { return ((i + 7) + (i2 - 1)) / 7; } @Override // o.InterfaceC15537gtP public R adjustInto(R r, long j) { int checkValidIntValue = this.range.checkValidIntValue(j, this); if (checkValidIntValue == r.get(this)) { return r; } if (this.rangeUnit == gtH.FOREVER) { int i = r.get(this.weekDef.weekOfWeekBasedYear); InterfaceC15536gtL plus = r.plus((long) ((j - r1) * 52.1775d), gtH.WEEKS); if (plus.get(this) > checkValidIntValue) { return (R) plus.minus(plus.get(this.weekDef.weekOfWeekBasedYear), gtH.WEEKS); } if (plus.get(this) < checkValidIntValue) { plus = plus.plus(2L, gtH.WEEKS); } R r2 = (R) plus.plus(i - plus.get(this.weekDef.weekOfWeekBasedYear), gtH.WEEKS); return r2.get(this) > checkValidIntValue ? (R) r2.minus(1L, gtH.WEEKS) : r2; } return (R) r.plus(checkValidIntValue - r1, this.baseUnit); } @Override // o.InterfaceC15537gtP public gtK resolve(Map map, gtK gtk, gtA gta) { long checkValidIntValue; gsJ date; long checkValidIntValue2; gsJ date2; long checkValidIntValue3; int localizedDayOfWeek; long localizedWeekOfYear; int value = this.weekDef.getFirstDayOfWeek().getValue(); if (this.rangeUnit == gtH.WEEKS) { map.put(EnumC15534gtD.DAY_OF_WEEK, Long.valueOf(gtG.floorMod((value - 1) + (this.range.checkValidIntValue(map.remove(this).longValue(), this) - 1), 7) + 1)); return null; } if (!map.containsKey(EnumC15534gtD.DAY_OF_WEEK)) { return null; } if (this.rangeUnit == gtH.FOREVER) { if (!map.containsKey(this.weekDef.weekOfWeekBasedYear)) { return null; } gsR from = gsR.from(gtk); int floorMod = gtG.floorMod(EnumC15534gtD.DAY_OF_WEEK.checkValidIntValue(map.get(EnumC15534gtD.DAY_OF_WEEK).longValue()) - value, 7); int checkValidIntValue4 = range().checkValidIntValue(map.get(this).longValue(), this); if (gta == gtA.LENIENT) { date2 = from.date(checkValidIntValue4, 1, this.weekDef.getMinimalDaysInFirstWeek()); checkValidIntValue3 = map.get(this.weekDef.weekOfWeekBasedYear).longValue(); localizedDayOfWeek = localizedDayOfWeek(date2, value); localizedWeekOfYear = localizedWeekOfYear(date2, localizedDayOfWeek); } else { date2 = from.date(checkValidIntValue4, 1, this.weekDef.getMinimalDaysInFirstWeek()); checkValidIntValue3 = this.weekDef.weekOfWeekBasedYear.range().checkValidIntValue(map.get(this.weekDef.weekOfWeekBasedYear).longValue(), this.weekDef.weekOfWeekBasedYear); localizedDayOfWeek = localizedDayOfWeek(date2, value); localizedWeekOfYear = localizedWeekOfYear(date2, localizedDayOfWeek); } gsJ plus = date2.plus(((checkValidIntValue3 - localizedWeekOfYear) * 7) + ((floorMod + 1) - localizedDayOfWeek), (InterfaceC15539gtV) gtH.DAYS); if (gta == gtA.STRICT && plus.getLong(this) != map.get(this).longValue()) { throw new DateTimeException("Strict mode rejected date parsed to a different year"); } map.remove(this); map.remove(this.weekDef.weekOfWeekBasedYear); map.remove(EnumC15534gtD.DAY_OF_WEEK); return plus; } if (!map.containsKey(EnumC15534gtD.YEAR)) { return null; } int floorMod2 = gtG.floorMod(EnumC15534gtD.DAY_OF_WEEK.checkValidIntValue(map.get(EnumC15534gtD.DAY_OF_WEEK).longValue()) - value, 7) + 1; int checkValidIntValue5 = EnumC15534gtD.YEAR.checkValidIntValue(map.get(EnumC15534gtD.YEAR).longValue()); gsR from2 = gsR.from(gtk); if (this.rangeUnit == gtH.MONTHS) { if (!map.containsKey(EnumC15534gtD.MONTH_OF_YEAR)) { return null; } long longValue = map.remove(this).longValue(); if (gta == gtA.LENIENT) { date = from2.date(checkValidIntValue5, 1, 1).plus(map.get(EnumC15534gtD.MONTH_OF_YEAR).longValue() - 1, (InterfaceC15539gtV) gtH.MONTHS); checkValidIntValue2 = ((longValue - localizedWeekOfMonth(date, localizedDayOfWeek(date, value))) * 7) + (floorMod2 - r0); } else { date = from2.date(checkValidIntValue5, EnumC15534gtD.MONTH_OF_YEAR.checkValidIntValue(map.get(EnumC15534gtD.MONTH_OF_YEAR).longValue()), 8); checkValidIntValue2 = ((this.range.checkValidIntValue(longValue, this) - localizedWeekOfMonth(date, localizedDayOfWeek(date, value))) * 7) + (floorMod2 - r0); } gsJ plus2 = date.plus(checkValidIntValue2, (InterfaceC15539gtV) gtH.DAYS); if (gta == gtA.STRICT && plus2.getLong(EnumC15534gtD.MONTH_OF_YEAR) != map.get(EnumC15534gtD.MONTH_OF_YEAR).longValue()) { throw new DateTimeException("Strict mode rejected date parsed to a different month"); } map.remove(this); map.remove(EnumC15534gtD.YEAR); map.remove(EnumC15534gtD.MONTH_OF_YEAR); map.remove(EnumC15534gtD.DAY_OF_WEEK); return plus2; } if (this.rangeUnit == gtH.YEARS) { long longValue2 = map.remove(this).longValue(); gsJ date3 = from2.date(checkValidIntValue5, 1, 1); if (gta == gtA.LENIENT) { checkValidIntValue = ((longValue2 - localizedWeekOfYear(date3, localizedDayOfWeek(date3, value))) * 7) + (floorMod2 - r0); } else { checkValidIntValue = ((this.range.checkValidIntValue(longValue2, this) - localizedWeekOfYear(date3, localizedDayOfWeek(date3, value))) * 7) + (floorMod2 - r0); } gsJ plus3 = date3.plus(checkValidIntValue, (InterfaceC15539gtV) gtH.DAYS); if (gta == gtA.STRICT && plus3.getLong(EnumC15534gtD.YEAR) != map.get(EnumC15534gtD.YEAR).longValue()) { throw new DateTimeException("Strict mode rejected date parsed to a different year"); } map.remove(this); map.remove(EnumC15534gtD.YEAR); map.remove(EnumC15534gtD.DAY_OF_WEEK); return plus3; } throw new IllegalStateException("unreachable"); } @Override // o.InterfaceC15537gtP public boolean isSupportedBy(gtK gtk) { if (!gtk.isSupported(EnumC15534gtD.DAY_OF_WEEK)) { return false; } if (this.rangeUnit == gtH.WEEKS) { return true; } if (this.rangeUnit == gtH.MONTHS) { return gtk.isSupported(EnumC15534gtD.DAY_OF_MONTH); } if (this.rangeUnit == gtH.YEARS) { return gtk.isSupported(EnumC15534gtD.DAY_OF_YEAR); } if (this.rangeUnit == gtI.WEEK_BASED_YEARS) { return gtk.isSupported(EnumC15534gtD.EPOCH_DAY); } if (this.rangeUnit == gtH.FOREVER) { return gtk.isSupported(EnumC15534gtD.EPOCH_DAY); } return false; } @Override // o.InterfaceC15537gtP public gtT rangeRefinedBy(gtK gtk) { EnumC15534gtD enumC15534gtD; if (this.rangeUnit == gtH.WEEKS) { return this.range; } if (this.rangeUnit == gtH.MONTHS) { enumC15534gtD = EnumC15534gtD.DAY_OF_MONTH; } else if (this.rangeUnit == gtH.YEARS) { enumC15534gtD = EnumC15534gtD.DAY_OF_YEAR; } else { if (this.rangeUnit == gtI.WEEK_BASED_YEARS) { return rangeWOWBY(gtk); } if (this.rangeUnit == gtH.FOREVER) { return gtk.range(EnumC15534gtD.YEAR); } throw new IllegalStateException("unreachable"); } int startOfWeekOffset = startOfWeekOffset(gtk.get(enumC15534gtD), gtG.floorMod(gtk.get(EnumC15534gtD.DAY_OF_WEEK) - this.weekDef.getFirstDayOfWeek().getValue(), 7) + 1); gtT range = gtk.range(enumC15534gtD); return gtT.of(computeWeek(startOfWeekOffset, (int) range.getMinimum()), computeWeek(startOfWeekOffset, (int) range.getMaximum())); } private gtT rangeWOWBY(gtK gtk) { while (true) { int floorMod = gtG.floorMod(gtk.get(EnumC15534gtD.DAY_OF_WEEK) - this.weekDef.getFirstDayOfWeek().getValue(), 7) + 1; long localizedWeekOfYear = localizedWeekOfYear(gtk, floorMod); if (localizedWeekOfYear == 0) { gtk = gsR.from(gtk).date(gtk).minus(2L, (InterfaceC15539gtV) gtH.WEEKS); } else { if (localizedWeekOfYear >= computeWeek(startOfWeekOffset(gtk.get(EnumC15534gtD.DAY_OF_YEAR), floorMod), (gsF.isLeap((long) gtk.get(EnumC15534gtD.YEAR)) ? 366 : 365) + this.weekDef.getMinimalDaysInFirstWeek())) { gtk = gsR.from(gtk).date(gtk).plus(2L, (InterfaceC15539gtV) gtH.WEEKS); } else { return gtT.of(1L, r0 - 1); } } } } @Override // o.InterfaceC15537gtP public String getDisplayName(Locale locale) { gtG.requireNonNull(locale, "locale"); return this.rangeUnit == gtH.YEARS ? "Week" : toString(); } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(this.name); sb.append("["); sb.append(this.weekDef.toString()); sb.append("]"); return sb.toString(); } @Override // o.InterfaceC15537gtP public gtT range() { return this.range; } @Override // o.InterfaceC15537gtP public InterfaceC15539gtV getRangeUnit() { return this.rangeUnit; } @Override // o.InterfaceC15537gtP public InterfaceC15539gtV getBaseUnit() { return this.baseUnit; } } public final InterfaceC15537gtP weekOfYear() { return this.weekOfYear; } public final InterfaceC15537gtP weekOfWeekBasedYear() { return this.weekOfWeekBasedYear; } public final InterfaceC15537gtP weekOfMonth() { return this.weekOfMonth; } public final InterfaceC15537gtP weekBasedYear() { return this.weekBasedYear; } public final int getMinimalDaysInFirstWeek() { return this.minimalDays; } public final EnumC15515gsk getFirstDayOfWeek() { return this.firstDayOfWeek; } public final InterfaceC15537gtP dayOfWeek() { return this.dayOfWeek; } }