1 
2  /*
3  * hunt-time: A time library for D programming language.
4  *
5  * Copyright (C) 2015-2018 HuntLabs
6  *
7  * Website: https://www.huntlabs.net/
8  *
9  * Licensed under the Apache-2.0 License.
10  *
11  */
12 
13 module hunt.time.chrono.HijrahDate;
14 
15 // import hunt.time.temporal.ChronoField;
16 
17 // import hunt.Exceptions;
18 
19 // import hunt.stream.ObjectInput;
20 // //import hunt.io.ObjectInputStream;
21 // import hunt.stream.ObjectOutput;
22 // import hunt.stream.Common;
23 // import hunt.time.Clock;
24 // import hunt.time.Exceptions;
25 // import hunt.time.LocalDate;
26 // import hunt.time.LocalTime;
27 // import hunt.time.ZoneId;
28 // import hunt.time.temporal.ChronoField;
29 // import hunt.time.temporal.TemporalAccessor;
30 // import hunt.time.temporal.TemporalAdjuster;
31 // import hunt.time.temporal.TemporalAmount;
32 // import hunt.time.temporal.TemporalField;
33 // import hunt.time.temporal.TemporalQuery;
34 // import hunt.time.temporal.TemporalUnit;
35 // import hunt.time.Exceptions;
36 // import hunt.time.temporal.ValueRange;
37 
38 // /**
39 //  * A date _in the Hijrah calendar system.
40 //  * !(p)
41 //  * This date operates using one of several variants of the
42 //  * {@linkplain HijrahChronology Hijrah calendar}.
43 //  * !(p)
44 //  * The Hijrah calendar has a different total of days _in a year than
45 //  * Gregorian calendar, and the length of each month is based on the period
46 //  * of a complete revolution of the moon around the earth
47 //  * (as between successive new moons).
48 //  * Refer to the {@link HijrahChronology} for details of supported variants.
49 //  * !(p)
50 //  * Each HijrahDate is created bound to a particular HijrahChronology,
51 //  * The same chronology is propagated to each HijrahDate computed from the date.
52 //  * To use a different Hijrah variant, its HijrahChronology can be used
53 //  * to create new HijrahDate instances.
54 //  * Alternatively, the {@link #withVariant} method can be used to convert
55 //  * to a new HijrahChronology.
56 //  *
57 //  * !(p)
58 //  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
59 //  * class; use of identity-sensitive operations (including reference equality
60 //  * ({@code ==}), identity hash code, or synchronization) on instances of
61 //  * {@code HijrahDate} may have unpredictable results and should be avoided.
62 //  * The {@code equals} method should be used for comparisons.
63 //  *
64 //  * @implSpec
65 //  * This class is immutable and thread-safe.
66 //  *
67 //  * @since 1.8
68 //  */
69 // public final class HijrahDate
70 //         : ChronoLocalDateImpl!(HijrahDate)
71 //         , ChronoLocalDate, Serializable {
72 
73 //     /**
74 //      * Serialization version.
75 //      */
76 //     private static final long serialVersionUID = -5207853542612002020L;
77 //     /**
78 //      * The Chronology of this HijrahDate.
79 //      */
80 //     private final /*transient*/ HijrahChronology chrono;
81 //     /**
82 //      * The proleptic year.
83 //      */
84 //     private final /*transient*/ int prolepticYear;
85 //     /**
86 //      * The month-of-year.
87 //      */
88 //     private final /*transient*/ int monthOfYear;
89 //     /**
90 //      * The day-of-month.
91 //      */
92 //     private final /*transient*/ int dayOfMonth;
93 
94 //     //-------------------------------------------------------------------------
95 //     /**
96 //      * Obtains an instance of {@code HijrahDate} from the Hijrah proleptic year,
97 //      * month-of-year and day-of-month.
98 //      *
99 //      * @param prolepticYear  the proleptic year to represent _in the Hijrah calendar
100 //      * @param monthOfYear  the month-of-year to represent, from 1 to 12
101 //      * @param dayOfMonth  the day-of-month to represent, from 1 to 30
102 //      * @return the Hijrah date, never null
103 //      * @throws DateTimeException if the value of any field is _out of range
104 //      */
105 //     static HijrahDate of(HijrahChronology chrono, int prolepticYear, int monthOfYear, int dayOfMonth) {
106 //         return new HijrahDate(chrono, prolepticYear, monthOfYear, dayOfMonth);
107 //     }
108 
109 //     /**
110 //      * Returns a HijrahDate for the chronology and epochDay.
111 //      * @param chrono The Hijrah chronology
112 //      * @param epochDay the epoch day
113 //      * @return a HijrahDate for the epoch day; non-null
114 //      */
115 //     static HijrahDate ofEpochDay(HijrahChronology chrono, long epochDay) {
116 //         return new HijrahDate(chrono, epochDay);
117 //     }
118 
119 //     //-----------------------------------------------------------------------
120 //     /**
121 //      * Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar
122 //      * _in the default time-zone.
123 //      * !(p)
124 //      * This will query the {@link Clock#systemDefaultZone() system clock} _in the default
125 //      * time-zone to obtain the current date.
126 //      * !(p)
127 //      * Using this method will prevent the ability to use an alternate clock for testing
128 //      * because the clock is hard-coded.
129 //      *
130 //      * @return the current date using the system clock and default time-zone, not null
131 //      */
132 //     public static HijrahDate now() {
133 //         return now(Clock.systemDefaultZone());
134 //     }
135 
136 //     /**
137 //      * Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar
138 //      * _in the specified time-zone.
139 //      * !(p)
140 //      * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
141 //      * Specifying the time-zone avoids dependence on the default time-zone.
142 //      * !(p)
143 //      * Using this method will prevent the ability to use an alternate clock for testing
144 //      * because the clock is hard-coded.
145 //      *
146 //      * @param zone  the zone ID to use, not null
147 //      * @return the current date using the system clock, not null
148 //      */
149 //     public static HijrahDate now(ZoneId zone) {
150 //         return now(Clock.system(zone));
151 //     }
152 
153 //     /**
154 //      * Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar
155 //      * from the specified clock.
156 //      * !(p)
157 //      * This will query the specified clock to obtain the current date - today.
158 //      * Using this method allows the use of an alternate clock for testing.
159 //      * The alternate clock may be introduced using {@linkplain Clock dependency injection}.
160 //      *
161 //      * @param clock  the clock to use, not null
162 //      * @return the current date, not null
163 //      * @throws DateTimeException if the current date cannot be obtained
164 //      */
165 //     public static HijrahDate now(Clock clock) {
166 //         return HijrahDate.ofEpochDay(HijrahChronology.INSTANCE, LocalDate.now(clock).toEpochDay());
167 //     }
168 
169 //     /**
170 //      * Obtains a {@code HijrahDate} of the Islamic Umm Al-Qura calendar
171 //      * from the proleptic-year, month-of-year and day-of-month fields.
172 //      * !(p)
173 //      * This returns a {@code HijrahDate} with the specified fields.
174 //      * The day must be valid for the year and month, otherwise an exception will be thrown.
175 //      *
176 //      * @param prolepticYear  the Hijrah proleptic-year
177 //      * @param month  the Hijrah month-of-year, from 1 to 12
178 //      * @param dayOfMonth  the Hijrah day-of-month, from 1 to 30
179 //      * @return the date _in Hijrah calendar system, not null
180 //      * @throws DateTimeException if the value of any field is _out of range,
181 //      *  or if the day-of-month is invalid for the month-year
182 //      */
183 //     public static HijrahDate of(int prolepticYear, int month, int dayOfMonth) {
184 //         return HijrahChronology.INSTANCE.date(prolepticYear, month, dayOfMonth);
185 //     }
186 
187 //     /**
188 //      * Obtains a {@code HijrahDate} of the Islamic Umm Al-Qura calendar from a temporal object.
189 //      * !(p)
190 //      * This obtains a date _in the Hijrah calendar system based on the specified temporal.
191 //      * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
192 //      * which this factory converts to an instance of {@code HijrahDate}.
193 //      * !(p)
194 //      * The conversion typically uses the {@link ChronoField#EPOCH_DAY EPOCH_DAY}
195 //      * field, which is standardized across calendar systems.
196 //      * !(p)
197 //      * This method matches the signature of the functional interface {@link TemporalQuery}
198 //      * allowing it to be used as a query via method reference, {@code HijrahDate::from}.
199 //      *
200 //      * @param temporal  the temporal object to convert, not null
201 //      * @return the date _in Hijrah calendar system, not null
202 //      * @throws DateTimeException if unable to convert to a {@code HijrahDate}
203 //      */
204 //     public static HijrahDate from(TemporalAccessor temporal) {
205 //         return HijrahChronology.INSTANCE.date(temporal);
206 //     }
207 
208 //     //-----------------------------------------------------------------------
209 //     /**
210 //      * Constructs an {@code HijrahDate} with the proleptic-year, month-of-year and
211 //      * day-of-month fields.
212 //      *
213 //      * @param chrono The chronology to create the date with
214 //      * @param prolepticYear the proleptic year
215 //      * @param monthOfYear the month of year
216 //      * @param dayOfMonth the day of month
217 //      */
218 //     private this(HijrahChronology chrono, int prolepticYear, int monthOfYear, int dayOfMonth) {
219 //         // Computing the Gregorian day checks the valid ranges
220 //         chrono.getEpochDay(prolepticYear, monthOfYear, dayOfMonth);
221 
222 //         this.chrono = chrono;
223 //         this.prolepticYear = prolepticYear;
224 //         this.monthOfYear = monthOfYear;
225 //         this.dayOfMonth = dayOfMonth;
226 //     }
227 
228 //     /**
229 //      * Constructs an instance with the Epoch Day.
230 //      *
231 //      * @param epochDay  the epochDay
232 //      */
233 //     private this(HijrahChronology chrono, long epochDay) {
234 //         int[] dateInfo = chrono.getHijrahDateInfo(cast(int)epochDay);
235 
236 //         this.chrono = chrono;
237 //         this.prolepticYear = dateInfo[0];
238 //         this.monthOfYear = dateInfo[1];
239 //         this.dayOfMonth = dateInfo[2];
240 //     }
241 
242 //     //-----------------------------------------------------------------------
243 //     /**
244 //      * Gets the chronology of this date, which is the Hijrah calendar system.
245 //      * !(p)
246 //      * The {@code Chronology} represents the calendar system _in use.
247 //      * The era and other fields _in {@link ChronoField} are defined by the chronology.
248 //      *
249 //      * @return the Hijrah chronology, not null
250 //      */
251 //     override
252 //     public HijrahChronology getChronology() {
253 //         return chrono;
254 //     }
255 
256 //     /**
257 //      * Gets the era applicable at this date.
258 //      * !(p)
259 //      * The Hijrah calendar system has one era, 'AH',
260 //      * defined by {@link HijrahEra}.
261 //      *
262 //      * @return the era applicable at this date, not null
263 //      */
264 //     override
265 //     public HijrahEra getEra() {
266 //         return HijrahEra.AH;
267 //     }
268 
269 //     /**
270 //      * Returns the length of the month represented by this date.
271 //      * !(p)
272 //      * This returns the length of the month _in days.
273 //      * Month lengths _in the Hijrah calendar system vary between 29 and 30 days.
274 //      *
275 //      * @return the length of the month _in days
276 //      */
277 //     override
278 //     public int lengthOfMonth() {
279 //         return chrono.getMonthLength(prolepticYear, monthOfYear);
280 //     }
281 
282 //     /**
283 //      * Returns the length of the year represented by this date.
284 //      * !(p)
285 //      * This returns the length of the year _in days.
286 //      * A Hijrah calendar system year is typically shorter than
287 //      * that of the ISO calendar system.
288 //      *
289 //      * @return the length of the year _in days
290 //      */
291 //     override
292 //     public int lengthOfYear() {
293 //         return chrono.getYearLength(prolepticYear);
294 //     }
295 
296 //     //-----------------------------------------------------------------------
297 //     override
298 //     public ValueRange range(TemporalField field) {
299 //         if (cast(ChronoField)(field) !is null) {
300 //             if (isSupported(field)) {
301 //                 ChronoField f = cast(ChronoField) field;
302 //                 switch (f) {
303 //                     case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());
304 //                     case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());
305 //                     case ALIGNED_WEEK_OF_MONTH: return ValueRange.of(1, 5);  // TODO
306 //                     // TODO does the limited range of valid years cause years to
307 //                     // start/end part way through? that would affect range
308 //                 }
309 //                 return getChronology().range(f);
310 //             }
311 //             throw new UnsupportedTemporalTypeException("Unsupported field: " ~ field);
312 //         }
313 //         return field.rangeRefinedBy(this);
314 //     }
315 
316 //     override
317 //     public long getLong(TemporalField field) {
318 //         if (cast(ChronoField)(field) !is null) {
319 //             switch (cast(ChronoField) field) {
320 //                 case DAY_OF_WEEK: return getDayOfWeek();
321 //                 case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1;
322 //                 case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
323 //                 case DAY_OF_MONTH: return this.dayOfMonth;
324 //                 case DAY_OF_YEAR: return this.getDayOfYear();
325 //                 case EPOCH_DAY: return toEpochDay();
326 //                 case ALIGNED_WEEK_OF_MONTH: return ((dayOfMonth - 1) / 7) + 1;
327 //                 case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
328 //                 case MONTH_OF_YEAR: return monthOfYear;
329 //                 case PROLEPTIC_MONTH: return getProlepticMonth();
330 //                 case YEAR_OF_ERA: return prolepticYear;
331 //                 case YEAR: return prolepticYear;
332 //                 case ERA: return getEraValue();
333 //             }
334 //             throw new UnsupportedTemporalTypeException("Unsupported field: " ~ field);
335 //         }
336 //         return field.getFrom(this);
337 //     }
338 
339 //     private long getProlepticMonth() {
340 //         return prolepticYear * 12L + monthOfYear - 1;
341 //     }
342 
343 //     override
344 //     public HijrahDate _with(TemporalField field, long newValue) {
345 //         if (cast(ChronoField)(field) !is null) {
346 //             ChronoField f = cast(ChronoField) field;
347 //             // not using checkValidIntValue so EPOCH_DAY and PROLEPTIC_MONTH work
348 //             chrono.range(f).checkValidValue(newValue, f);    // TODO: validate value
349 //             int nvalue = cast(int) newValue;
350 //             switch (f) {
351 //                 case DAY_OF_WEEK: return plusDays(newValue - getDayOfWeek());
352 //                 case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
353 //                 case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
354 //                 case DAY_OF_MONTH: return resolvePreviousValid(prolepticYear, monthOfYear, nvalue);
355 //                 case DAY_OF_YEAR: return plusDays(Math.min(nvalue, lengthOfYear()) - getDayOfYear());
356 //                 case EPOCH_DAY: return new HijrahDate(chrono, newValue);
357 //                 case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
358 //                 case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
359 //                 case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, dayOfMonth);
360 //                 case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
361 //                 case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, monthOfYear, dayOfMonth);
362 //                 case YEAR: return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth);
363 //                 case ERA: return resolvePreviousValid(1 - prolepticYear, monthOfYear, dayOfMonth);
364 //             }
365 //             throw new UnsupportedTemporalTypeException("Unsupported field: " ~ field);
366 //         }
367 //         return super._with(field, newValue);
368 //     }
369 
370 //     private HijrahDate resolvePreviousValid(int prolepticYear, int month, int day) {
371 //         int monthDays = chrono.getMonthLength(prolepticYear, month);
372 //         if (day > monthDays) {
373 //             day = monthDays;
374 //         }
375 //         return HijrahDate.of(chrono, prolepticYear, month, day);
376 //     }
377 
378 //     /**
379 //      * {@inheritDoc}
380 //      * @throws DateTimeException if unable to make the adjustment.
381 //      *     For example, if the adjuster requires an ISO chronology
382 //      * @throws ArithmeticException {@inheritDoc}
383 //      */
384 //     override
385 //     public  HijrahDate _with(TemporalAdjuster adjuster) {
386 //         return super._with(adjuster);
387 //     }
388 
389 //     /**
390 //      * Returns a {@code HijrahDate} with the Chronology requested.
391 //      * !(p)
392 //      * The year, month, and day are checked against the new requested
393 //      * HijrahChronology.  If the chronology has a shorter month length
394 //      * for the month, the day is reduced to be the last day of the month.
395 //      *
396 //      * @param chronology the new HijrahChonology, non-null
397 //      * @return a HijrahDate with the requested HijrahChronology, non-null
398 //      */
399 //     public HijrahDate withVariant(HijrahChronology chronology) {
400 //         if (chrono == chronology) {
401 //             return this;
402 //         }
403 //         // Like resolvePreviousValid the day is constrained to stay _in the same month
404 //         int monthDays = chronology.getDayOfYear(prolepticYear, monthOfYear);
405 //         return HijrahDate.of(chronology, prolepticYear, monthOfYear,(dayOfMonth > monthDays) ? monthDays : dayOfMonth );
406 //     }
407 
408 //     /**
409 //      * {@inheritDoc}
410 //      * @throws DateTimeException {@inheritDoc}
411 //      * @throws ArithmeticException {@inheritDoc}
412 //      */
413 //     override
414 //     public HijrahDate plus(TemporalAmount amount) {
415 //         return super.plus(amount);
416 //     }
417 
418 //     /**
419 //      * {@inheritDoc}
420 //      * @throws DateTimeException {@inheritDoc}
421 //      * @throws ArithmeticException {@inheritDoc}
422 //      */
423 //     override
424 //     public HijrahDate minus(TemporalAmount amount) {
425 //         return super.minus(amount);
426 //     }
427 
428 //     override
429 //     public long toEpochDay() {
430 //         return chrono.getEpochDay(prolepticYear, monthOfYear, dayOfMonth);
431 //     }
432 
433 //     /**
434 //      * Gets the day-of-year field.
435 //      * !(p)
436 //      * This method returns the primitive {@code int} value for the day-of-year.
437 //      *
438 //      * @return the day-of-year
439 //      */
440 //     private int getDayOfYear() {
441 //         return chrono.getDayOfYear(prolepticYear, monthOfYear) + dayOfMonth;
442 //     }
443 
444 //     /**
445 //      * Gets the day-of-week value.
446 //      *
447 //      * @return the day-of-week; computed from the epochday
448 //      */
449 //     private int getDayOfWeek() {
450 //         int dow0 = Math.floorMod(toEpochDay() + 3, 7);
451 //         return dow0 + 1;
452 //     }
453 
454 //     /**
455 //      * Gets the Era of this date.
456 //      *
457 //      * @return the Era of this date; computed from epochDay
458 //      */
459 //     private int getEraValue() {
460 //         return (prolepticYear > 1 ? 1 : 0);
461 //     }
462 
463 //     //-----------------------------------------------------------------------
464 //     /**
465 //      * Checks if the year is a leap year, according to the Hijrah calendar system rules.
466 //      *
467 //      * @return true if this date is _in a leap year
468 //      */
469 //     override
470 //     public bool isLeapYear() {
471 //         return chrono.isLeapYear(prolepticYear);
472 //     }
473 
474 //     //-----------------------------------------------------------------------
475 //     override
476 //     HijrahDate plusYears(long years) {
477 //         if (years == 0) {
478 //             return this;
479 //         }
480 //         int newYear = Math.addExact(this.prolepticYear, cast(int)years);
481 //         return resolvePreviousValid(newYear, monthOfYear, dayOfMonth);
482 //     }
483 
484 //     override
485 //     HijrahDate plusMonths(long monthsToAdd) {
486 //         if (monthsToAdd == 0) {
487 //             return this;
488 //         }
489 //         long monthCount = prolepticYear * 12L + (monthOfYear - 1);
490 //         long calcMonths = monthCount + monthsToAdd;  // safe overflow
491 //         int newYear = chrono.checkValidYear(Math.floorDiv(calcMonths, 12L));
492 //         int newMonth = cast(int)Math.floorMod(calcMonths, 12L) + 1;
493 //         return resolvePreviousValid(newYear, newMonth, dayOfMonth);
494 //     }
495 
496 //     override
497 //     HijrahDate plusWeeks(long weeksToAdd) {
498 //         return super.plusWeeks(weeksToAdd);
499 //     }
500 
501 //     override
502 //     HijrahDate plusDays(long days) {
503 //         return new HijrahDate(chrono, toEpochDay() + days);
504 //     }
505 
506 //     override
507 //     public HijrahDate plus(long amountToAdd, TemporalUnit unit) {
508 //         return super.plus(amountToAdd, unit);
509 //     }
510 
511 //     override
512 //     public HijrahDate minus(long amountToSubtract, TemporalUnit unit) {
513 //         return super.minus(amountToSubtract, unit);
514 //     }
515 
516 //     override
517 //     HijrahDate minusYears(long yearsToSubtract) {
518 //         return super.minusYears(yearsToSubtract);
519 //     }
520 
521 //     override
522 //     HijrahDate minusMonths(long monthsToSubtract) {
523 //         return super.minusMonths(monthsToSubtract);
524 //     }
525 
526 //     override
527 //     HijrahDate minusWeeks(long weeksToSubtract) {
528 //         return super.minusWeeks(weeksToSubtract);
529 //     }
530 
531 //     override
532 //     HijrahDate minusDays(long daysToSubtract) {
533 //         return super.minusDays(daysToSubtract);
534 //     }
535 
536 //     override        // for javadoc and covariant return type
537 //     /*@SuppressWarnings("unchecked")*/
538 //     public final ChronoLocalDateTime!(HijrahDate) atTime(LocalTime localTime) {
539 //         return cast(ChronoLocalDateTime!(HijrahDate))super.atTime(localTime);
540 //     }
541 
542 //     override
543 //     public ChronoPeriod until(ChronoLocalDate endDate) {
544 //         // TODO: untested
545 //         HijrahDate end = getChronology().date(endDate);
546 //         long totalMonths = (end.prolepticYear - this.prolepticYear) * 12 + (end.monthOfYear - this.monthOfYear);  // safe
547 //         int days = end.dayOfMonth - this.dayOfMonth;
548 //         if (totalMonths > 0 && days < 0) {
549 //             totalMonths--;
550 //             HijrahDate calcDate = this.plusMonths(totalMonths);
551 //             days = cast(int) (end.toEpochDay() - calcDate.toEpochDay());  // safe
552 //         } else if (totalMonths < 0 && days > 0) {
553 //             totalMonths++;
554 //             days -= end.lengthOfMonth();
555 //         }
556 //         long years = totalMonths / 12;  // safe
557 //         int months = cast(int) (totalMonths % 12);  // safe
558 //         return getChronology().period(Math.toIntExact(years), months, days);
559 //     }
560 
561 //     //-------------------------------------------------------------------------
562 //     /**
563 //      * Compares this date to another date, including the chronology.
564 //      * !(p)
565 //      * Compares this {@code HijrahDate} with another ensuring that the date is the same.
566 //      * !(p)
567 //      * Only objects of type {@code HijrahDate} are compared, other types return false.
568 //      * To compare the dates of two {@code TemporalAccessor} instances, including dates
569 //      * _in two different chronologies, use {@link ChronoField#EPOCH_DAY} as a comparator.
570 //      *
571 //      * @param obj  the object to check, null returns false
572 //      * @return true if this is equal to the other date and the Chronologies are equal
573 //      */
574 //     override  // override for performance
575 //     public bool opEquals(Object obj) {
576 //         if (this is obj) {
577 //             return true;
578 //         }
579 //         if (cast(HijrahDate)(obj) !is null) {
580 //             HijrahDate otherDate = cast(HijrahDate) obj;
581 //             return prolepticYear == otherDate.prolepticYear
582 //                 && this.monthOfYear == otherDate.monthOfYear
583 //                 && this.dayOfMonth == otherDate.dayOfMonth
584 //                 && getChronology().equals(otherDate.getChronology());
585 //         }
586 //         return false;
587 //     }
588 
589 //     /**
590 //      * A hash code for this date.
591 //      *
592 //      * @return a suitable hash code based only on the Chronology and the date
593 //      */
594 //     override  // override for performance
595 //     public size_t toHash() @trusted nothrow {
596 //         int yearValue = prolepticYear;
597 //         int monthValue = monthOfYear;
598 //         int dayValue = dayOfMonth;
599 //         return getChronology().getId().toHash() ^ (yearValue & 0xFFFFF800)
600 //                 ^ ((yearValue << 11) + (monthValue << 6) + (dayValue));
601 //     }
602 
603 //     //-----------------------------------------------------------------------
604 //     /**
605 //      * Defend against malicious streams.
606 //      *
607 //      * @param s the stream to read
608 //      * @throws InvalidObjectException always
609 //      */
610 //     private void readObject(ObjectInputStream s) /*throws InvalidObjectException*/ {
611 //         throw new InvalidObjectException("Deserialization via serialization delegate");
612 //     }
613 
614 //     /**
615 //      * Writes the object using a
616 //      * <a href="{@docRoot}/serialized-form.html#hunt.time.chrono.Ser">dedicated serialized form</a>.
617 //      * @serialData
618 //      * !(pre)
619 //      *  _out.writeByte(6);                 // identifies a HijrahDate
620 //      *  _out.writeObject(chrono);          // the HijrahChronology variant
621 //      *  _out.writeInt(get(YEAR));
622 //      *  _out.writeByte(get(MONTH_OF_YEAR));
623 //      *  _out.writeByte(get(DAY_OF_MONTH));
624 //      * </pre>
625 //      *
626 //      * @return the instance of {@code Ser}, not null
627 //      */
628 //     private Object writeReplace() {
629 //         return new Ser(Ser.HIJRAH_DATE_TYPE, this);
630 //     }
631 
632 //     void writeExternal(ObjectOutput _out) /*throws IOException*/ {
633 //         // HijrahChronology is implicit _in the Hijrah_DATE_TYPE
634 //         _out.writeObject(getChronology());
635 //         _out.writeInt(get(YEAR));
636 //         _out.writeByte(get(MONTH_OF_YEAR));
637 //         _out.writeByte(get(DAY_OF_MONTH));
638 //     }
639 
640 //     static HijrahDate readExternal(ObjectInput _in) /*throws IOException, ClassNotFoundException*/ {
641 //         HijrahChronology chrono = cast(HijrahChronology) _in.readObject();
642 //         int year = _in.readInt();
643 //         int month = _in.readByte();
644 //         int dayOfMonth = _in.readByte();
645 //         return chrono.date(year, month, dayOfMonth);
646 //     }
647 
648 // }