001/* 002 * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos 003 * 004 * All rights reserved. 005 * 006 * Redistribution and use in source and binary forms, with or without 007 * modification, are permitted provided that the following conditions are met: 008 * 009 * * Redistributions of source code must retain the above copyright notice, 010 * this list of conditions and the following disclaimer. 011 * 012 * * Redistributions in binary form must reproduce the above copyright notice, 013 * this list of conditions and the following disclaimer in the documentation 014 * and/or other materials provided with the distribution. 015 * 016 * * Neither the name of JSR-310 nor the names of its contributors 017 * may be used to endorse or promote products derived from this software 018 * without specific prior written permission. 019 * 020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 021 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 023 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 031 */ 032package org.threeten.bp.temporal; 033 034import java.util.Locale; 035 036import org.threeten.bp.format.TextStyle; 037 038/** 039 * An era of the time-line. 040 * <p> 041 * Most calendar systems have a single epoch dividing the time-line into two eras. 042 * However, some calendar systems, have multiple eras, such as one for the reign 043 * of each leader. 044 * In all cases, the era is conceptually the largest division of the time-line. 045 * Each chronology defines the Era's that are known Eras and a 046 * {@link Chrono#eras Chrono.eras} to get the valid eras. 047 * <p> 048 * For example, the Thai Buddhist calendar system divides time into two eras, 049 * before and after a single date. By contrast, the Japanese calendar system 050 * has one era for the reign of each Emperor. 051 * <p> 052 * Instances of {@code Era} may be compared using the {@code ==} operator. 053 * 054 * <h3>Specification for implementors</h3> 055 * This interface must be implemented with care to ensure other classes operate correctly. 056 * All implementations must be singletons - final, immutable and thread-safe. 057 * It is recommended to use an enum whenever possible. 058 * 059 * @param <C> the chronology of the era 060 */ 061public interface Era<C extends Chrono<C>> extends TemporalAccessor, TemporalAdjuster { 062 063 /** 064 * Gets the numeric value associated with the era as defined by the chronology. 065 * Each chronology defines the predefined Eras and methods to list the Eras 066 * of the chronology. 067 * <p> 068 * All fields, including eras, have an associated numeric value. 069 * The meaning of the numeric value for era is determined by the chronology 070 * according to these principles: 071 * <p><ul> 072 * <li>The era in use at the epoch 1970-01-01 (ISO) has the value 1. 073 * <li>Later eras have sequentially higher values. 074 * <li>Earlier eras have sequentially lower values, which may be negative. 075 * </ul><p> 076 * 077 * @return the numeric era value 078 */ 079 int getValue(); 080 081 /** 082 * Gets the chronology of this era. 083 * <p> 084 * The {@code Chrono} represents the calendar system in use. 085 * This always returns the standard form of the chronology. 086 * 087 * @return the chronology, not null 088 */ 089 C getChrono(); 090 091 //----------------------------------------------------------------------- 092 /** 093 * Obtains a date in this era given the year-of-era, month, and day. 094 * <p> 095 * This era is combined with the given date fields to form a date. 096 * The year specified must be the year-of-era. 097 * Methods to create a date from the proleptic-year are on {@code Chrono}. 098 * This always uses the standard form of the chronology. 099 * 100 * @param yearOfEra the calendar system year-of-era 101 * @param month the calendar system month-of-year 102 * @param day the calendar system day-of-month 103 * @return a local date based on this era and the specified year-of-era, month and day 104 */ 105 ChronoLocalDate<C> date(int yearOfEra, int month, int day); 106 107 /** 108 * Obtains a date in this era given year-of-era and day-of-year fields. 109 * <p> 110 * This era is combined with the given date fields to form a date. 111 * The year specified must be the year-of-era. 112 * Methods to create a date from the proleptic-year are on {@code Chrono}. 113 * This always uses the standard form of the chronology. 114 * 115 * @param yearOfEra the calendar system year-of-era 116 * @param dayOfYear the calendar system day-of-year 117 * @return a local date based on this era and the specified year-of-era and day-of-year 118 */ 119 ChronoLocalDate<C> dateYearDay(int yearOfEra, int dayOfYear); 120 121 //----------------------------------------------------------------------- 122 /** 123 * Gets the textual representation of this era. 124 * <p> 125 * This returns the textual name used to identify the era. 126 * The parameters control the style of the returned text and the locale. 127 * <p> 128 * If no textual mapping is found then the {@link #getValue() numeric value} is returned. 129 * 130 * @param style the style of the text required, not null 131 * @param locale the locale to use, not null 132 * @return the text value of the era, not null 133 */ 134 String getText(TextStyle style, Locale locale); 135 136 // NOTE: methods to convert year-of-era/proleptic-year cannot be here as they may depend on month/day (Japanese) 137}