View Javadoc
1   /*
2    * MoneyWise: Finance Application
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.moneywise.archive;
18  
19  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
20  import io.github.tonywasher.joceanus.oceanus.date.OceanusFiscalYear;
21  
22  /**
23   * Simple class to define an archive year.
24   */
25  public final class MoneyWiseArchiveYear {
26      /**
27       * Year boundary.
28       */
29      private static final int YEAR_BDY = 60;
30  
31      /**
32       * Year constant.
33       */
34      private static final int YEAR_1900 = 1900;
35  
36      /**
37       * Year constant.
38       */
39      private static final int YEAR_2000 = 2000;
40  
41      /**
42       * The date.
43       */
44      private final OceanusDate theDate;
45  
46      /**
47       * The range name.
48       */
49      private final String theRangeName;
50  
51      /**
52       * Constructor.
53       *
54       * @param pName the range name
55       */
56      MoneyWiseArchiveYear(final String pName) {
57          /* Store parameters */
58          theRangeName = pName;
59  
60          /* Isolate the year part */
61          final int myLen = pName.length();
62          int myYear = Integer.parseInt(pName.substring(myLen - 2));
63  
64          /* Calculate the actual year */
65          if (myYear < YEAR_BDY) {
66              myYear += YEAR_2000;
67          } else {
68              myYear += YEAR_1900;
69          }
70  
71          /* Create the date */
72          final OceanusFiscalYear myFiscal = OceanusFiscalYear.UK;
73          theDate = new OceanusDate(myYear, myFiscal.getFirstMonth(), myFiscal.getFirstDay());
74          theDate.adjustDay(-1);
75      }
76  
77      /**
78       * Get the date.
79       *
80       * @return the date
81       */
82      OceanusDate getDate() {
83          return theDate;
84      }
85  
86      /**
87       * Get the range name.
88       *
89       * @return the name
90       */
91      String getRangeName() {
92          return theRangeName;
93      }
94  }