src/share/classes/sun/util/calendar/LocalGregorianCalendar.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 23,38 **** * questions. */ package sun.util.calendar; - import java.io.File; - import java.io.FileInputStream; import java.io.IOException; - import java.security.AccessController; - import java.security.PrivilegedActionException; - import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.StringTokenizer; import java.util.TimeZone; --- 23,33 ----
*** 57,92 **** --- 52,92 ---- super(zone); } private int gregorianYear = FIELD_UNDEFINED; + @Override public Date setEra(Era era) { if (getEra() != era) { super.setEra(era); gregorianYear = FIELD_UNDEFINED; } return this; } + @Override public Date addYear(int localYear) { super.addYear(localYear); gregorianYear += localYear; return this; } + @Override public Date setYear(int localYear) { if (getYear() != localYear) { super.setYear(localYear); gregorianYear = FIELD_UNDEFINED; } return this; } + @Override public int getNormalizedYear() { return gregorianYear; } + @Override public void setNormalizedYear(int normalizedYear) { this.gregorianYear = normalizedYear; } void setLocalEra(Era era) {
*** 95,104 **** --- 95,105 ---- void setLocalYear(int year) { super.setYear(year); } + @Override public String toString() { String time = super.toString(); time = time.substring(time.indexOf('T')); StringBuffer sb = new StringBuffer(); Era era = getEra();
*** 115,143 **** return sb.toString(); } } static LocalGregorianCalendar getLocalGregorianCalendar(String name) { ! Properties calendarProps = null; try { ! String homeDir = AccessController.doPrivileged( ! new sun.security.action.GetPropertyAction("java.home")); ! final String fname = homeDir + File.separator + "lib" + File.separator ! + "calendars.properties"; ! calendarProps = AccessController.doPrivileged(new PrivilegedExceptionAction<Properties>() { ! public Properties run() throws IOException { ! Properties props = new Properties(); ! try (FileInputStream fis = new FileInputStream(fname)) { ! props.load(fis); ! } ! return props; ! } ! }); ! } catch (PrivilegedActionException e) { ! throw new RuntimeException(e.getException()); } - // Parse calendar.*.eras String props = calendarProps.getProperty("calendar." + name + ".eras"); if (props == null) { return null; } --- 116,131 ---- return sb.toString(); } } static LocalGregorianCalendar getLocalGregorianCalendar(String name) { ! Properties calendarProps; try { ! calendarProps = CalendarSystem.getCalendarProperties(); ! } catch (IOException | IllegalArgumentException e) { ! throw new InternalError(e); } // Parse calendar.*.eras String props = calendarProps.getProperty("calendar." + name + ".eras"); if (props == null) { return null; }
*** 188,213 **** --- 176,206 ---- this.name = name; this.eras = eras; setEras(eras); } + @Override public String getName() { return name; } + @Override public Date getCalendarDate() { return getCalendarDate(System.currentTimeMillis(), newCalendarDate()); } + @Override public Date getCalendarDate(long millis) { return getCalendarDate(millis, newCalendarDate()); } + @Override public Date getCalendarDate(long millis, TimeZone zone) { return getCalendarDate(millis, newCalendarDate(zone)); } + @Override public Date getCalendarDate(long millis, CalendarDate date) { Date ldate = (Date) super.getCalendarDate(millis, date); return adjustYear(ldate, millis, ldate.getZoneOffset()); }
*** 232,257 **** } ldate.setNormalized(true); return ldate; } public Date newCalendarDate() { return new Date(); } public Date newCalendarDate(TimeZone zone) { return new Date(zone); } public boolean validate(CalendarDate date) { Date ldate = (Date) date; Era era = ldate.getEra(); if (era != null) { if (!validateEra(era)) { return false; } ! ldate.setNormalizedYear(era.getSinceDate().getYear() + ldate.getYear()); } else { ldate.setNormalizedYear(ldate.getYear()); } return super.validate(ldate); } --- 225,262 ---- } ldate.setNormalized(true); return ldate; } + @Override public Date newCalendarDate() { return new Date(); } + @Override public Date newCalendarDate(TimeZone zone) { return new Date(zone); } + @Override public boolean validate(CalendarDate date) { Date ldate = (Date) date; Era era = ldate.getEra(); if (era != null) { if (!validateEra(era)) { return false; } ! ldate.setNormalizedYear(era.getSinceDate().getYear() + ldate.getYear() - 1); ! // If it's not the last Era, validate the date. ! if (era != eras[eras.length - 1]) { ! Date tmp = newCalendarDate(date.getZone()); ! tmp.setEra(era).setDate(date.getYear(), date.getMonth(), date.getDayOfMonth()); ! normalize(tmp); ! if (tmp.getEra() != era) { ! return false; ! } ! } } else { ldate.setNormalizedYear(ldate.getYear()); } return super.validate(ldate); }
*** 264,273 **** --- 269,279 ---- } } return false; } + @Override public boolean normalize(CalendarDate date) { if (date.isNormalized()) { return true; }
*** 337,346 **** --- 343,353 ---- } ldate.setNormalized(true); return true; } + @Override void normalizeMonth(CalendarDate date) { normalizeYear(date); super.normalizeMonth(date); }
*** 358,367 **** --- 365,375 ---- /** * Returns whether the specified Gregorian year is a leap year. * @see #isLeapYear(Era, int) */ + @Override public boolean isLeapYear(int gregorianYear) { return CalendarUtils.isGregorianLeapYear(gregorianYear); } public boolean isLeapYear(Era era, int year) {
*** 370,379 **** --- 378,388 ---- } int gyear = era.getSinceDate().getYear() + year - 1; return isLeapYear(gyear); } + @Override public void getCalendarDateFromFixedDate(CalendarDate date, long fixedDate) { Date ldate = (Date) date; super.getCalendarDateFromFixedDate(ldate, fixedDate); adjustYear(ldate, (fixedDate - EPOCH_OFFSET) * DAY_IN_MILLIS, 0); }