net.time4j.Weekcycle Maven / Gradle / Ivy
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2016 Meno Hochschild,
* -----------------------------------------------------------------------
* This file (Weekcycle.java) is part of project Time4J.
*
* Time4J is free software: You can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* Time4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Time4J. If not, see .
* -----------------------------------------------------------------------
*/
package net.time4j;
import net.time4j.engine.BasicUnit;
import net.time4j.engine.ChronoEntity;
import net.time4j.engine.Chronology;
import net.time4j.engine.UnitRule;
import java.io.ObjectStreamException;
import java.io.Serializable;
import static net.time4j.PlainDate.CALENDAR_DATE;
/**
* Represents a special unit for week-based years which are described by ISO-8601 and
* follow the week cycle from Monday to Sunday.
*
* @author Meno Hochschild
* @since 3.21/4.17
* @doctags.concurrency {immutable}
*/
/*[deutsch]
* Repräsentiert eine Spezialeinheit für wochenbasierte Jahre, die von ISO-8601
* beschrieben sind und immer dem Wochenzyklus von Montag bis Sonntag folgen.
*
* @author Meno Hochschild
* @since 3.21/4.17
* @doctags.concurrency {immutable}
*/
public final class Weekcycle
extends BasicUnit
implements IsoDateUnit, Serializable {
//~ Statische Felder/Initialisierungen --------------------------------
/**
* Constant for week-based years which either have 364 or 371 days.
*/
/*[deutsch]
* Konstante für wochenbasierte Jahre, die entweder 364 oder 371 Tage haben.
*/
public static final Weekcycle YEARS = new Weekcycle();
private static final long serialVersionUID = -4981215347844372171L;
//~ Konstruktoren -----------------------------------------------------
private Weekcycle() {
// singleton
}
//~ Methoden ----------------------------------------------------------
/**
* Calculates the temporal distance between given calendar dates
* in this calendar unit.
*
* @param start starting date
* @param end ending date
* @return duration as count of this unit
*/
/*[deutsch]
* Ermittelt den zeitlichen Abstand zwischen den angegebenen
* Datumsangaben gemessen in dieser Einheit.
*
* @param start starting date
* @param end ending date
* @return duration as count of this unit
*/
public long between(
PlainDate start,
PlainDate end
) {
return this.derive(start).between(start, end);
}
@Override
public char getSymbol() {
return 'Y';
}
@Override
public double getLength() {
return CalendarUnit.YEARS.getLength(); // same average length as for gregorian years
}
@Override
public boolean isCalendrical() {
return true;
}
@Override
public String toString() {
return "WEEK_BASED_YEARS";
}
@Override
protected > UnitRule derive(Chronology chronology) {
if (chronology.isRegistered(CALENDAR_DATE)) {
return YOWElement.unitRule();
}
return null;
}
private Object readResolve() throws ObjectStreamException {
return YEARS;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy