Okay, I ve与优异的Jodatime图书馆相距甚远,试图实施一个普通的零售/信托(4-5-4)日历。 我已经找到了我公司的具体案例,但一般案件(主要是确定年初和租赁年份)是杀手;例如,有一套日期,即两个财政年度(通常为364天)将在1个标准化组织年度内开始。
在确定年度启动规则的过程中,我最后总结出一个抽象的类别和两个确定年份的具体类别,其依据是国际标准化组织的起始日。
(四舍五入)
private static abstract class SimpleFiscalYearEndPattern implements FiscalYearEndPattern {
protected final int leapYearCountOffset;
protected final int doomsdayOffset;
private final int startingDayOfWeek;
private final int yearOffset;
private final long millisFromEpochToFiscalYearStart;
private final long millisElapsedToEpochDividedByTwo;
/**
* Restricted constructor
* @param fiscalYear
* @param startingOn
* @param inFirstWeek
*/
protected SimpleFiscalYearEndPattern(final int fiscalYear, final LocalDate startingOn, final MonthDay inFirstWeek) {
this.yearOffset = fiscalYear - startingOn.getYear();
this.doomsdayOffset = getDoomsdayOffset(inFirstWeek);
this.startingDayOfWeek = startingOn.getDayOfWeek();
final int startingDoomsday = getDoomsdayOffset(new MonthDay(startingOn, REFERENCE_CHRONOLOGY));
// If the starting doomsday is a later day-of-week, it needs to become negative.
this.leapYearCountOffset = calculateLeapYearCountOffset(startingDoomsday : doomsdayOffset, doomsdayOffset);
final int leapYearsBefore = getPreviousLeapYears(fiscalYearBeforeEpoch);
}
}
具体类别(日期: 1/7 - 2/28):
private static final class BeforeLeapYearEndPattern extends SimpleFiscalYearEndPattern {
private static final int FIRST_YEAR_LEAP_YEAR_OFFSET = -1;
private BeforeLeapYearEndPattern(final int fiscalYear, final LocalDate startingOn, final MonthDay onOrBefore) {
super(fiscalYear, startingOn, onOrBefore);
}
public static final BeforeLeapYearEndPattern create(final int fiscalYear, final LocalDate startingOn, final MonthDay onOrBefore) {
return new BeforeLeapYearEndPattern(fiscalYear, startingOn, onOrBefore);
}
/* (non-Javadoc)
* @see ext.site.time.chrono.FiscalYearEndPatternBuilder.SimpleFiscalYearEndPattern#getPreviousLeapYears(int)
*/
@Override
protected int getPreviousLeapYears(final int isoYear) {
// Formula gets count of leap years, including current, so subtract a year first.
final int previousYear = isoYear - 1;
// If the doomsday offset is -1, then the first year is a leap year.
return (previousYear + leapYearCountOffset + (previousYear / 4) - (previousYear / 100) + (previousYear / 400)) / 7 + (leapYearCountOffset == FIRST_YEAR_LEAP_YEAR_OFFSET ? 1 : 0);
}
如果你注意到,我使用<条码>,代谢年份代码>,该代码(作为最后变量)在“条码”的抽象超级类别中加以界定,然后由超级层建筑商标明。 我不想重复上层建筑商的公式——它对于第3/1-12/31号系列中的日期有不同;我也不想将实例变数列入具体的子类——其他计算仍然需要<条码>。
www.un.org/spanish/ecosoc 问题: 当建筑商要求使用(子级)方法时,<条码>的状态是什么? 它是否以任何方式得到保障,或者在汇编者之意下可能发生变化的东西? 我怎么能检验一下? 我已经知道,汇编者可以自由地重新安排一些发言,但会(可能)在这里出现?