• BaseCalendar


    BaseCalendar

    package sun.util.calendar;
    
    import java.util.TimeZone;
    import sun.util.calendar.AbstractCalendar;
    import sun.util.calendar.CalendarDate;
    import sun.util.calendar.CalendarUtils;
    import sun.util.calendar.BaseCalendar.Date;
    
    public abstract class BaseCalendar extends AbstractCalendar {
    	public static final int JANUARY = 1;
    	public static final int FEBRUARY = 2;
    	public static final int MARCH = 3;
    	public static final int APRIL = 4;
    	public static final int MAY = 5;
    	public static final int JUNE = 6;
    	public static final int JULY = 7;
    	public static final int AUGUST = 8;
    	public static final int SEPTEMBER = 9;
    	public static final int OCTOBER = 10;
    	public static final int NOVEMBER = 11;
    	public static final int DECEMBER = 12;
    	public static final int SUNDAY = 1;
    	public static final int MONDAY = 2;
    	public static final int TUESDAY = 3;
    	public static final int WEDNESDAY = 4;
    	public static final int THURSDAY = 5;
    	public static final int FRIDAY = 6;
    	public static final int SATURDAY = 7;
    	private static final int BASE_YEAR = 1970;
    	private static final int[] FIXED_DATES = new int[]{719163, 719528, 719893, 720259, 720624, 720989, 721354, 721720,
    			722085, 722450, 722815, 723181, 723546, 723911, 724276, 724642, 725007, 725372, 725737, 726103, 726468,
    			726833, 727198, 727564, 727929, 728294, 728659, 729025, 729390, 729755, 730120, 730486, 730851, 731216,
    			731581, 731947, 732312, 732677, 733042, 733408, 733773, 734138, 734503, 734869, 735234, 735599, 735964,
    			736330, 736695, 737060, 737425, 737791, 738156, 738521, 738886, 739252, 739617, 739982, 740347, 740713,
    			741078, 741443, 741808, 742174, 742539, 742904, 743269, 743635, 744000, 744365};
    	static final int[] DAYS_IN_MONTH = new int[]{31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    	static final int[] ACCUMULATED_DAYS_IN_MONTH = new int[]{-30, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304,
    			334};
    	static final int[] ACCUMULATED_DAYS_IN_MONTH_LEAP = new int[]{-30, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305,
    			335};
    
    	public boolean validate(CalendarDate arg0) {
    		Date arg1 = (Date) arg0;
    		if (arg1.isNormalized()) {
    			return true;
    		} else {
    			int arg2 = arg1.getMonth();
    			if (arg2 >= 1 && arg2 <= 12) {
    				int arg3 = arg1.getDayOfMonth();
    				if (arg3 > 0 && arg3 <= this.getMonthLength(arg1.getNormalizedYear(), arg2)) {
    					int arg4 = arg1.getDayOfWeek();
    					if (arg4 != Integer.MIN_VALUE && arg4 != this.getDayOfWeek(arg1)) {
    						return false;
    					} else if (!this.validateTime(arg0)) {
    						return false;
    					} else {
    						arg1.setNormalized(true);
    						return true;
    					}
    				} else {
    					return false;
    				}
    			} else {
    				return false;
    			}
    		}
    	}
    
    	public boolean normalize(CalendarDate arg0) {
    		if (arg0.isNormalized()) {
    			return true;
    		} else {
    			Date arg1 = (Date) arg0;
    			TimeZone arg2 = arg1.getZone();
    			if (arg2 != null) {
    				this.getTime(arg0);
    				return true;
    			} else {
    				int arg3 = this.normalizeTime(arg1);
    				this.normalizeMonth(arg1);
    				long arg4 = (long) arg1.getDayOfMonth() + (long) arg3;
    				int arg6 = arg1.getMonth();
    				int arg7 = arg1.getNormalizedYear();
    				int arg8 = this.getMonthLength(arg7, arg6);
    				if (arg4 > 0L && arg4 <= (long) arg8) {
    					arg1.setDayOfWeek(this.getDayOfWeek(arg1));
    				} else if (arg4 <= 0L && arg4 > -28L) {
    					--arg6;
    					arg8 = this.getMonthLength(arg7, arg6);
    					arg4 += (long) arg8;
    					arg1.setDayOfMonth((int) arg4);
    					if (arg6 == 0) {
    						arg6 = 12;
    						arg1.setNormalizedYear(arg7 - 1);
    					}
    
    					arg1.setMonth(arg6);
    				} else if (arg4 > (long) arg8 && arg4 < (long) (arg8 + 28)) {
    					arg4 -= (long) arg8;
    					++arg6;
    					arg1.setDayOfMonth((int) arg4);
    					if (arg6 > 12) {
    						arg1.setNormalizedYear(arg7 + 1);
    						arg6 = 1;
    					}
    
    					arg1.setMonth(arg6);
    				} else {
    					long arg9 = arg4 + this.getFixedDate(arg7, arg6, 1, arg1) - 1L;
    					this.getCalendarDateFromFixedDate(arg1, arg9);
    				}
    
    				arg0.setLeapYear(this.isLeapYear(arg1.getNormalizedYear()));
    				arg0.setZoneOffset(0);
    				arg0.setDaylightSaving(0);
    				arg1.setNormalized(true);
    				return true;
    			}
    		}
    	}
    
    	void normalizeMonth(CalendarDate arg0) {
    		Date arg1 = (Date) arg0;
    		int arg2 = arg1.getNormalizedYear();
    		long arg3 = (long) arg1.getMonth();
    		if (arg3 <= 0L) {
    			long arg5 = 1L - arg3;
    			arg2 -= (int) (arg5 / 12L + 1L);
    			arg3 = 13L - arg5 % 12L;
    			arg1.setNormalizedYear(arg2);
    			arg1.setMonth((int) arg3);
    		} else if (arg3 > 12L) {
    			arg2 += (int) ((arg3 - 1L) / 12L);
    			arg3 = (arg3 - 1L) % 12L + 1L;
    			arg1.setNormalizedYear(arg2);
    			arg1.setMonth((int) arg3);
    		}
    
    	}
    
    	public int getYearLength(CalendarDate arg0) {
    		return this.isLeapYear(((Date) arg0).getNormalizedYear()) ? 366 : 365;
    	}
    
    	public int getYearLengthInMonths(CalendarDate arg0) {
    		return 12;
    	}
    
    	public int getMonthLength(CalendarDate arg0) {
    		Date arg1 = (Date) arg0;
    		int arg2 = arg1.getMonth();
    		if (arg2 >= 1 && arg2 <= 12) {
    			return this.getMonthLength(arg1.getNormalizedYear(), arg2);
    		} else {
    			throw new IllegalArgumentException("Illegal month value: " + arg2);
    		}
    	}
    
    	private int getMonthLength(int arg0, int arg1) {
    		int arg2 = DAYS_IN_MONTH[arg1];
    		if (arg1 == 2 && this.isLeapYear(arg0)) {
    			++arg2;
    		}
    
    		return arg2;
    	}
    
    	public long getDayOfYear(CalendarDate arg0) {
    		return this.getDayOfYear(((Date) arg0).getNormalizedYear(), arg0.getMonth(), arg0.getDayOfMonth());
    	}
    
    	final long getDayOfYear(int arg0, int arg1, int arg2) {
    		return (long) arg2 + (long) (this.isLeapYear(arg0)
    				? ACCUMULATED_DAYS_IN_MONTH_LEAP[arg1]
    				: ACCUMULATED_DAYS_IN_MONTH[arg1]);
    	}
    
    	public long getFixedDate(CalendarDate arg0) {
    		if (!arg0.isNormalized()) {
    			this.normalizeMonth(arg0);
    		}
    
    		return this.getFixedDate(((Date) arg0).getNormalizedYear(), arg0.getMonth(), arg0.getDayOfMonth(), (Date) arg0);
    	}
    
    	public long getFixedDate(int arg0, int arg1, int arg2, Date arg3) {
    		boolean arg4 = arg1 == 1 && arg2 == 1;
    		if (arg3 != null && arg3.hit(arg0)) {
    			return arg4 ? arg3.getCachedJan1() : arg3.getCachedJan1() + this.getDayOfYear(arg0, arg1, arg2) - 1L;
    		} else {
    			int arg5 = arg0 - 1970;
    			long arg6;
    			if (arg5 >= 0 && arg5 < FIXED_DATES.length) {
    				arg6 = (long) FIXED_DATES[arg5];
    				if (arg3 != null) {
    					arg3.setCache(arg0, arg6, this.isLeapYear(arg0) ? 366 : 365);
    				}
    
    				return arg4 ? arg6 : arg6 + this.getDayOfYear(arg0, arg1, arg2) - 1L;
    			} else {
    				arg6 = (long) arg0 - 1L;
    				long arg8 = (long) arg2;
    				if (arg6 >= 0L) {
    					arg8 += 365L * arg6 + arg6 / 4L - arg6 / 100L + arg6 / 400L + (long) ((367 * arg1 - 362) / 12);
    				} else {
    					arg8 += 365L * arg6 + CalendarUtils.floorDivide(arg6, 4L) - CalendarUtils.floorDivide(arg6, 100L)
    							+ CalendarUtils.floorDivide(arg6, 400L)
    							+ (long) CalendarUtils.floorDivide(367 * arg1 - 362, 12);
    				}
    
    				if (arg1 > 2) {
    					arg8 -= this.isLeapYear(arg0) ? 1L : 2L;
    				}
    
    				if (arg3 != null && arg4) {
    					arg3.setCache(arg0, arg8, this.isLeapYear(arg0) ? 366 : 365);
    				}
    
    				return arg8;
    			}
    		}
    	}
    
    	public void getCalendarDateFromFixedDate(CalendarDate arg0, long arg1) {
    		Date arg3 = (Date) arg0;
    		int arg4;
    		long arg5;
    		boolean arg7;
    		if (arg3.hit(arg1)) {
    			arg4 = arg3.getCachedYear();
    			arg5 = arg3.getCachedJan1();
    			arg7 = this.isLeapYear(arg4);
    		} else {
    			arg4 = this.getGregorianYearFromFixedDate(arg1);
    			arg5 = this.getFixedDate(arg4, 1, 1, (Date) null);
    			arg7 = this.isLeapYear(arg4);
    			arg3.setCache(arg4, arg5, arg7 ? 366 : 365);
    		}
    
    		int arg8 = (int) (arg1 - arg5);
    		long arg9 = arg5 + 31L + 28L;
    		if (arg7) {
    			++arg9;
    		}
    
    		if (arg1 >= arg9) {
    			arg8 += arg7 ? 1 : 2;
    		}
    
    		int arg11 = 12 * arg8 + 373;
    		if (arg11 > 0) {
    			arg11 /= 367;
    		} else {
    			arg11 = CalendarUtils.floorDivide(arg11, 367);
    		}
    
    		long arg12 = arg5 + (long) ACCUMULATED_DAYS_IN_MONTH[arg11];
    		if (arg7 && arg11 >= 3) {
    			++arg12;
    		}
    
    		int arg14 = (int) (arg1 - arg12) + 1;
    		int arg15 = getDayOfWeekFromFixedDate(arg1);
    
    		assert arg15 > 0 : "negative day of week " + arg15;
    
    		arg3.setNormalizedYear(arg4);
    		arg3.setMonth(arg11);
    		arg3.setDayOfMonth(arg14);
    		arg3.setDayOfWeek(arg15);
    		arg3.setLeapYear(arg7);
    		arg3.setNormalized(true);
    	}
    
    	public int getDayOfWeek(CalendarDate arg0) {
    		long arg1 = this.getFixedDate(arg0);
    		return getDayOfWeekFromFixedDate(arg1);
    	}
    
    	public static final int getDayOfWeekFromFixedDate(long arg) {
    		return arg >= 0L ? (int) (arg % 7L) + 1 : (int) CalendarUtils.mod(arg, 7L) + 1;
    	}
    
    	public int getYearFromFixedDate(long arg0) {
    		return this.getGregorianYearFromFixedDate(arg0);
    	}
    
    	final int getGregorianYearFromFixedDate(long arg0) {
    		long arg2;
    		int arg4;
    		int arg5;
    		int arg6;
    		int arg7;
    		int arg8;
    		int arg9;
    		int arg10;
    		int arg11;
    		if (arg0 > 0L) {
    			arg2 = arg0 - 1L;
    			arg8 = (int) (arg2 / 146097L);
    			arg4 = (int) (arg2 % 146097L);
    			arg9 = arg4 / '躬';
    			arg5 = arg4 % '躬';
    			arg10 = arg5 / 1461;
    			arg6 = arg5 % 1461;
    			arg11 = arg6 / 365;
    			arg7 = arg6 % 365 + 1;
    		} else {
    			arg2 = arg0 - 1L;
    			arg8 = (int) CalendarUtils.floorDivide(arg2, 146097L);
    			arg4 = (int) CalendarUtils.mod(arg2, 146097L);
    			arg9 = CalendarUtils.floorDivide(arg4, '躬');
    			arg5 = CalendarUtils.mod(arg4, '躬');
    			arg10 = CalendarUtils.floorDivide(arg5, 1461);
    			arg6 = CalendarUtils.mod(arg5, 1461);
    			arg11 = CalendarUtils.floorDivide(arg6, 365);
    			arg7 = CalendarUtils.mod(arg6, 365) + 1;
    		}
    
    		int arg12 = 400 * arg8 + 100 * arg9 + 4 * arg10 + arg11;
    		if (arg9 != 4 && arg11 != 4) {
    			++arg12;
    		}
    
    		return arg12;
    	}
    
    	protected boolean isLeapYear(CalendarDate arg0) {
    		return this.isLeapYear(((Date) arg0).getNormalizedYear());
    	}
    
    	boolean isLeapYear(int arg0) {
    		return CalendarUtils.isGregorianLeapYear(arg0);
    	}
    }
    

      

    ##################

  • 相关阅读:
    Docker的load,save和import,export的区别
    LeetCode 146. LRU 缓存机制
    mongoTemplate怎么获取MongoDB自动生成的主键_id
    $ajax()或$.get()中的请求成功时运行的函数success无法执行的解决办法
    使用$.get()请求controller出现 http://localhost:8080/../[object%20Object] 错误的问题解决
    Java利用Runtime调用Python脚本
    SpringMVC返回对象类型报错HttpMessageNotWritableException: No converter found for return value of type
    「题解」洛谷 P1801 黑匣子
    「题解」洛谷 P1717 钓鱼
    「题解」洛谷 P2571 [SCOI2010]传送带
  • 原文地址:https://www.cnblogs.com/herd/p/16268451.html
Copyright © 2020-2023  润新知