001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (https://www.swig.org).
003 * Version 4.1.1
004 *
005 * Do not make changes to this file unless you know what you are doing - modify
006 * the SWIG interface file instead.
007 * ----------------------------------------------------------------------------- */
008
009package org.quantlib;
010
011public class Date implements org.quantlib.helpers.QuantLibJNIHelpers.AutoCloseable {
012  private transient long swigCPtr;
013  protected transient boolean swigCMemOwn;
014
015  protected Date(long cPtr, boolean cMemoryOwn) {
016    swigCMemOwn = cMemoryOwn;
017    swigCPtr = cPtr;
018  }
019
020  protected static long getCPtr(Date obj) {
021    return (obj == null) ? 0 : obj.swigCPtr;
022  }
023
024  protected static long swigRelease(Date obj) {
025    long ptr = 0;
026    if (obj != null) {
027      if (!obj.swigCMemOwn)
028        throw new RuntimeException("Cannot release ownership as memory is not owned");
029      ptr = obj.swigCPtr;
030      obj.swigCMemOwn = false;
031      obj.delete();
032    }
033    return ptr;
034  }
035
036  @SuppressWarnings("deprecation")
037  protected void finalize() {
038    delete();
039  }
040
041  public synchronized void delete() {
042    if (swigCPtr != 0) {
043      if (swigCMemOwn) {
044        swigCMemOwn = false;
045        QuantLibJNI.delete_Date(swigCPtr);
046      }
047      swigCPtr = 0;
048    }
049  }
050
051  public Date() {
052    this(QuantLibJNI.new_Date__SWIG_0(), true);
053  }
054
055  public Date(int d, Month m, int y) {
056    this(QuantLibJNI.new_Date__SWIG_1(d, m.swigValue(), y), true);
057  }
058
059  public Date(int d, Month m, int y, int hours, int minutes, int seconds, int millisec, int microsec) {
060    this(QuantLibJNI.new_Date__SWIG_2(d, m.swigValue(), y, hours, minutes, seconds, millisec, microsec), true);
061  }
062
063  public Date(int d, Month m, int y, int hours, int minutes, int seconds, int millisec) {
064    this(QuantLibJNI.new_Date__SWIG_3(d, m.swigValue(), y, hours, minutes, seconds, millisec), true);
065  }
066
067  public Date(int d, Month m, int y, int hours, int minutes, int seconds) {
068    this(QuantLibJNI.new_Date__SWIG_4(d, m.swigValue(), y, hours, minutes, seconds), true);
069  }
070
071  public Date(int serialNumber) {
072    this(QuantLibJNI.new_Date__SWIG_5(serialNumber), true);
073  }
074
075  public Weekday weekday() {
076    return Weekday.swigToEnum(QuantLibJNI.Date_weekday(swigCPtr, this));
077  }
078
079  public int dayOfMonth() {
080    return QuantLibJNI.Date_dayOfMonth(swigCPtr, this);
081  }
082
083  public int dayOfYear() {
084    return QuantLibJNI.Date_dayOfYear(swigCPtr, this);
085  }
086
087  public Month month() {
088    return Month.swigToEnum(QuantLibJNI.Date_month(swigCPtr, this));
089  }
090
091  public int year() {
092    return QuantLibJNI.Date_year(swigCPtr, this);
093  }
094
095  public int hours() {
096    return QuantLibJNI.Date_hours(swigCPtr, this);
097  }
098
099  public int minutes() {
100    return QuantLibJNI.Date_minutes(swigCPtr, this);
101  }
102
103  public int seconds() {
104    return QuantLibJNI.Date_seconds(swigCPtr, this);
105  }
106
107  public int milliseconds() {
108    return QuantLibJNI.Date_milliseconds(swigCPtr, this);
109  }
110
111  public int microseconds() {
112    return QuantLibJNI.Date_microseconds(swigCPtr, this);
113  }
114
115  public double fractionOfDay() {
116    return QuantLibJNI.Date_fractionOfDay(swigCPtr, this);
117  }
118
119  public double fractionOfSecond() {
120    return QuantLibJNI.Date_fractionOfSecond(swigCPtr, this);
121  }
122
123  public int serialNumber() {
124    return QuantLibJNI.Date_serialNumber(swigCPtr, this);
125  }
126
127  public static boolean isLeap(int y) {
128    return QuantLibJNI.Date_isLeap(y);
129  }
130
131  public static Date minDate() {
132    return new Date(QuantLibJNI.Date_minDate(), true);
133  }
134
135  public static Date maxDate() {
136    return new Date(QuantLibJNI.Date_maxDate(), true);
137  }
138
139  public static Date todaysDate() {
140    return new Date(QuantLibJNI.Date_todaysDate(), true);
141  }
142
143  public static Date localDateTime() {
144    return new Date(QuantLibJNI.Date_localDateTime(), true);
145  }
146
147  public static Date universalDateTime() {
148    return new Date(QuantLibJNI.Date_universalDateTime(), true);
149  }
150
151  public static Date endOfMonth(Date arg0) {
152    return new Date(QuantLibJNI.Date_endOfMonth(Date.getCPtr(arg0), arg0), true);
153  }
154
155  public static boolean isEndOfMonth(Date arg0) {
156    return QuantLibJNI.Date_isEndOfMonth(Date.getCPtr(arg0), arg0);
157  }
158
159  public static Date nextWeekday(Date arg0, Weekday arg1) {
160    return new Date(QuantLibJNI.Date_nextWeekday(Date.getCPtr(arg0), arg0, arg1.swigValue()), true);
161  }
162
163  public static Date nthWeekday(long n, Weekday arg1, Month m, int y) {
164    return new Date(QuantLibJNI.Date_nthWeekday(n, arg1.swigValue(), m.swigValue(), y), true);
165  }
166
167  public Date add(int days) {
168    return new Date(QuantLibJNI.Date_add__SWIG_0(swigCPtr, this, days), true);
169  }
170
171  public Date subtract(int days) {
172    return new Date(QuantLibJNI.Date_subtract__SWIG_0(swigCPtr, this, days), true);
173  }
174
175  public Date add(Period arg0) {
176    return new Date(QuantLibJNI.Date_add__SWIG_1(swigCPtr, this, Period.getCPtr(arg0), arg0), true);
177  }
178
179  public Date subtract(Period arg0) {
180    return new Date(QuantLibJNI.Date_subtract__SWIG_1(swigCPtr, this, Period.getCPtr(arg0), arg0), true);
181  }
182
183  public Date(String str, String fmt) {
184    this(QuantLibJNI.new_Date__SWIG_6(str, fmt), true);
185  }
186
187  public int weekdayNumber() {
188    return QuantLibJNI.Date_weekdayNumber(swigCPtr, this);
189  }
190
191  public String toString() {
192    return QuantLibJNI.Date_toString(swigCPtr, this);
193  }
194
195  public String __repr__() {
196    return QuantLibJNI.Date___repr__(swigCPtr, this);
197  }
198
199  public String ISO() {
200    return QuantLibJNI.Date_ISO(swigCPtr, this);
201  }
202
203  public int subtract(Date other) {
204    return QuantLibJNI.Date_subtract__SWIG_2(swigCPtr, this, Date.getCPtr(other), other);
205  }
206
207    // convenience method to use java.time API
208    public static Date of(java.time.LocalDate localDate) {
209      return new Date(localDate.getDayOfMonth(), Month.swigToEnum(localDate.getMonthValue()), localDate.getYear());
210    }
211
212    // convenience method to use java.time API
213    public java.time.LocalDate toLocalDate() {
214      return java.time.LocalDate.of(this.year(), this.month().swigValue(), this.dayOfMonth());
215    }
216    
217}