jdk/src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java
author chegar
Mon, 18 Aug 2014 10:59:36 +0100
changeset 25991 e48157b42439
parent 25966 jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java@71ee1f15845e
parent 25859 jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java@3317bb8137f4
child 37593 824750ada3d6
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.util.calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    28
import java.security.AccessController;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author Masayoshi Okutsu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class LocalGregorianCalendar extends BaseCalendar {
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    38
    private static final Era[] JAPANESE_ERAS = {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    39
        new Era("Meiji",  "M", -3218832000000L, true),
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    40
        new Era("Taisho", "T", -1812153600000L, true),
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    41
        new Era("Showa",  "S", -1357603200000L, true),
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    42
        new Era("Heisei", "H",   600220800000L, true),
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    43
    };
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    44
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    45
    private static boolean isValidEra(Era newEra, Era[] eras) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    46
        Era last = eras[eras.length - 1];
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    47
        if (last.getSinceDate().getYear() >= newEra.getSinceDate().getYear()) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    48
            return false;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    49
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    50
        // The new era name should be unique. Its abbr may not.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    51
        String newName = newEra.getName();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    52
        for (Era era : eras) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    53
            if (era.getName().equals(newName)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    54
                return false;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    55
            }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    56
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    57
        return true;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    58
    }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private Era[] eras;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static class Date extends BaseCalendar.Date {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        protected Date() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        protected Date(TimeZone zone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            super(zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        private int gregorianYear = FIELD_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    75
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public Date setEra(Era era) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            if (getEra() != era) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                super.setEra(era);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                gregorianYear = FIELD_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    84
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        public Date addYear(int localYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            super.addYear(localYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            gregorianYear += localYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    91
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        public Date setYear(int localYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (getYear() != localYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                super.setYear(localYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                gregorianYear = FIELD_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   100
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        public int getNormalizedYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return gregorianYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   105
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public void setNormalizedYear(int normalizedYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            this.gregorianYear = normalizedYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        void setLocalEra(Era era) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            super.setEra(era);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        void setLocalYear(int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            super.setYear(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   118
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            String time = super.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            time = time.substring(time.indexOf('T'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            Era era = getEra();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (era != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                String abbr = era.getAbbreviation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                if (abbr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    sb.append(abbr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            sb.append(getYear()).append('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            CalendarUtils.sprintf0d(sb, getMonth(), 2).append('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            CalendarUtils.sprintf0d(sb, getDayOfMonth(), 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            sb.append(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    static LocalGregorianCalendar getLocalGregorianCalendar(String name) {
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   139
        // Only the Japanese calendar is supported.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   140
        if (!"japanese".equals(name)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   143
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   144
        // Append an era to the predefined eras if it's given by the property.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   145
        String prop = AccessController.doPrivileged(
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   146
                new sun.security.action.GetPropertyAction("jdk.calendar.japanese.supplemental.era"));
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   147
        if (prop != null) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   148
            Era era = parseEraEntry(prop);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   149
            if (era != null) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   150
                if (isValidEra(era, JAPANESE_ERAS)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   151
                    int length = JAPANESE_ERAS.length;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   152
                    Era[] eras = new Era[length + 1];
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   153
                    System.arraycopy(JAPANESE_ERAS, 0, eras, 0, length);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   154
                    eras[length] = era;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   155
                    return new LocalGregorianCalendar(name, eras);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   156
                }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   157
            }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   158
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   159
        return new LocalGregorianCalendar(name, JAPANESE_ERAS);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   160
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   162
    private static Era parseEraEntry(String entry) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   163
        String[] keyValuePairs = entry.split(",");
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   164
        String eraName = null;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   165
        boolean localTime = true;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   166
        long since = 0;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   167
        String abbr = null;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   168
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   169
        for (String item : keyValuePairs) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   170
            String[] keyvalue = item.split("=");
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   171
            if (keyvalue.length != 2) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   172
                return null;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   173
            }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   174
            String key = keyvalue[0].trim();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   175
            String value = keyvalue[1].trim();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   176
            switch (key) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   177
            case "name":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   178
                eraName = value;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   179
                break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   180
            case "since":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   181
                if (value.endsWith("u")) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   182
                    localTime = false;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   183
                    value = value.substring(0, value.length() - 1);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   184
                }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   185
                try {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   186
                    since = Long.parseLong(value);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   187
                } catch (NumberFormatException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                }
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   190
                break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   191
            case "abbr":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   192
                abbr = value;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   193
                break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   194
            default:
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   195
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   198
        if (eraName == null || eraName.isEmpty()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   199
                || abbr == null || abbr.isEmpty()) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   200
            return null;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   201
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   202
        return new Era(eraName, abbr, since, localTime);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private LocalGregorianCalendar(String name, Era[] eras) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        this.eras = eras;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        setEras(eras);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   211
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   216
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public Date getCalendarDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return getCalendarDate(System.currentTimeMillis(), newCalendarDate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   221
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public Date getCalendarDate(long millis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return getCalendarDate(millis, newCalendarDate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   226
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public Date getCalendarDate(long millis, TimeZone zone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return getCalendarDate(millis, newCalendarDate(zone));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   231
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public Date getCalendarDate(long millis, CalendarDate date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        Date ldate = (Date) super.getCalendarDate(millis, date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return adjustYear(ldate, millis, ldate.getZoneOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private Date adjustYear(Date ldate, long millis, int zoneOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        for (i = eras.length - 1; i >= 0; --i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            Era era = eras[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            long since = era.getSince(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (era.isLocalTime()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                since -= zoneOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (millis >= since) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                ldate.setLocalEra(era);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                int y = ldate.getNormalizedYear() - era.getSinceDate().getYear() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                ldate.setLocalYear(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (i < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            ldate.setLocalEra(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            ldate.setLocalYear(ldate.getNormalizedYear());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        ldate.setNormalized(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return ldate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   260
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public Date newCalendarDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return new Date();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   265
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public Date newCalendarDate(TimeZone zone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return new Date(zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   270
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public boolean validate(CalendarDate date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        Date ldate = (Date) date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        Era era = ldate.getEra();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (era != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (!validateEra(era)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   278
            ldate.setNormalizedYear(era.getSinceDate().getYear() + ldate.getYear() - 1);
17474
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   279
            Date tmp = newCalendarDate(date.getZone());
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   280
            tmp.setEra(era).setDate(date.getYear(), date.getMonth(), date.getDayOfMonth());
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   281
            normalize(tmp);
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   282
            if (tmp.getEra() != era) {
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   283
                return false;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   284
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } else {
17474
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   286
            if (date.getYear() >= eras[0].getSinceDate().getYear()) {
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   287
                return false;
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
   288
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            ldate.setNormalizedYear(ldate.getYear());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return super.validate(ldate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private boolean validateEra(Era era) {
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   295
        for (Era era1 : eras) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   296
            if (era == era1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   303
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public boolean normalize(CalendarDate date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (date.isNormalized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        normalizeYear(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        Date ldate = (Date) date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // Normalize it as a Gregorian date and get its millisecond value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        super.normalize(ldate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        boolean hasMillis = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        long millis = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        int year = ldate.getNormalizedYear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        Era era = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        for (i = eras.length - 1; i >= 0; --i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            era = eras[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (era.isLocalTime()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                CalendarDate sinceDate = era.getSinceDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                int sinceYear = sinceDate.getYear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                if (year > sinceYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                if (year == sinceYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    int month = ldate.getMonth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    int sinceMonth = sinceDate.getMonth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    if (month > sinceMonth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    if (month == sinceMonth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        int day = ldate.getDayOfMonth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        int sinceDay = sinceDate.getDayOfMonth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                        if (day > sinceDay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        if (day == sinceDay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                            long timeOfDay = ldate.getTimeOfDay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                            long sinceTimeOfDay = sinceDate.getTimeOfDay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                            if (timeOfDay >= sinceTimeOfDay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                            --i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                if (!hasMillis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    millis  = super.getTime(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    hasMillis = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                long since = era.getSince(date.getZone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                if (millis >= since) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            ldate.setLocalEra(era);
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents: 17474
diff changeset
   365
            @SuppressWarnings("null")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            int y = ldate.getNormalizedYear() - era.getSinceDate().getYear() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            ldate.setLocalYear(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            // Set Gregorian year with no era
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            ldate.setEra(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            ldate.setLocalYear(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            ldate.setNormalizedYear(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        ldate.setNormalized(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   378
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    void normalizeMonth(CalendarDate date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        normalizeYear(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        super.normalizeMonth(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    void normalizeYear(CalendarDate date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        Date ldate = (Date) date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // Set the supposed-to-be-correct Gregorian year first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // e.g., Showa 90 becomes 2015 (1926 + 90 - 1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        Era era = ldate.getEra();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (era == null || !validateEra(era)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            ldate.setNormalizedYear(ldate.getYear());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            ldate.setNormalizedYear(era.getSinceDate().getYear() + ldate.getYear() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Returns whether the specified Gregorian year is a leap year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see #isLeapYear(Era, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   400
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public boolean isLeapYear(int gregorianYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        return CalendarUtils.isGregorianLeapYear(gregorianYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public boolean isLeapYear(Era era, int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (era == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return isLeapYear(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        int gyear = era.getSinceDate().getYear() + year - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return isLeapYear(gyear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
   413
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public void getCalendarDateFromFixedDate(CalendarDate date, long fixedDate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        Date ldate = (Date) date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        super.getCalendarDateFromFixedDate(ldate, fixedDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        adjustYear(ldate, (fixedDate - EPOCH_OFFSET) * DAY_IN_MILLIS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
}