//////////////////////////////////////////

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.

//////////////////////////////////////////

= Working with legacy Date/Calendar types

The `groovy-dateutil` module supports numerous extensions for working with
Java's classic `Date` and `Calendar` classes.

You can access the properties of a `Date` or `Calendar` using the normal array index notation
with the constant field numbers from the `Calendar` class as shown in the following example:

[source,groovy]
-------------------------------------
include::../test/gdk/WorkingWithDateUtilTypesTest.groovy[tags=calendar_getAt,indent=0]
-------------------------------------
<1> Import the constants
<2> Setting the calendar's year, month and day of month
<3> Accessing the calendar's day of week

Groovy supports arithmetic on and iteration between `Date` and `Calendar` instances as shown in the following example:
[source,groovy]
-------------------------------------
include::../test/gdk/WorkingWithDateUtilTypesTest.groovy[tags=date_arithmetic,indent=0]
-------------------------------------

You can parse strings into dates and output dates into formatted strings:
[source,groovy]
-------------------------------------
include::../test/gdk/WorkingWithDateUtilTypesTest.groovy[tags=date_parsing,indent=0]
-------------------------------------

You can also create a new Date or Calendar based on an existing one:
[source,groovy]
-------------------------------------
include::../test/gdk/WorkingWithDateUtilTypesTest.groovy[tags=date_copyWith,indent=0]
-------------------------------------

== A number-based DSL for durations

The `org.apache.groovy.dateutil.TimeCategory` category adds properties to numbers for
producing durations that can be added to or subtracted from `Date` instances:

[source,groovy]
-------------------------------------
use (org.apache.groovy.dateutil.TimeCategory) {
    def christmas = new Date(124, 11, 25)     // 25 Dec 2024
    assert (christmas + 1.week - 3.days).date == 29
    assert (christmas - christmas).toMilliseconds() == 0

    def party = 2.hours + 30.minutes
    assert party.toMilliseconds() == (150 * 60 * 1000)
}
-------------------------------------

This is a dequirked, `java.util.Date`-flavored parallel to the (now deprecated)
`groovy.time.TimeCategory`. Relative to the legacy class, `.ago`/`.from.now` preserve the
time-of-day uniformly (they no longer floor day/month/year amounts to midnight), and
`toMilliseconds()` is deterministic (years and months use fixed `java.time.temporal.ChronoUnit`
estimates rather than resolving against the current date). A `java.time` flavored equivalent,
`org.apache.groovy.datetime.TimeCategory`, is available in the `groovy-datetime` module.
