diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7f50ff..5061567 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -88,20 +88,21 @@ jobs: lein: ${{ env.LEIN_VERSION }} - name: Run JVM tests run: lein test-all -# test-bb: -# needs: setup -# runs-on: ubuntu-latest -# steps: -# - name: Checkout -# uses: actions/checkout@v2 -# - name: Prepare java -# uses: actions/setup-java@v2 -# with: -# distribution: 'temurin' -# java-version: 17 -# - name: Setup Babashka -# uses: turtlequeue/setup-babashka@v1.3.0 -# with: -# babashka-version: 0.8.156 -# - name: Run Babashka tests -# run: ./bin/bb-test-runner.sh + test-bb: + needs: setup + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Prepare java + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 17 + - name: Setup Babashka + uses: turtlequeue/setup-babashka@v1.5.0 + with: + babashka-version: 0.10.164-SNAPSHOT + babashka-url: "https://output.circle-artifacts.com/output/job/e752ca69-381f-4087-83c1-0686444fdf82/artifacts/0/release/babashka-0.10.164-SNAPSHOT-linux-amd64.tar.gz" + - name: Run Babashka tests + run: ./bin/bb-test-runner.sh diff --git a/bin/bb-test-runner.sh b/bin/bb-test-runner.sh index b1841ea..bcfb67f 100755 --- a/bin/bb-test-runner.sh +++ b/bin/bb-test-runner.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -bb --debug --file ./bin/bb-test-runner.clj +bb --debug --file ./bin/bb_test_runner.clj diff --git a/bin/bb_test_runner.clj b/bin/bb_test_runner.clj index 90c65a6..c2adc91 100644 --- a/bin/bb_test_runner.clj +++ b/bin/bb_test_runner.clj @@ -22,9 +22,11 @@ 'java-time.clock 'java-time.pre-java8 'java-time + 'java-time.api ]) (def test-nsyms ['java-time-test + 'java-time.api-test 'java-time.graph-test]) (some->> (seq (concat require-nsyms test-nsyms)) diff --git a/docs/java-time.api.html b/docs/java-time.api.html index 8e1495f..1c3bcb2 100644 --- a/docs/java-time.api.html +++ b/docs/java-time.api.html @@ -2,8 +2,8 @@ ""> java-time.api documentation

java-time.api

abs

(abs a)

Returns the absolute value of a temporal amount:

(abs (negate x)) == (abs x)

-

abuts?

(abuts? i oi)

True if this interval abut with the other one

-

adjust

(adjust entity adjuster & args)

Adjusts the temporal entity using the provided adjuster with optional args.

+

abuts?

(abuts? i oi)

True if this interval abut with the other one

+

adjust

(adjust entity adjuster & args)

Adjusts the temporal entity using the provided adjuster with optional args.

The adjuster should either be a keyword which resolves to one of the predefined adjusters (see java-time.repl/show-adjusters) an instance of TemporalAdjuster or a function which returns another temporal entity when applied to the given one:

(adjust (local-date 2015 1 1) :next-working-day)
 => #<LocalDate 2015-1-2>
@@ -14,9 +14,10 @@
 (adjust (local-date 2015 1 1) plus (days 1))
 => #<LocalDate 2015-1-2>
 
-

advance-clock!

(advance-clock! clock amount)

Advances the clock by the given time amount.

+

advance-clock!

(advance-clock! clock amount)

Advances the clock by the given time amount.

This mutates the mock clock.

-

after?

(after? x)(after? x y)(after? x y & more)

Returns true if time entities are ordered from the latest to the earliest (same semantics as >), otherwise false.

+

Not available in babashka.

+

after?

(after? x)(after? x y)(after? x y & more)

Returns true if time entities are ordered from the latest to the earliest (same semantics as >), otherwise false.

(after? (local-date 2011) (local-date 2010) (local-date 2009))
 => true
 
@@ -24,24 +25,24 @@
         (interval (instant 10000) (instant 1000000)))
 => true
 
-

am-pm

(am-pm)(am-pm v)(am-pm fmt arg)

Returns the AmPm for the given keyword name (:am or :pm), ordinal or entity. Current AM/PM if no arguments given.

-

am-pm?

(am-pm? o)

True if org.threeten.extra.AmPm.

-

as

(as o k)(as o k1 k2)(as o k1 k2 & ks)

Values of property/unit identified by keys/objects ks of the temporal entity o, e.g.

+

am-pm

(am-pm)(am-pm v)(am-pm fmt arg)

Returns the AmPm for the given keyword name (:am or :pm), ordinal or entity. Current AM/PM if no arguments given.

+

am-pm?

(am-pm? o)

True if org.threeten.extra.AmPm.

+

as

(as o k)(as o k1 k2)(as o k1 k2 & ks)

Values of property/unit identified by keys/objects ks of the temporal entity o, e.g.

(as (duration 1 :hour) :minutes)
 => 60
 
 (as (local-date 2015 9) :year :month-of-year)
 => [2015 9]
 
-

as-map

(as-map e)(as-map e value-fn)

Converts a time entity to a map of property key -> value as defined by the passed in value-fn. By default the actual value of the unit/field is produced.

+

as-map

(as-map e)(as-map e value-fn)

Converts a time entity to a map of property key -> value as defined by the passed in value-fn. By default the actual value of the unit/field is produced.

(as-map (duration))
 => {:nanos 0, :seconds 0}
 
 (as-map (local-date 2015 1 1))
 => {:year 2015, :month-of-year 1, :day-of-month 1, ...}
 
-

available-zone-ids

(available-zone-ids)

Returns a set of string identifiers for all available ZoneIds.

-

before?

(before? x)(before? x y)(before? x y & more)

Returns true if time entities are ordered from the earliest to the latest (same semantics as <), otherwise false.

+

available-zone-ids

(available-zone-ids)

Returns a set of string identifiers for all available ZoneIds.

+

before?

(before? x)(before? x y)(before? x y & more)

Returns true if time entities are ordered from the earliest to the latest (same semantics as <), otherwise false.

(before? (local-date 2009) (local-date 2010) (local-date 2011))
 => true
 
@@ -49,10 +50,10 @@
          (instant 99999999))
 => true
 
-

chronology

(chronology o)

The Chronology of the entity

-

clock?

(clock? x)

Returns true if x is an instance of java.time.Clock.

-

contains?

(contains? i o)

True if the interval contains the given instant or interval

-

convert-amount

(convert-amount amount from-unit to-unit)

Converts an amount from one unit to another. Returns a map of:

+

chronology

(chronology o)

The Chronology of the entity

+

clock?

(clock? x)

Returns true if x is an instance of java.time.Clock.

+

contains?

(contains? i o)

True if the interval contains the given instant or interval

+

convert-amount

(convert-amount amount from-unit to-unit)

Converts an amount from one unit to another. Returns a map of:

  • :whole - the whole part of the conversion in the to unit
  • :remainder - the remainder in the from unit
  • @@ -63,14 +64,14 @@
    (convert-amount 10000 :seconds :hours)
     => {:remainder 2800 :whole 2}
     
    -

day-of-month

(day-of-month)(day-of-month arg)(day-of-month fmt arg)

Returns the DayOfMonth for the given entity, clock, zone or day of month. Current day of month if no arguments given.

-

day-of-month?

(day-of-month? o)

Returns true if o is org.threeten.extra.DayOfMonth, otherwise false.

-

day-of-week

(day-of-week)(day-of-week v)(day-of-week fmt arg)

Returns the DayOfWeek for the given day keyword name (e.g. :monday), ordinal or entity. Current day if no arguments given.

-

day-of-week?

(day-of-week? o)

True if java.time.DayOfWeek.

-

day-of-year

(day-of-year)(day-of-year arg)(day-of-year fmt arg)

Returns the DayOfYear for the given entity, clock, zone or day of year. Current day of year if no arguments given.

-

day-of-year?

(day-of-year? o)

Returns true if o is org.threeten.extra.DayOfYear, otherwise false.

-

days

(days i)

Returns a Period of i days.

-

duration

(duration)(duration arg0)(duration arg0 arg1)

Creates a duration - a temporal entity representing standard days, hours, minutes, millis, micros and nanos. The duration itself contains only seconds and nanos as properties.

+

day-of-month

(day-of-month)(day-of-month arg)(day-of-month fmt arg)

Returns the DayOfMonth for the given entity, clock, zone or day of month. Current day of month if no arguments given.

+

day-of-month?

(day-of-month? o)

Returns true if o is org.threeten.extra.DayOfMonth, otherwise false.

+

day-of-week

(day-of-week)(day-of-week v)(day-of-week fmt arg)

Returns the DayOfWeek for the given day keyword name (e.g. :monday), ordinal or entity. Current day if no arguments given.

+

day-of-week?

(day-of-week? o)

True if java.time.DayOfWeek.

+

day-of-year

(day-of-year)(day-of-year arg)(day-of-year fmt arg)

Returns the DayOfYear for the given entity, clock, zone or day of year. Current day of year if no arguments given.

+

day-of-year?

(day-of-year? o)

Returns true if o is org.threeten.extra.DayOfYear, otherwise false.

+

days

(days i)

Returns a Period of i days.

+

duration

(duration)(duration arg0)(duration arg0 arg1)

Creates a duration - a temporal entity representing standard days, hours, minutes, millis, micros and nanos. The duration itself contains only seconds and nanos as properties.

Given one argument will:

  • interpret as millis if a number
  • @@ -83,15 +84,15 @@
  • get a duration between two Temporals
  • get a duration of a specified unit, e.g. (duration 100 :seconds)
-

duration?

(duration? v)

Returns true if v is an instance of java.time.Duration, otherwise false.

-

end

(end i)

Gets the end instant of the interval

-

field

(field k)(field entity k)

Returns a TemporalField for the given key k or extracts the field from the given temporal entity.

+

duration?

(duration? v)

Returns true if v is an instance of java.time.Duration, otherwise false.

+

end

(end i)

Gets the end instant of the interval

+

field

(field k)(field entity k)

Returns a TemporalField for the given key k or extracts the field from the given temporal entity.

You can see predefined fields via java-time.repl/show-fields.

If you want to make your own custom TemporalFields resolvable, you need to rebind the java-time.properties/*fields* to a custom java_time.properties.FieldGroup.

-

field?

(field? o)

True if this is a TemporalField.

-

fields

(fields o)

Fields present in this temporal entity

-

fixed-clock

(fixed-clock)(fixed-clock i)(fixed-clock i z)

Creates a fixed clock either at the current instant or at the supplied instant/instant + zone.

-

format

(format o)(format fmt o)

Formats the given time entity as a string.

+

field?

(field? o)

True if this is a TemporalField.

+

fields

(fields o)

Fields present in this temporal entity

+

fixed-clock

(fixed-clock)(fixed-clock i)(fixed-clock i z)

Creates a fixed clock either at the current instant or at the supplied instant/instant + zone.

+

format

(format o)(format fmt o)

Formats the given time entity as a string.

Accepts something that can be converted to a DateTimeFormatter or a formatter key, e.g. :iso-offset-time, as a first argument. Given one argument uses the default format.

(format (zoned-date-time))
 => "2015-03-21T09:22:46.677800+01:00[Europe/London]"
@@ -99,7 +100,7 @@
 (format :iso-date (zoned-date-time))
 "2015-03-21+01:00"
 
-

formatter

(formatter fmt)(formatter fmt arg1)

Constructs a DateTimeFormatter out of a

+

formatter

(formatter fmt)(formatter fmt arg1)

Constructs a DateTimeFormatter out of a

  • format string - “yyyy/MM/dd”, “HH:mm”, etc.
  • formatter name - :iso-date, :iso-time, etc.
  • @@ -109,10 +110,10 @@
  • resolver-style - either :strict, :smartor :lenient
  • case - either :insensitive or :sensitive (defaults to :sensitive)
-

friday?

(friday? i)

Returns true if the given time entity with the day-of-week property falls on a Friday, otherwise false.

-

gap

(gap i oi)

Gets the gap between this interval and the other one or nil

-

hours

(hours i)

Returns a Duration of i hours.

-

instant

(instant)(instant arg0)(instant arg0 arg1)

Creates an Instant. The following arguments are supported:

+

friday?

(friday? i)

Returns true if the given time entity with the day-of-week property falls on a Friday, otherwise false.

+

gap

(gap i oi)

Gets the gap between this interval and the other one or nil

+

hours

(hours i)

Returns a Duration of i hours.

+

instant

(instant)(instant arg0)(instant arg0 arg1)

Creates an Instant. The following arguments are supported:

  • no arguments - current instant
  • one argument @@ -130,11 +131,11 @@
-

instant->sql-timestamp

(instant->sql-timestamp instant-or-millis)

Creates a java.sql.Timestamp from the provided instant-or-millis - a millisecond numeric time value or something convertible to an Instant.

+

instant->sql-timestamp

(instant->sql-timestamp instant-or-millis)

Creates a java.sql.Timestamp from the provided instant-or-millis - a millisecond numeric time value or something convertible to an Instant.

Please consider using the JSR-310 Java Time types instead of java.sql.Timestamp if your drivers support them.

java.sql.Timestamp is a version of a java.util.Date supposed to be used as a local date-time (no time zone) for the purposes of conversion from/to native JDBC driver TIMESTAMP types.

-

instant?

(instant? v)

Returns true if v is an instance of java.time.Instant, otherwise false.

-

interval

(interval o)(interval a b)

Constructs an interval out of a string, start and end instants or a start + duration:

+

instant?

(instant? v)

Returns true if v is an instance of java.time.Instant, otherwise false.

+

interval

(interval o)(interval a b)

Constructs an interval out of a string, start and end instants or a start + duration:

(j/interval "2010-01-01T00:00:00Z/2013-01-01T00:00:00Z")
 => #<Interval 2010-01-01T00:00:00Z/2013-01-01T00:00:00Z>
 
@@ -145,8 +146,8 @@
 => #<Interval 1970-01-01T00:01:40Z/1970-01-01T00:16:40Z>
 

Requires the optional threeten-extra dependency.

-

interval?

(interval? o)

True if Interval

-

iterate

(iterate f initial v & vs)

Returns a lazy sequence of initial , (apply f initial v vs), etc.

+

interval?

(interval? o)

True if Interval

+

iterate

(iterate f initial v & vs)

Returns a lazy sequence of initial , (apply f initial v vs), etc.

Useful when you want to produce a sequence of temporal entities, for example:

(iterate plus (days 0) 1)
 => (#<Period P0D> #<Period P1D> #<Period P2D> ...)
@@ -157,11 +158,11 @@
 (iterate adjust (local-date 2010 1 1) :next-working-day)
 => (#<LocalDate 2010-01-01> #<LocalDate 2010-01-04> ...)
 
-

java-date

(java-date)(java-date a)(java-date a b)

Creates a java.util.Date out of any combination of arguments valid for instant or the Instant itself.

+

java-date

(java-date)(java-date a)(java-date a b)

Creates a java.util.Date out of any combination of arguments valid for instant or the Instant itself.

A java.util.Date represents an instant in time. It’s a direct analog of the java.time.Instant type introduced in the JSR-310. Please consider using the java.time.Instant (through instant) directly.

-

largest-min-value

(largest-min-value p)

Largest minimum value of this property

-

leap?

(leap? o)

True if the year of this entity is a leap year.

-

local-date

(local-date)(local-date arg0)(local-date arg0 arg1)(local-date arg0 arg1 arg2)

Creates a LocalDate. The following arguments are supported:

+

largest-min-value

(largest-min-value p)

Largest minimum value of this property

+

leap?

(leap? o)

True if the year of this entity is a leap year.

+

local-date

(local-date)(local-date arg0)(local-date arg0 arg1)(local-date arg0 arg1 arg2)

Creates a LocalDate. The following arguments are supported:

  • no arguments - current local-date
  • one argument @@ -186,7 +187,7 @@
-

local-date-time

(local-date-time)(local-date-time y m d h)(local-date-time y m d h mm)(local-date-time y m d h mm ss)(local-date-time y m d h mm ss n)(local-date-time arg0)(local-date-time arg0 arg1)(local-date-time arg0 arg1 arg2)

Creates a LocalDateTime. The following arguments are supported:

+

local-date-time

(local-date-time)(local-date-time y m d h)(local-date-time y m d h mm)(local-date-time y m d h mm ss)(local-date-time y m d h mm ss n)(local-date-time arg0)(local-date-time arg0 arg1)(local-date-time arg0 arg1 arg2)

Creates a LocalDateTime. The following arguments are supported:

  • no arguments - current local date-time
  • one argument @@ -209,9 +210,9 @@

    three and more arguments - year/month/day/…

-

local-date-time?

(local-date-time? v)

Returns true if v is an instance of java.time.LocalDateTime, otherwise false.

-

local-date?

(local-date? v)

Returns true if v is an instance of java.time.LocalDate, otherwise false.

-

local-time

(local-time)(local-time h m s nn)(local-time arg0)(local-time arg0 arg1)(local-time arg0 arg1 arg2)

Creates a LocalTime. The following arguments are supported:

+

local-date-time?

(local-date-time? v)

Returns true if v is an instance of java.time.LocalDateTime, otherwise false.

+

local-date?

(local-date? v)

Returns true if v is an instance of java.time.LocalDate, otherwise false.

+

local-time

(local-time)(local-time h m s nn)(local-time arg0)(local-time arg0 arg1)(local-time arg0 arg1 arg2)

Creates a LocalTime. The following arguments are supported:

  • no arguments - current local time
  • one argument @@ -231,19 +232,19 @@
  • three/four arguments - hour, minute, second, nanos
-

local-time?

(local-time? v)

Returns true if v is an instance of java.time.LocalTime, otherwise false.

-

max

(max o & os)

Latest/longest of the given time entities. Entities should be of the same type

-

max-value

(max-value p)

Maximum value of this property, e.g. 29th of February for months

-

micros

(micros micros)

Duration of a specified number of microseconds.

-

millis

(millis i)

Returns a Duration of i millis.

-

min

(min o & os)

Earliest/shortest of the given time entities. Entities should be of the same type

-

min-value

(min-value p)

Minimum value of this property

-

minus

(minus o & os)

Subtracts all of the os from the time entity o

+

local-time?

(local-time? v)

Returns true if v is an instance of java.time.LocalTime, otherwise false.

+

max

(max o & os)

Latest/longest of the given time entities. Entities should be of the same type

+

max-value

(max-value p)

Maximum value of this property, e.g. 29th of February for months

+

micros

(micros micros)

Duration of a specified number of microseconds.

+

millis

(millis i)

Returns a Duration of i millis.

+

min

(min o & os)

Earliest/shortest of the given time entities. Entities should be of the same type

+

min-value

(min-value p)

Minimum value of this property

+

minus

(minus o & os)

Subtracts all of the os from the time entity o

(j/minus (j/local-date 2015) (j/years 1))
 => <java.time.LocalDate "2014-01-01">
 
-

minutes

(minutes i)

Returns a Duration of i minutes.

-

mock-clock

(mock-clock)(mock-clock instant)(mock-clock instant zone)

Returns a mock implementation of the java.time.Clock. The mock supports advance-clock! operation which allows to move the time in the clock, e.g.:

+

minutes

(minutes i)

Returns a Duration of i minutes.

+

mock-clock

(mock-clock)(mock-clock instant)(mock-clock instant zone)

Returns a mock implementation of the java.time.Clock. The mock supports advance-clock! operation which allows to move the time in the clock, e.g.:

(let [clock (mock-clock 0 "UTC")]
   (with-clock clock
     (is (= (value clock) 0))
@@ -254,13 +255,14 @@
 

You can move the clock back via advancing by a negative temporal amount.

Creates a clock at epoch in the default time zone when called without arguments.

-

monday?

(monday? i)

Returns true if the given time entity with the day-of-week property falls on a Monday, otherwise false.

-

month

(month)(month v)(month fmt arg)

Returns the Month for the given month keyword name (e.g. :january), ordinal or entity. Current month if no arguments given.

-

month-day

(month-day)(month-day arg)(month-day a b)

Returns the MonthDay for the given entity, string, clock, zone or month/day combination. Current month-day if no arguments given.

-

month-day?

(month-day? o)

Returns true if o is java.time.MonthDay, otherwise false.

-

month?

(month? o)

True if java.time.Month.

-

months

(months i)

Returns a Period of i months.

-

move-end-by

(move-end-by i & os)

Moves the end instant of the interval by the sum of given periods/durations/numbers of milliseconds.

+

Not available in babashka.

+

monday?

(monday? i)

Returns true if the given time entity with the day-of-week property falls on a Monday, otherwise false.

+

month

(month)(month v)(month fmt arg)

Returns the Month for the given month keyword name (e.g. :january), ordinal or entity. Current month if no arguments given.

+

month-day

(month-day)(month-day arg)(month-day a b)

Returns the MonthDay for the given entity, string, clock, zone or month/day combination. Current month-day if no arguments given.

+

month-day?

(month-day? o)

Returns true if o is java.time.MonthDay, otherwise false.

+

month?

(month? o)

True if java.time.Month.

+

months

(months i)

Returns a Period of i months.

+

move-end-by

(move-end-by i & os)

Moves the end instant of the interval by the sum of given periods/durations/numbers of milliseconds.

(move-start-by (interval 0 10000) (millis 1000) (seconds 1))
 => #<Interval ...:00Z/...:12Z>
 
@@ -268,7 +270,7 @@
(move-end-by (interval 0 10000) (millis -11000))
 => DateTimeException...
 
-

move-end-to

(move-end-to i new-end)

Moves the end of the interval to the given instant (or something convertible to an instant):

+

move-end-to

(move-end-to i new-end)

Moves the end of the interval to the given instant (or something convertible to an instant):

(move-end-to (interval 0 10000) (instant 15000))
 => #<Interval ...:00Z/...:15Z>
 
@@ -276,7 +278,7 @@
(move-end-to (interval 0 10000) (millis -1))
 => DateTimeException...
 
-

move-start-by

(move-start-by i & os)

Moves the start instant of the interval by the sum of given periods/durations/numbers of milliseconds:

+

move-start-by

(move-start-by i & os)

Moves the start instant of the interval by the sum of given periods/durations/numbers of milliseconds:

(move-start-by (interval 0 10000) (millis 1000) (seconds 1))
 => #<Interval ...:02Z/...:10Z>
 
@@ -284,7 +286,7 @@
(move-start-by (interval 0 10000) (millis 11000))
 ;=> DateTimeException...
 
-

move-start-to

(move-start-to i new-start)

Moves the start instant of the interval to the given instant (or something convertible to an instant):

+

move-start-to

(move-start-to i new-start)

Moves the start instant of the interval to the given instant (or something convertible to an instant):

(move-start-to (interval 0 10000) (instant 5000))
 => #<Interval ...:05Z/...:10Z>
 
@@ -292,15 +294,15 @@
(move-start-to (interval 0 10000) (millis 15000))
 => DateTimeException...
 
-

multiply-by

(multiply-by o v)

Entity o multiplied by the value v

-

nanos

(nanos i)

Returns a Duration of i nanos.

-

negate

(negate a)

Negates a temporal amount:

+

multiply-by

(multiply-by o v)

Entity o multiplied by the value v

+

nanos

(nanos i)

Returns a Duration of i nanos.

+

negate

(negate a)

Negates a temporal amount:

(negate (negate x)) == x

-

negative?

(negative? a)

True if the amount is negative

-

not-after?

(not-after? x)(not-after? x y)(not-after? x y & more)

Like before?, except returns true if the inputs are equal.

-

not-before?

(not-before? x)(not-before? x y)(not-before? x y & more)

Like after?, except returns true if the inputs are equal.

-

offset-clock

(offset-clock d)(offset-clock c d)

Creates a clock offset from the current/provided clock by a given duration.

-

offset-date-time

(offset-date-time)(offset-date-time y m d h)(offset-date-time y mo d h m)(offset-date-time y mo d h m s)(offset-date-time y mo d h m s n)(offset-date-time y mo d h m s n o)(offset-date-time arg0)(offset-date-time arg0 arg1)(offset-date-time arg0 arg1 arg2)

Creates an OffsetDateTime. The following arguments are supported:

+

negative?

(negative? a)

True if the amount is negative

+

not-after?

(not-after? x)(not-after? x y)(not-after? x y & more)

Like before?, except returns true if the inputs are equal.

+

not-before?

(not-before? x)(not-before? x y)(not-before? x y & more)

Like after?, except returns true if the inputs are equal.

+

offset-clock

(offset-clock d)(offset-clock c d)

Creates a clock offset from the current/provided clock by a given duration.

+

offset-date-time

(offset-date-time)(offset-date-time y m d h)(offset-date-time y mo d h m)(offset-date-time y mo d h m s)(offset-date-time y mo d h m s n)(offset-date-time y mo d h m s n o)(offset-date-time arg0)(offset-date-time arg0 arg1)(offset-date-time arg0 arg1 arg2)

Creates an OffsetDateTime. The following arguments are supported:

  • no arguments - current date-time with the default offset
  • one argument @@ -330,8 +332,8 @@
  • eight arguments - time fields up to nanoseconds and a zone offset

If zone offset is not specified, default will be used. You can check the default offset by invoking (zone-offset).

-

offset-date-time?

(offset-date-time? v)

Returns true if v is an instance of java.time.OffsetDateTime, otherwise false.

-

offset-time

(offset-time)(offset-time h m s)(offset-time h m s n)(offset-time h m s n o)(offset-time arg0)(offset-time arg0 arg1)

Creates an OffsetTime. The following arguments are supported:

+

offset-date-time?

(offset-date-time? v)

Returns true if v is an instance of java.time.OffsetDateTime, otherwise false.

+

offset-time

(offset-time)(offset-time h m s)(offset-time h m s n)(offset-time h m s n o)(offset-time arg0)(offset-time arg0 arg1)

Creates an OffsetTime. The following arguments are supported:

  • no arguments - current time with the default offset
  • one argument @@ -356,10 +358,10 @@
  • five arguments - last is the offset

If zone offset is not specified, default will be used. You can check the default offset by invoking (zone-offset).

-

offset-time?

(offset-time? v)

Returns true if v is an instance of java.time.OffsetTime, otherwise false.

-

overlap

(overlap i oi)

Gets the overlap between this interval and the other one or nil

-

overlaps?

(overlaps? i oi)

True if this interval overlaps the other one

-

period

(period)(period arg0)(period arg0 arg1)(period arg0 arg1 arg2)

Creates a period - a temporal entity consisting of years, months and days.

+

offset-time?

(offset-time? v)

Returns true if v is an instance of java.time.OffsetTime, otherwise false.

+

overlap

(overlap i oi)

Gets the overlap between this interval and the other one or nil

+

overlaps?

(overlaps? i oi)

True if this interval overlaps the other one

+

period

(period)(period arg0)(period arg0 arg1)(period arg0 arg1 arg2)

Creates a period - a temporal entity consisting of years, months and days.

Given one argument will

  • interpret as years if a number
  • @@ -374,98 +376,99 @@
  • get a period of a specified number of years and months

Given three arguments will create a year/month/day period.

-

period?

(period? v)

Returns true if v is an instance of java.time.Period, otherwise false.

-

plus

(plus o & os)

Adds all of the os to the time entity o. plus is not commutative, the first argument is always the entity which will accumulate the rest of the arguments.

+

period?

(period? v)

Returns true if v is an instance of java.time.Period, otherwise false.

+

plus

(plus o & os)

Adds all of the os to the time entity o. plus is not commutative, the first argument is always the entity which will accumulate the rest of the arguments.

(j/plus (j/local-date 2015) (j/years 1))
 => <java.time.LocalDate "2016-01-01">
 
-

properties

(properties o)

Map of properties present in this temporal entity

-

property

(property o k)

Property of this temporal entity under key k

-

quarter

(quarter)(quarter v)(quarter fmt arg)

Returns the Quarter for the given quarter keyword name (e.g. :q1), ordinal or entity. Current quarter if no arguments given.

-

quarter?

(quarter? o)

True if org.threeten.extra.Quarter.

-

range

(range p)

Range of values for this property

-

saturday?

(saturday? i)

Returns true if the given time entity with the day-of-week property falls on a Saturday, otherwise false.

-

seconds

(seconds i)

Returns a Duration of i seconds.

-

set-clock!

(set-clock! clock time)

Sets the clock to the given time.

+

properties

(properties o)

Map of properties present in this temporal entity

+

property

(property o k)

Property of this temporal entity under key k

+

quarter

(quarter)(quarter v)(quarter fmt arg)

Returns the Quarter for the given quarter keyword name (e.g. :q1), ordinal or entity. Current quarter if no arguments given.

+

quarter?

(quarter? o)

True if org.threeten.extra.Quarter.

+

range

(range p)

Range of values for this property

+

saturday?

(saturday? i)

Returns true if the given time entity with the day-of-week property falls on a Saturday, otherwise false.

+

seconds

(seconds i)

Returns a Duration of i seconds.

+

set-clock!

(set-clock! clock time)

Sets the clock to the given time.

This mutates the mock clock.

-

smallest-max-value

(smallest-max-value p)

Smallest maximum value of this property, e.g. 28th of February for months

-

sql-date

(sql-date)(sql-date arg0)(sql-date arg0 arg1)(sql-date arg0 arg1 arg2)

Creates a java.sql.Date out of any combination of arguments valid for local-date or the LocalDate itself.

+

Not available in babashka.

+

smallest-max-value

(smallest-max-value p)

Smallest maximum value of this property, e.g. 28th of February for months

+

sql-date

(sql-date)(sql-date arg0)(sql-date arg0 arg1)(sql-date arg0 arg1 arg2)

Creates a java.sql.Date out of any combination of arguments valid for local-date or the LocalDate itself.

Please consider using the JSR-310 Java Time types instead of java.sql.Date if your drivers support them.

Even though java.sql.Date extends a java.util.Date, it’s supposed to be used as a local date (no time component or time zone) for the purposes of conversion from/to native JDBC driver DATE types.

-

sql-time

(sql-time)(sql-time arg0)(sql-time arg0 arg1)(sql-time arg0 arg1 arg2)

Creates a java.sql.Time out of any combination of arguments valid for local-time (except the nanos constructor) or the LocalTime itself.

+

sql-time

(sql-time)(sql-time arg0)(sql-time arg0 arg1)(sql-time arg0 arg1 arg2)

Creates a java.sql.Time out of any combination of arguments valid for local-time (except the nanos constructor) or the LocalTime itself.

Please consider using the JSR-310 Java Time types instead of java.sql.Time if your drivers support them.

Even though java.sql.Time extends a java.util.Date, it’s supposed to be used as a local time (no date component or time zone) for the purposes of conversion from/to native JDBC driver TIME types.

-

sql-timestamp

(sql-timestamp)(sql-timestamp arg0)(sql-timestamp arg0 arg1)(sql-timestamp arg0 arg1 arg2)(sql-timestamp arg0 arg1 arg2 arg3)(sql-timestamp arg0 arg1 arg2 arg3 arg4)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5 arg6)

Creates a java.sql.Timestamp in the local time zone out of any combination of arguments valid for local-date-time or the LocalDateTime itself.

+

sql-timestamp

(sql-timestamp)(sql-timestamp arg0)(sql-timestamp arg0 arg1)(sql-timestamp arg0 arg1 arg2)(sql-timestamp arg0 arg1 arg2 arg3)(sql-timestamp arg0 arg1 arg2 arg3 arg4)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5 arg6)

Creates a java.sql.Timestamp in the local time zone out of any combination of arguments valid for local-date-time or the LocalDateTime itself.

Does not support Timestamp construction from an Instant or a long millis value—please use instant->sql-timestamp for this purpose.

Please consider using the JSR-310 Java Time types instead of java.sql.Timestamp if your drivers support them.

java.sql.Timestamp is a version of a java.util.Date supposed to be used as a local date-time (no time zone) for the purposes of conversion from/to native JDBC driver TIMESTAMP types.

-

standard-days

(standard-days i)

Returns a Duration of i days.

-

start

(start i)

Gets the start instant of the interval

-

sunday?

(sunday? i)

Returns true if the given time entity with the day-of-week property falls on a Sunday, otherwise false.

-

supports?

(supports? o p)

True if the o entity supports the p property

-

system-clock

(system-clock)(system-clock k)

Creates a system clock. In the default time zone if called without arguments, otherwise accepts a Zone Id.

-

thursday?

(thursday? i)

Returns true if the given time entity with the day-of-week property falls on a Thursday, otherwise false.

-

tick-clock

(tick-clock d)(tick-clock c d)

Creates a clock wrapping system/provided clock that only ticks as per specified duration.

-

time-between

(time-between o e u)

Time between temporal entities o and e in unit u.

+

standard-days

(standard-days i)

Returns a Duration of i days.

+

start

(start i)

Gets the start instant of the interval

+

sunday?

(sunday? i)

Returns true if the given time entity with the day-of-week property falls on a Sunday, otherwise false.

+

supports?

(supports? o p)

True if the o entity supports the p property

+

system-clock

(system-clock)(system-clock k)

Creates a system clock. In the default time zone if called without arguments, otherwise accepts a Zone Id.

+

thursday?

(thursday? i)

Returns true if the given time entity with the day-of-week property falls on a Thursday, otherwise false.

+

tick-clock

(tick-clock d)(tick-clock c d)

Creates a clock wrapping system/provided clock that only ticks as per specified duration.

+

time-between

(time-between o e u)

Time between temporal entities o and e in unit u.

(j/time-between (j/local-date 2015) (j/local-date 2016) :days)
 => 365
 
 (j/time-between :days (j/local-date 2015) (j/local-date 2016))
 => 365
 
-

to-java-date

deprecated

(to-java-date o)

Converts a date entity to a java.util.Date.

+

to-java-date

deprecated

(to-java-date o)

Converts a date entity to a java.util.Date.

Deprecated: This function only has a single arity and works for entities directly convertible to java.time.Instant. Please consider using java-date instead.

-

to-millis-from-epoch

(to-millis-from-epoch o)

Converts a date entity to a long representing the number of milliseconds from epoch.

-

to-sql-date

deprecated

(to-sql-date o)

Converts a local date entity to a java.sql.Date.

+

to-millis-from-epoch

(to-millis-from-epoch o)

Converts a date entity to a long representing the number of milliseconds from epoch.

+

to-sql-date

deprecated

(to-sql-date o)

Converts a local date entity to a java.sql.Date.

Deprecated: This function only has a single arity and works for entities directly convertible to java.time.LocalDate. Please consider using sql-date instead.

-

to-sql-timestamp

deprecated

(to-sql-timestamp o)

Converts a date entity to a java.sql.Timestamp.

+

to-sql-timestamp

deprecated

(to-sql-timestamp o)

Converts a date entity to a java.sql.Timestamp.

Deprecated: This function only has a single arity and works for entities directly convertible to java.time.Instant. Please consider using sql-timestamp instead.

-

truncate-to

(truncate-to o u)

Truncates this entity to the specified time unit. Only works for units that divide into the length of standard day without remainder (up to :days).

-

tuesday?

(tuesday? i)

Returns true if the given time entity with the day-of-week property falls on a Tuesday, otherwise false.

-

unit

(unit k)(unit entity k)

Returns a TemporalUnit for the given key k or extracts the field from the given temporal entity.

+

truncate-to

(truncate-to o u)

Truncates this entity to the specified time unit. Only works for units that divide into the length of standard day without remainder (up to :days).

+

tuesday?

(tuesday? i)

Returns true if the given time entity with the day-of-week property falls on a Tuesday, otherwise false.

+

unit

(unit k)(unit entity k)

Returns a TemporalUnit for the given key k or extracts the field from the given temporal entity.

You can see predefined units via java-time.repl/show-units.

If you want to make your own custom TemporalUnits resolvable, you need to rebind the java-time.properties/*units* to a custom java_time.properties.UnitGroup.

-

unit?

(unit? o)

True if this is a TemporalUnit.

-

units

(units o)

Units present in this temporal entity.

-

value

(value p)

Value of the property

-

value-range

(value-range min max)(value-range arg0)

Creates a ValueRange given the min and max amounts or a map of :min-smallest, :max-smallest, :min-largest and :max-largest.

-

wednesday?

(wednesday? i)

Returns true if the given time entity with the day-of-week property falls on a Wednesday, otherwise false.

-

weekday?

(weekday? dt)

Complement of weekend?.

-

weekend?

(weekend? dt)

Returns true if argument is saturday? or sunday?, otherwise false.

-

weeks

(weeks i)

Returns a Period of i weeks.

-

when-joda-time-loaded

macro

(when-joda-time-loaded & body)

Execute the body when Joda-Time classes are found on the classpath.

+

unit?

(unit? o)

True if this is a TemporalUnit.

+

units

(units o)

Units present in this temporal entity.

+

value

(value p)

Value of the property

+

value-range

(value-range min max)(value-range arg0)

Creates a ValueRange given the min and max amounts or a map of :min-smallest, :max-smallest, :min-largest and :max-largest.

+

wednesday?

(wednesday? i)

Returns true if the given time entity with the day-of-week property falls on a Wednesday, otherwise false.

+

weekday?

(weekday? dt)

Complement of weekend?.

+

weekend?

(weekend? dt)

Returns true if argument is saturday? or sunday?, otherwise false.

+

weeks

(weeks i)

Returns a Period of i weeks.

+

when-joda-time-loaded

macro

(when-joda-time-loaded & body)

Execute the body when Joda-Time classes are found on the classpath.

Take care - when AOT-compiling code using this macro, the Joda-Time classes must be on the classpath at compile time!

-

with-clock

macro

(with-clock c & forms)

Executes the given forms in the scope of the provided clock.

+

with-clock

macro

(with-clock c & forms)

Executes the given forms in the scope of the provided clock.

All the temporal entities that get created without parameters will inherit their values from the clock:

(with-clock (system-clock “Europe/London”) (zone-id)) => #<java.time.ZoneRegion Europe/London>

-

with-clock-fn

(with-clock-fn c f)

Executes the given function in the scope of the provided clock. All the temporal entities that get created without parameters will inherit their values from the clock.

-

with-largest-min-value

(with-largest-min-value p)

Underlying temporal entity with the value set to the largest minimum available for this property

-

with-max-value

(with-max-value p)

Underlying temporal entity with the value set to the maximum available for this property

-

with-min-value

(with-min-value p)

Underlying temporal entity with the value set to the minimum available for this property

-

with-offset

(with-offset o offset)

Sets the offset to the specified value ensuring that the local time stays the same.

+

with-clock-fn

(with-clock-fn c f)

Executes the given function in the scope of the provided clock. All the temporal entities that get created without parameters will inherit their values from the clock.

+

with-largest-min-value

(with-largest-min-value p)

Underlying temporal entity with the value set to the largest minimum available for this property

+

with-max-value

(with-max-value p)

Underlying temporal entity with the value set to the maximum available for this property

+

with-min-value

(with-min-value p)

Underlying temporal entity with the value set to the minimum available for this property

+

with-offset

(with-offset o offset)

Sets the offset to the specified value ensuring that the local time stays the same.

(offset-time 10 30 0 0 +2) => #<java.time.OffsetTime 10:30+02:00> (with-offset *1 +3) => #<java.time.OffsetTime 10:30+03:00>

-

with-offset-same-instant

(with-offset-same-instant o offset)

Sets the offset to the specified value ensuring that the result has the same instant, e.g.:

+

with-offset-same-instant

(with-offset-same-instant o offset)

Sets the offset to the specified value ensuring that the result has the same instant, e.g.:

(offset-time 10 30 0 0 +2) => #<java.time.OffsetTime 10:30+02:00> (with-offset-same-instant *1 +3) => #<java.time.OffsetTime 11:30+03:00>

-

with-smallest-max-value

(with-smallest-max-value p)

Underlying temporal entity with the value set to the smallest maximum available for this property

-

with-value

(with-value p v)

Underlying temporal entity with the value of this property set to v

-

with-zone

(with-zone o z)

Returns this temporal entity with the specified ZoneId

-

with-zone-same-instant

(with-zone-same-instant zdt z)

Sets the zone to the specified value ensuring that the result has the same instant, e.g.:

+

with-smallest-max-value

(with-smallest-max-value p)

Underlying temporal entity with the value set to the smallest maximum available for this property

+

with-value

(with-value p v)

Underlying temporal entity with the value of this property set to v

+

with-zone

(with-zone o z)

Returns this temporal entity with the specified ZoneId

+

with-zone-same-instant

(with-zone-same-instant zdt z)

Sets the zone to the specified value ensuring that the result has the same instant, e.g.:

(zoned-date-time 2015) => #<java.time.ZonedDateTime 2015-01-01T00:00+00:00Europe/London> (with-zone-same-instant *1 “America/New_York”) => #<java.time.ZonedDateTime 2014-12-31T18:00-05:00America/New_York>

-

year

(year)(year arg)(year fmt arg)

Returns the Year for the given entity, string, clock, zone or number. Current year if no arguments given.

-

year-month

(year-month)(year-month arg)(year-month a b)

Returns the YearMonth for the given entity, string, clock, zone or month/day combination. Current year-month if no arguments given.

-

year-month?

(year-month? o)

Returns true if o is java.time.YearMonth, otherwise false.

-

year-quarter

(year-quarter)(year-quarter arg)(year-quarter a b)

Returns the YearQuarter for the given entity, clock, zone or year with quarter. Current year quarter if no arguments given.

-

year-quarter?

(year-quarter? o)

Returns true if o is org.threeten.extra.YearQuarter, otherwise false.

-

year?

(year? o)

Returns true if o is java.time.Year, otherwise false.

-

years

(years i)

Returns a Period of i years.

-

zero?

(zero? a)

True if the amount is zero

-

zone-id

(zone-id)(zone-id arg0)(zone-id arg0 arg1)

Creates a ZoneId from a string identifier, java.util.TimeZone or extracts from another temporal entity.

+

year

(year)(year arg)(year fmt arg)

Returns the Year for the given entity, string, clock, zone or number. Current year if no arguments given.

+

year-month

(year-month)(year-month arg)(year-month a b)

Returns the YearMonth for the given entity, string, clock, zone or month/day combination. Current year-month if no arguments given.

+

year-month?

(year-month? o)

Returns true if o is java.time.YearMonth, otherwise false.

+

year-quarter

(year-quarter)(year-quarter arg)(year-quarter a b)

Returns the YearQuarter for the given entity, clock, zone or year with quarter. Current year quarter if no arguments given.

+

year-quarter?

(year-quarter? o)

Returns true if o is org.threeten.extra.YearQuarter, otherwise false.

+

year?

(year? o)

Returns true if o is java.time.Year, otherwise false.

+

years

(years i)

Returns a Period of i years.

+

zero?

(zero? a)

True if the amount is zero

+

zone-id

(zone-id)(zone-id arg0)(zone-id arg0 arg1)

Creates a ZoneId from a string identifier, java.util.TimeZone or extracts from another temporal entity.

Returns default system zone id if no arguments provided.

Given two arguments will use the second as the offset.

-

zone-id?

(zone-id? v)

Returns true if v is an instance of java.time.ZoneId, otherwise false.

-

zone-offset

(zone-offset)(zone-offset o)(zone-offset h m)(zone-offset h m s)

Creates a ZoneOffset from a string identifier (e.g. “+01”), a number of hours/hours and minutes/hours, minutes and seconds or extracts from another temporal entity.

+

zone-id?

(zone-id? v)

Returns true if v is an instance of java.time.ZoneId, otherwise false.

+

zone-offset

(zone-offset)(zone-offset o)(zone-offset h m)(zone-offset h m s)

Creates a ZoneOffset from a string identifier (e.g. “+01”), a number of hours/hours and minutes/hours, minutes and seconds or extracts from another temporal entity.

Returns default system zone offset if no arguments provided.

-

zoned-date-time

(zoned-date-time)(zoned-date-time y m d h)(zoned-date-time y mo d h m)(zoned-date-time y mo d h m s)(zoned-date-time y mo d h m s n)(zoned-date-time y mo d h m s n o)(zoned-date-time arg0)(zoned-date-time arg0 arg1)(zoned-date-time arg0 arg1 arg2)

Creates a ZonedDateTime. The following arguments are supported:

+

zoned-date-time

(zoned-date-time)(zoned-date-time y m d h)(zoned-date-time y mo d h m)(zoned-date-time y mo d h m s)(zoned-date-time y mo d h m s n)(zoned-date-time y mo d h m s n o)(zoned-date-time arg0)(zoned-date-time arg0 arg1)(zoned-date-time arg0 arg1 arg2)

Creates a ZonedDateTime. The following arguments are supported:

  • no arguments - current date-time in the default zone
  • one argument @@ -494,5 +497,5 @@
  • eight arguments - last is the zone id

If zone id is not specified, default zone id will be used. You can check the default zone by invoking (zone-id).

-

zoned-date-time?

(zoned-date-time? v)

Returns true if v is an instance of java.time.ZonedDateTime, otherwise false.

-
\ No newline at end of file +

zoned-date-time?

(zoned-date-time? v)

Returns true if v is an instance of java.time.ZonedDateTime, otherwise false.

+
\ No newline at end of file diff --git a/docs/java-time.html b/docs/java-time.html index 924e4f1..a5405e9 100644 --- a/docs/java-time.html +++ b/docs/java-time.html @@ -8,8 +8,8 @@

abs

(abs a)

Returns the absolute value of a temporal amount:

(abs (negate x)) == (abs x)

-

abuts?

(abuts? i oi)

True if this interval abut with the other one

-

adjust

(adjust entity adjuster & args)

Adjusts the temporal entity using the provided adjuster with optional args.

+

abuts?

(abuts? i oi)

True if this interval abut with the other one

+

adjust

(adjust entity adjuster & args)

Adjusts the temporal entity using the provided adjuster with optional args.

The adjuster should either be a keyword which resolves to one of the predefined adjusters (see java-time.repl/show-adjusters) an instance of TemporalAdjuster or a function which returns another temporal entity when applied to the given one:

(adjust (local-date 2015 1 1) :next-working-day)
 => #<LocalDate 2015-1-2>
@@ -20,9 +20,10 @@
 (adjust (local-date 2015 1 1) plus (days 1))
 => #<LocalDate 2015-1-2>
 
-

advance-clock!

(advance-clock! clock amount)

Advances the clock by the given time amount.

+

advance-clock!

(advance-clock! clock amount)

Advances the clock by the given time amount.

This mutates the mock clock.

-

after?

(after? x)(after? x y)(after? x y & more)

Returns true if time entities are ordered from the latest to the earliest (same semantics as >), otherwise false.

+

Not available in babashka.

+

after?

(after? x)(after? x y)(after? x y & more)

Returns true if time entities are ordered from the latest to the earliest (same semantics as >), otherwise false.

(after? (local-date 2011) (local-date 2010) (local-date 2009))
 => true
 
@@ -30,24 +31,24 @@
         (interval (instant 10000) (instant 1000000)))
 => true
 
-

am-pm

(am-pm)(am-pm v)(am-pm fmt arg)

Returns the AmPm for the given keyword name (:am or :pm), ordinal or entity. Current AM/PM if no arguments given.

-

am-pm?

(am-pm? o)

True if org.threeten.extra.AmPm.

-

as

(as o k)(as o k1 k2)(as o k1 k2 & ks)

Values of property/unit identified by keys/objects ks of the temporal entity o, e.g.

+

am-pm

(am-pm)(am-pm v)(am-pm fmt arg)

Returns the AmPm for the given keyword name (:am or :pm), ordinal or entity. Current AM/PM if no arguments given.

+

am-pm?

(am-pm? o)

True if org.threeten.extra.AmPm.

+

as

(as o k)(as o k1 k2)(as o k1 k2 & ks)

Values of property/unit identified by keys/objects ks of the temporal entity o, e.g.

(as (duration 1 :hour) :minutes)
 => 60
 
 (as (local-date 2015 9) :year :month-of-year)
 => [2015 9]
 
-

as-map

(as-map e)(as-map e value-fn)

Converts a time entity to a map of property key -> value as defined by the passed in value-fn. By default the actual value of the unit/field is produced.

+

as-map

(as-map e)(as-map e value-fn)

Converts a time entity to a map of property key -> value as defined by the passed in value-fn. By default the actual value of the unit/field is produced.

(as-map (duration))
 => {:nanos 0, :seconds 0}
 
 (as-map (local-date 2015 1 1))
 => {:year 2015, :month-of-year 1, :day-of-month 1, ...}
 
-

available-zone-ids

(available-zone-ids)

Returns a set of string identifiers for all available ZoneIds.

-

before?

(before? x)(before? x y)(before? x y & more)

Returns true if time entities are ordered from the earliest to the latest (same semantics as <), otherwise false.

+

available-zone-ids

(available-zone-ids)

Returns a set of string identifiers for all available ZoneIds.

+

before?

(before? x)(before? x y)(before? x y & more)

Returns true if time entities are ordered from the earliest to the latest (same semantics as <), otherwise false.

(before? (local-date 2009) (local-date 2010) (local-date 2011))
 => true
 
@@ -55,10 +56,10 @@
          (instant 99999999))
 => true
 
-

chronology

(chronology o)

The Chronology of the entity

-

clock?

(clock? x)

Returns true if x is an instance of java.time.Clock.

-

contains?

(contains? i o)

True if the interval contains the given instant or interval

-

convert-amount

(convert-amount amount from-unit to-unit)

Converts an amount from one unit to another. Returns a map of:

+

chronology

(chronology o)

The Chronology of the entity

+

clock?

(clock? x)

Returns true if x is an instance of java.time.Clock.

+

contains?

(contains? i o)

True if the interval contains the given instant or interval

+

convert-amount

(convert-amount amount from-unit to-unit)

Converts an amount from one unit to another. Returns a map of:

  • :whole - the whole part of the conversion in the to unit
  • :remainder - the remainder in the from unit
  • @@ -69,14 +70,14 @@
    (convert-amount 10000 :seconds :hours)
     => {:remainder 2800 :whole 2}
     
    -

day-of-month

(day-of-month)(day-of-month arg)(day-of-month fmt arg)

Returns the DayOfMonth for the given entity, clock, zone or day of month. Current day of month if no arguments given.

-

day-of-month?

(day-of-month? o)

Returns true if o is org.threeten.extra.DayOfMonth, otherwise false.

-

day-of-week

(day-of-week)(day-of-week v)(day-of-week fmt arg)

Returns the DayOfWeek for the given day keyword name (e.g. :monday), ordinal or entity. Current day if no arguments given.

-

day-of-week?

(day-of-week? o)

True if java.time.DayOfWeek.

-

day-of-year

(day-of-year)(day-of-year arg)(day-of-year fmt arg)

Returns the DayOfYear for the given entity, clock, zone or day of year. Current day of year if no arguments given.

-

day-of-year?

(day-of-year? o)

Returns true if o is org.threeten.extra.DayOfYear, otherwise false.

-

days

(days i)

Returns a Period of i days.

-

duration

(duration)(duration arg0)(duration arg0 arg1)

Creates a duration - a temporal entity representing standard days, hours, minutes, millis, micros and nanos. The duration itself contains only seconds and nanos as properties.

+

day-of-month

(day-of-month)(day-of-month arg)(day-of-month fmt arg)

Returns the DayOfMonth for the given entity, clock, zone or day of month. Current day of month if no arguments given.

+

day-of-month?

(day-of-month? o)

Returns true if o is org.threeten.extra.DayOfMonth, otherwise false.

+

day-of-week

(day-of-week)(day-of-week v)(day-of-week fmt arg)

Returns the DayOfWeek for the given day keyword name (e.g. :monday), ordinal or entity. Current day if no arguments given.

+

day-of-week?

(day-of-week? o)

True if java.time.DayOfWeek.

+

day-of-year

(day-of-year)(day-of-year arg)(day-of-year fmt arg)

Returns the DayOfYear for the given entity, clock, zone or day of year. Current day of year if no arguments given.

+

day-of-year?

(day-of-year? o)

Returns true if o is org.threeten.extra.DayOfYear, otherwise false.

+

days

(days i)

Returns a Period of i days.

+

duration

(duration)(duration arg0)(duration arg0 arg1)

Creates a duration - a temporal entity representing standard days, hours, minutes, millis, micros and nanos. The duration itself contains only seconds and nanos as properties.

Given one argument will:

  • interpret as millis if a number
  • @@ -89,15 +90,15 @@
  • get a duration between two Temporals
  • get a duration of a specified unit, e.g. (duration 100 :seconds)
-

duration?

(duration? v)

Returns true if v is an instance of java.time.Duration, otherwise false.

-

end

(end i)

Gets the end instant of the interval

-

field

(field k)(field entity k)

Returns a TemporalField for the given key k or extracts the field from the given temporal entity.

+

duration?

(duration? v)

Returns true if v is an instance of java.time.Duration, otherwise false.

+

end

(end i)

Gets the end instant of the interval

+

field

(field k)(field entity k)

Returns a TemporalField for the given key k or extracts the field from the given temporal entity.

You can see predefined fields via java-time.repl/show-fields.

If you want to make your own custom TemporalFields resolvable, you need to rebind the java-time.properties/*fields* to a custom java_time.properties.FieldGroup.

-

field?

(field? o)

True if this is a TemporalField.

-

fields

(fields o)

Fields present in this temporal entity

-

fixed-clock

(fixed-clock)(fixed-clock i)(fixed-clock i z)

Creates a fixed clock either at the current instant or at the supplied instant/instant + zone.

-

format

(format o)(format fmt o)

Formats the given time entity as a string.

+

field?

(field? o)

True if this is a TemporalField.

+

fields

(fields o)

Fields present in this temporal entity

+

fixed-clock

(fixed-clock)(fixed-clock i)(fixed-clock i z)

Creates a fixed clock either at the current instant or at the supplied instant/instant + zone.

+

format

(format o)(format fmt o)

Formats the given time entity as a string.

Accepts something that can be converted to a DateTimeFormatter or a formatter key, e.g. :iso-offset-time, as a first argument. Given one argument uses the default format.

(format (zoned-date-time))
 => "2015-03-21T09:22:46.677800+01:00[Europe/London]"
@@ -105,7 +106,7 @@
 (format :iso-date (zoned-date-time))
 "2015-03-21+01:00"
 
-

formatter

(formatter fmt)(formatter fmt arg1)

Constructs a DateTimeFormatter out of a

+

formatter

(formatter fmt)(formatter fmt arg1)

Constructs a DateTimeFormatter out of a

  • format string - “yyyy/MM/dd”, “HH:mm”, etc.
  • formatter name - :iso-date, :iso-time, etc.
  • @@ -115,10 +116,10 @@
  • resolver-style - either :strict, :smartor :lenient
  • case - either :insensitive or :sensitive (defaults to :sensitive)
-

friday?

(friday? i)

Returns true if the given time entity with the day-of-week property falls on a Friday, otherwise false.

-

gap

(gap i oi)

Gets the gap between this interval and the other one or nil

-

hours

(hours i)

Returns a Duration of i hours.

-

instant

(instant)(instant arg0)(instant arg0 arg1)

Creates an Instant. The following arguments are supported:

+

friday?

(friday? i)

Returns true if the given time entity with the day-of-week property falls on a Friday, otherwise false.

+

gap

(gap i oi)

Gets the gap between this interval and the other one or nil

+

hours

(hours i)

Returns a Duration of i hours.

+

instant

(instant)(instant arg0)(instant arg0 arg1)

Creates an Instant. The following arguments are supported:

  • no arguments - current instant
  • one argument @@ -136,11 +137,11 @@
-

instant->sql-timestamp

(instant->sql-timestamp instant-or-millis)

Creates a java.sql.Timestamp from the provided instant-or-millis - a millisecond numeric time value or something convertible to an Instant.

+

instant->sql-timestamp

(instant->sql-timestamp instant-or-millis)

Creates a java.sql.Timestamp from the provided instant-or-millis - a millisecond numeric time value or something convertible to an Instant.

Please consider using the JSR-310 Java Time types instead of java.sql.Timestamp if your drivers support them.

java.sql.Timestamp is a version of a java.util.Date supposed to be used as a local date-time (no time zone) for the purposes of conversion from/to native JDBC driver TIMESTAMP types.

-

instant?

(instant? v)

Returns true if v is an instance of java.time.Instant, otherwise false.

-

interval

(interval o)(interval a b)

Constructs an interval out of a string, start and end instants or a start + duration:

+

instant?

(instant? v)

Returns true if v is an instance of java.time.Instant, otherwise false.

+

interval

(interval o)(interval a b)

Constructs an interval out of a string, start and end instants or a start + duration:

(j/interval "2010-01-01T00:00:00Z/2013-01-01T00:00:00Z")
 => #<Interval 2010-01-01T00:00:00Z/2013-01-01T00:00:00Z>
 
@@ -151,8 +152,8 @@
 => #<Interval 1970-01-01T00:01:40Z/1970-01-01T00:16:40Z>
 

Requires the optional threeten-extra dependency.

-

interval?

(interval? o)

True if Interval

-

iterate

(iterate f initial v & vs)

Returns a lazy sequence of initial , (apply f initial v vs), etc.

+

interval?

(interval? o)

True if Interval

+

iterate

(iterate f initial v & vs)

Returns a lazy sequence of initial , (apply f initial v vs), etc.

Useful when you want to produce a sequence of temporal entities, for example:

(iterate plus (days 0) 1)
 => (#<Period P0D> #<Period P1D> #<Period P2D> ...)
@@ -163,11 +164,11 @@
 (iterate adjust (local-date 2010 1 1) :next-working-day)
 => (#<LocalDate 2010-01-01> #<LocalDate 2010-01-04> ...)
 
-

java-date

(java-date)(java-date a)(java-date a b)

Creates a java.util.Date out of any combination of arguments valid for instant or the Instant itself.

+

java-date

(java-date)(java-date a)(java-date a b)

Creates a java.util.Date out of any combination of arguments valid for instant or the Instant itself.

A java.util.Date represents an instant in time. It’s a direct analog of the java.time.Instant type introduced in the JSR-310. Please consider using the java.time.Instant (through instant) directly.

-

largest-min-value

(largest-min-value p)

Largest minimum value of this property

-

leap?

(leap? o)

True if the year of this entity is a leap year.

-

local-date

(local-date)(local-date arg0)(local-date arg0 arg1)(local-date arg0 arg1 arg2)

Creates a LocalDate. The following arguments are supported:

+

largest-min-value

(largest-min-value p)

Largest minimum value of this property

+

leap?

(leap? o)

True if the year of this entity is a leap year.

+

local-date

(local-date)(local-date arg0)(local-date arg0 arg1)(local-date arg0 arg1 arg2)

Creates a LocalDate. The following arguments are supported:

  • no arguments - current local-date
  • one argument @@ -192,7 +193,7 @@
-

local-date-time

(local-date-time)(local-date-time y m d h)(local-date-time y m d h mm)(local-date-time y m d h mm ss)(local-date-time y m d h mm ss n)(local-date-time arg0)(local-date-time arg0 arg1)(local-date-time arg0 arg1 arg2)

Creates a LocalDateTime. The following arguments are supported:

+

local-date-time

(local-date-time)(local-date-time y m d h)(local-date-time y m d h mm)(local-date-time y m d h mm ss)(local-date-time y m d h mm ss n)(local-date-time arg0)(local-date-time arg0 arg1)(local-date-time arg0 arg1 arg2)

Creates a LocalDateTime. The following arguments are supported:

  • no arguments - current local date-time
  • one argument @@ -215,9 +216,9 @@

    three and more arguments - year/month/day/…

-

local-date-time?

(local-date-time? v)

Returns true if v is an instance of java.time.LocalDateTime, otherwise false.

-

local-date?

(local-date? v)

Returns true if v is an instance of java.time.LocalDate, otherwise false.

-

local-time

(local-time)(local-time h m s nn)(local-time arg0)(local-time arg0 arg1)(local-time arg0 arg1 arg2)

Creates a LocalTime. The following arguments are supported:

+

local-date-time?

(local-date-time? v)

Returns true if v is an instance of java.time.LocalDateTime, otherwise false.

+

local-date?

(local-date? v)

Returns true if v is an instance of java.time.LocalDate, otherwise false.

+

local-time

(local-time)(local-time h m s nn)(local-time arg0)(local-time arg0 arg1)(local-time arg0 arg1 arg2)

Creates a LocalTime. The following arguments are supported:

  • no arguments - current local time
  • one argument @@ -237,19 +238,19 @@
  • three/four arguments - hour, minute, second, nanos
-

local-time?

(local-time? v)

Returns true if v is an instance of java.time.LocalTime, otherwise false.

-

max

(max o & os)

Latest/longest of the given time entities. Entities should be of the same type

-

max-value

(max-value p)

Maximum value of this property, e.g. 29th of February for months

-

micros

(micros micros)

Duration of a specified number of microseconds.

-

millis

(millis i)

Returns a Duration of i millis.

-

min

(min o & os)

Earliest/shortest of the given time entities. Entities should be of the same type

-

min-value

(min-value p)

Minimum value of this property

-

minus

(minus o & os)

Subtracts all of the os from the time entity o

+

local-time?

(local-time? v)

Returns true if v is an instance of java.time.LocalTime, otherwise false.

+

max

(max o & os)

Latest/longest of the given time entities. Entities should be of the same type

+

max-value

(max-value p)

Maximum value of this property, e.g. 29th of February for months

+

micros

(micros micros)

Duration of a specified number of microseconds.

+

millis

(millis i)

Returns a Duration of i millis.

+

min

(min o & os)

Earliest/shortest of the given time entities. Entities should be of the same type

+

min-value

(min-value p)

Minimum value of this property

+

minus

(minus o & os)

Subtracts all of the os from the time entity o

(j/minus (j/local-date 2015) (j/years 1))
 => <java.time.LocalDate "2014-01-01">
 
-

minutes

(minutes i)

Returns a Duration of i minutes.

-

mock-clock

(mock-clock)(mock-clock instant)(mock-clock instant zone)

Returns a mock implementation of the java.time.Clock. The mock supports advance-clock! operation which allows to move the time in the clock, e.g.:

+

minutes

(minutes i)

Returns a Duration of i minutes.

+

mock-clock

(mock-clock)(mock-clock instant)(mock-clock instant zone)

Returns a mock implementation of the java.time.Clock. The mock supports advance-clock! operation which allows to move the time in the clock, e.g.:

(let [clock (mock-clock 0 "UTC")]
   (with-clock clock
     (is (= (value clock) 0))
@@ -260,13 +261,14 @@
 

You can move the clock back via advancing by a negative temporal amount.

Creates a clock at epoch in the default time zone when called without arguments.

-

monday?

(monday? i)

Returns true if the given time entity with the day-of-week property falls on a Monday, otherwise false.

-

month

(month)(month v)(month fmt arg)

Returns the Month for the given month keyword name (e.g. :january), ordinal or entity. Current month if no arguments given.

-

month-day

(month-day)(month-day arg)(month-day a b)

Returns the MonthDay for the given entity, string, clock, zone or month/day combination. Current month-day if no arguments given.

-

month-day?

(month-day? o)

Returns true if o is java.time.MonthDay, otherwise false.

-

month?

(month? o)

True if java.time.Month.

-

months

(months i)

Returns a Period of i months.

-

move-end-by

(move-end-by i & os)

Moves the end instant of the interval by the sum of given periods/durations/numbers of milliseconds.

+

Not available in babashka.

+

monday?

(monday? i)

Returns true if the given time entity with the day-of-week property falls on a Monday, otherwise false.

+

month

(month)(month v)(month fmt arg)

Returns the Month for the given month keyword name (e.g. :january), ordinal or entity. Current month if no arguments given.

+

month-day

(month-day)(month-day arg)(month-day a b)

Returns the MonthDay for the given entity, string, clock, zone or month/day combination. Current month-day if no arguments given.

+

month-day?

(month-day? o)

Returns true if o is java.time.MonthDay, otherwise false.

+

month?

(month? o)

True if java.time.Month.

+

months

(months i)

Returns a Period of i months.

+

move-end-by

(move-end-by i & os)

Moves the end instant of the interval by the sum of given periods/durations/numbers of milliseconds.

(move-start-by (interval 0 10000) (millis 1000) (seconds 1))
 => #<Interval ...:00Z/...:12Z>
 
@@ -274,7 +276,7 @@
(move-end-by (interval 0 10000) (millis -11000))
 => DateTimeException...
 
-

move-end-to

(move-end-to i new-end)

Moves the end of the interval to the given instant (or something convertible to an instant):

+

move-end-to

(move-end-to i new-end)

Moves the end of the interval to the given instant (or something convertible to an instant):

(move-end-to (interval 0 10000) (instant 15000))
 => #<Interval ...:00Z/...:15Z>
 
@@ -282,7 +284,7 @@
(move-end-to (interval 0 10000) (millis -1))
 => DateTimeException...
 
-

move-start-by

(move-start-by i & os)

Moves the start instant of the interval by the sum of given periods/durations/numbers of milliseconds:

+

move-start-by

(move-start-by i & os)

Moves the start instant of the interval by the sum of given periods/durations/numbers of milliseconds:

(move-start-by (interval 0 10000) (millis 1000) (seconds 1))
 => #<Interval ...:02Z/...:10Z>
 
@@ -290,7 +292,7 @@
(move-start-by (interval 0 10000) (millis 11000))
 ;=> DateTimeException...
 
-

move-start-to

(move-start-to i new-start)

Moves the start instant of the interval to the given instant (or something convertible to an instant):

+

move-start-to

(move-start-to i new-start)

Moves the start instant of the interval to the given instant (or something convertible to an instant):

(move-start-to (interval 0 10000) (instant 5000))
 => #<Interval ...:05Z/...:10Z>
 
@@ -298,15 +300,15 @@
(move-start-to (interval 0 10000) (millis 15000))
 => DateTimeException...
 
-

multiply-by

(multiply-by o v)

Entity o multiplied by the value v

-

nanos

(nanos i)

Returns a Duration of i nanos.

-

negate

(negate a)

Negates a temporal amount:

+

multiply-by

(multiply-by o v)

Entity o multiplied by the value v

+

nanos

(nanos i)

Returns a Duration of i nanos.

+

negate

(negate a)

Negates a temporal amount:

(negate (negate x)) == x

-

negative?

(negative? a)

True if the amount is negative

-

not-after?

(not-after? x)(not-after? x y)(not-after? x y & more)

Like before?, except returns true if the inputs are equal.

-

not-before?

(not-before? x)(not-before? x y)(not-before? x y & more)

Like after?, except returns true if the inputs are equal.

-

offset-clock

(offset-clock d)(offset-clock c d)

Creates a clock offset from the current/provided clock by a given duration.

-

offset-date-time

(offset-date-time)(offset-date-time y m d h)(offset-date-time y mo d h m)(offset-date-time y mo d h m s)(offset-date-time y mo d h m s n)(offset-date-time y mo d h m s n o)(offset-date-time arg0)(offset-date-time arg0 arg1)(offset-date-time arg0 arg1 arg2)

Creates an OffsetDateTime. The following arguments are supported:

+

negative?

(negative? a)

True if the amount is negative

+

not-after?

(not-after? x)(not-after? x y)(not-after? x y & more)

Like before?, except returns true if the inputs are equal.

+

not-before?

(not-before? x)(not-before? x y)(not-before? x y & more)

Like after?, except returns true if the inputs are equal.

+

offset-clock

(offset-clock d)(offset-clock c d)

Creates a clock offset from the current/provided clock by a given duration.

+

offset-date-time

(offset-date-time)(offset-date-time y m d h)(offset-date-time y mo d h m)(offset-date-time y mo d h m s)(offset-date-time y mo d h m s n)(offset-date-time y mo d h m s n o)(offset-date-time arg0)(offset-date-time arg0 arg1)(offset-date-time arg0 arg1 arg2)

Creates an OffsetDateTime. The following arguments are supported:

  • no arguments - current date-time with the default offset
  • one argument @@ -336,8 +338,8 @@
  • eight arguments - time fields up to nanoseconds and a zone offset

If zone offset is not specified, default will be used. You can check the default offset by invoking (zone-offset).

-

offset-date-time?

(offset-date-time? v)

Returns true if v is an instance of java.time.OffsetDateTime, otherwise false.

-

offset-time

(offset-time)(offset-time h m s)(offset-time h m s n)(offset-time h m s n o)(offset-time arg0)(offset-time arg0 arg1)

Creates an OffsetTime. The following arguments are supported:

+

offset-date-time?

(offset-date-time? v)

Returns true if v is an instance of java.time.OffsetDateTime, otherwise false.

+

offset-time

(offset-time)(offset-time h m s)(offset-time h m s n)(offset-time h m s n o)(offset-time arg0)(offset-time arg0 arg1)

Creates an OffsetTime. The following arguments are supported:

  • no arguments - current time with the default offset
  • one argument @@ -362,10 +364,10 @@
  • five arguments - last is the offset

If zone offset is not specified, default will be used. You can check the default offset by invoking (zone-offset).

-

offset-time?

(offset-time? v)

Returns true if v is an instance of java.time.OffsetTime, otherwise false.

-

overlap

(overlap i oi)

Gets the overlap between this interval and the other one or nil

-

overlaps?

(overlaps? i oi)

True if this interval overlaps the other one

-

period

(period)(period arg0)(period arg0 arg1)(period arg0 arg1 arg2)

Creates a period - a temporal entity consisting of years, months and days.

+

offset-time?

(offset-time? v)

Returns true if v is an instance of java.time.OffsetTime, otherwise false.

+

overlap

(overlap i oi)

Gets the overlap between this interval and the other one or nil

+

overlaps?

(overlaps? i oi)

True if this interval overlaps the other one

+

period

(period)(period arg0)(period arg0 arg1)(period arg0 arg1 arg2)

Creates a period - a temporal entity consisting of years, months and days.

Given one argument will

  • interpret as years if a number
  • @@ -380,98 +382,99 @@
  • get a period of a specified number of years and months

Given three arguments will create a year/month/day period.

-

period?

(period? v)

Returns true if v is an instance of java.time.Period, otherwise false.

-

plus

(plus o & os)

Adds all of the os to the time entity o. plus is not commutative, the first argument is always the entity which will accumulate the rest of the arguments.

+

period?

(period? v)

Returns true if v is an instance of java.time.Period, otherwise false.

+

plus

(plus o & os)

Adds all of the os to the time entity o. plus is not commutative, the first argument is always the entity which will accumulate the rest of the arguments.

(j/plus (j/local-date 2015) (j/years 1))
 => <java.time.LocalDate "2016-01-01">
 
-

properties

(properties o)

Map of properties present in this temporal entity

-

property

(property o k)

Property of this temporal entity under key k

-

quarter

(quarter)(quarter v)(quarter fmt arg)

Returns the Quarter for the given quarter keyword name (e.g. :q1), ordinal or entity. Current quarter if no arguments given.

-

quarter?

(quarter? o)

True if org.threeten.extra.Quarter.

-

range

(range p)

Range of values for this property

-

saturday?

(saturday? i)

Returns true if the given time entity with the day-of-week property falls on a Saturday, otherwise false.

-

seconds

(seconds i)

Returns a Duration of i seconds.

-

set-clock!

(set-clock! clock time)

Sets the clock to the given time.

+

properties

(properties o)

Map of properties present in this temporal entity

+

property

(property o k)

Property of this temporal entity under key k

+

quarter

(quarter)(quarter v)(quarter fmt arg)

Returns the Quarter for the given quarter keyword name (e.g. :q1), ordinal or entity. Current quarter if no arguments given.

+

quarter?

(quarter? o)

True if org.threeten.extra.Quarter.

+

range

(range p)

Range of values for this property

+

saturday?

(saturday? i)

Returns true if the given time entity with the day-of-week property falls on a Saturday, otherwise false.

+

seconds

(seconds i)

Returns a Duration of i seconds.

+

set-clock!

(set-clock! clock time)

Sets the clock to the given time.

This mutates the mock clock.

-

smallest-max-value

(smallest-max-value p)

Smallest maximum value of this property, e.g. 28th of February for months

-

sql-date

(sql-date)(sql-date arg0)(sql-date arg0 arg1)(sql-date arg0 arg1 arg2)

Creates a java.sql.Date out of any combination of arguments valid for local-date or the LocalDate itself.

+

Not available in babashka.

+

smallest-max-value

(smallest-max-value p)

Smallest maximum value of this property, e.g. 28th of February for months

+

sql-date

(sql-date)(sql-date arg0)(sql-date arg0 arg1)(sql-date arg0 arg1 arg2)

Creates a java.sql.Date out of any combination of arguments valid for local-date or the LocalDate itself.

Please consider using the JSR-310 Java Time types instead of java.sql.Date if your drivers support them.

Even though java.sql.Date extends a java.util.Date, it’s supposed to be used as a local date (no time component or time zone) for the purposes of conversion from/to native JDBC driver DATE types.

-

sql-time

(sql-time)(sql-time arg0)(sql-time arg0 arg1)(sql-time arg0 arg1 arg2)

Creates a java.sql.Time out of any combination of arguments valid for local-time (except the nanos constructor) or the LocalTime itself.

+

sql-time

(sql-time)(sql-time arg0)(sql-time arg0 arg1)(sql-time arg0 arg1 arg2)

Creates a java.sql.Time out of any combination of arguments valid for local-time (except the nanos constructor) or the LocalTime itself.

Please consider using the JSR-310 Java Time types instead of java.sql.Time if your drivers support them.

Even though java.sql.Time extends a java.util.Date, it’s supposed to be used as a local time (no date component or time zone) for the purposes of conversion from/to native JDBC driver TIME types.

-

sql-timestamp

(sql-timestamp)(sql-timestamp arg0)(sql-timestamp arg0 arg1)(sql-timestamp arg0 arg1 arg2)(sql-timestamp arg0 arg1 arg2 arg3)(sql-timestamp arg0 arg1 arg2 arg3 arg4)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5 arg6)

Creates a java.sql.Timestamp in the local time zone out of any combination of arguments valid for local-date-time or the LocalDateTime itself.

+

sql-timestamp

(sql-timestamp)(sql-timestamp arg0)(sql-timestamp arg0 arg1)(sql-timestamp arg0 arg1 arg2)(sql-timestamp arg0 arg1 arg2 arg3)(sql-timestamp arg0 arg1 arg2 arg3 arg4)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5)(sql-timestamp arg0 arg1 arg2 arg3 arg4 arg5 arg6)

Creates a java.sql.Timestamp in the local time zone out of any combination of arguments valid for local-date-time or the LocalDateTime itself.

Does not support Timestamp construction from an Instant or a long millis value—please use instant->sql-timestamp for this purpose.

Please consider using the JSR-310 Java Time types instead of java.sql.Timestamp if your drivers support them.

java.sql.Timestamp is a version of a java.util.Date supposed to be used as a local date-time (no time zone) for the purposes of conversion from/to native JDBC driver TIMESTAMP types.

-

standard-days

(standard-days i)

Returns a Duration of i days.

-

start

(start i)

Gets the start instant of the interval

-

sunday?

(sunday? i)

Returns true if the given time entity with the day-of-week property falls on a Sunday, otherwise false.

-

supports?

(supports? o p)

True if the o entity supports the p property

-

system-clock

(system-clock)(system-clock k)

Creates a system clock. In the default time zone if called without arguments, otherwise accepts a Zone Id.

-

thursday?

(thursday? i)

Returns true if the given time entity with the day-of-week property falls on a Thursday, otherwise false.

-

tick-clock

(tick-clock d)(tick-clock c d)

Creates a clock wrapping system/provided clock that only ticks as per specified duration.

-

time-between

(time-between o e u)

Time between temporal entities o and e in unit u.

+

standard-days

(standard-days i)

Returns a Duration of i days.

+

start

(start i)

Gets the start instant of the interval

+

sunday?

(sunday? i)

Returns true if the given time entity with the day-of-week property falls on a Sunday, otherwise false.

+

supports?

(supports? o p)

True if the o entity supports the p property

+

system-clock

(system-clock)(system-clock k)

Creates a system clock. In the default time zone if called without arguments, otherwise accepts a Zone Id.

+

thursday?

(thursday? i)

Returns true if the given time entity with the day-of-week property falls on a Thursday, otherwise false.

+

tick-clock

(tick-clock d)(tick-clock c d)

Creates a clock wrapping system/provided clock that only ticks as per specified duration.

+

time-between

(time-between o e u)

Time between temporal entities o and e in unit u.

(j/time-between (j/local-date 2015) (j/local-date 2016) :days)
 => 365
 
 (j/time-between :days (j/local-date 2015) (j/local-date 2016))
 => 365
 
-

to-java-date

deprecated

(to-java-date o)

Converts a date entity to a java.util.Date.

+

to-java-date

deprecated

(to-java-date o)

Converts a date entity to a java.util.Date.

Deprecated: This function only has a single arity and works for entities directly convertible to java.time.Instant. Please consider using java-date instead.

-

to-millis-from-epoch

(to-millis-from-epoch o)

Converts a date entity to a long representing the number of milliseconds from epoch.

-

to-sql-date

deprecated

(to-sql-date o)

Converts a local date entity to a java.sql.Date.

+

to-millis-from-epoch

(to-millis-from-epoch o)

Converts a date entity to a long representing the number of milliseconds from epoch.

+

to-sql-date

deprecated

(to-sql-date o)

Converts a local date entity to a java.sql.Date.

Deprecated: This function only has a single arity and works for entities directly convertible to java.time.LocalDate. Please consider using sql-date instead.

-

to-sql-timestamp

deprecated

(to-sql-timestamp o)

Converts a date entity to a java.sql.Timestamp.

+

to-sql-timestamp

deprecated

(to-sql-timestamp o)

Converts a date entity to a java.sql.Timestamp.

Deprecated: This function only has a single arity and works for entities directly convertible to java.time.Instant. Please consider using sql-timestamp instead.

-

truncate-to

(truncate-to o u)

Truncates this entity to the specified time unit. Only works for units that divide into the length of standard day without remainder (up to :days).

-

tuesday?

(tuesday? i)

Returns true if the given time entity with the day-of-week property falls on a Tuesday, otherwise false.

-

unit

(unit k)(unit entity k)

Returns a TemporalUnit for the given key k or extracts the field from the given temporal entity.

+

truncate-to

(truncate-to o u)

Truncates this entity to the specified time unit. Only works for units that divide into the length of standard day without remainder (up to :days).

+

tuesday?

(tuesday? i)

Returns true if the given time entity with the day-of-week property falls on a Tuesday, otherwise false.

+

unit

(unit k)(unit entity k)

Returns a TemporalUnit for the given key k or extracts the field from the given temporal entity.

You can see predefined units via java-time.repl/show-units.

If you want to make your own custom TemporalUnits resolvable, you need to rebind the java-time.properties/*units* to a custom java_time.properties.UnitGroup.

-

unit?

(unit? o)

True if this is a TemporalUnit.

-

units

(units o)

Units present in this temporal entity.

-

value

(value p)

Value of the property

-

value-range

(value-range min max)(value-range arg0)

Creates a ValueRange given the min and max amounts or a map of :min-smallest, :max-smallest, :min-largest and :max-largest.

-

wednesday?

(wednesday? i)

Returns true if the given time entity with the day-of-week property falls on a Wednesday, otherwise false.

-

weekday?

(weekday? dt)

Complement of weekend?.

-

weekend?

(weekend? dt)

Returns true if argument is saturday? or sunday?, otherwise false.

-

weeks

(weeks i)

Returns a Period of i weeks.

-

when-joda-time-loaded

macro

(when-joda-time-loaded & body)

Execute the body when Joda-Time classes are found on the classpath.

+

unit?

(unit? o)

True if this is a TemporalUnit.

+

units

(units o)

Units present in this temporal entity.

+

value

(value p)

Value of the property

+

value-range

(value-range min max)(value-range arg0)

Creates a ValueRange given the min and max amounts or a map of :min-smallest, :max-smallest, :min-largest and :max-largest.

+

wednesday?

(wednesday? i)

Returns true if the given time entity with the day-of-week property falls on a Wednesday, otherwise false.

+

weekday?

(weekday? dt)

Complement of weekend?.

+

weekend?

(weekend? dt)

Returns true if argument is saturday? or sunday?, otherwise false.

+

weeks

(weeks i)

Returns a Period of i weeks.

+

when-joda-time-loaded

macro

(when-joda-time-loaded & body)

Execute the body when Joda-Time classes are found on the classpath.

Take care - when AOT-compiling code using this macro, the Joda-Time classes must be on the classpath at compile time!

-

with-clock

macro

(with-clock c & forms)

Executes the given forms in the scope of the provided clock.

+

with-clock

macro

(with-clock c & forms)

Executes the given forms in the scope of the provided clock.

All the temporal entities that get created without parameters will inherit their values from the clock:

(with-clock (system-clock “Europe/London”) (zone-id)) => #<java.time.ZoneRegion Europe/London>

-

with-clock-fn

(with-clock-fn c f)

Executes the given function in the scope of the provided clock. All the temporal entities that get created without parameters will inherit their values from the clock.

-

with-largest-min-value

(with-largest-min-value p)

Underlying temporal entity with the value set to the largest minimum available for this property

-

with-max-value

(with-max-value p)

Underlying temporal entity with the value set to the maximum available for this property

-

with-min-value

(with-min-value p)

Underlying temporal entity with the value set to the minimum available for this property

-

with-offset

(with-offset o offset)

Sets the offset to the specified value ensuring that the local time stays the same.

+

with-clock-fn

(with-clock-fn c f)

Executes the given function in the scope of the provided clock. All the temporal entities that get created without parameters will inherit their values from the clock.

+

with-largest-min-value

(with-largest-min-value p)

Underlying temporal entity with the value set to the largest minimum available for this property

+

with-max-value

(with-max-value p)

Underlying temporal entity with the value set to the maximum available for this property

+

with-min-value

(with-min-value p)

Underlying temporal entity with the value set to the minimum available for this property

+

with-offset

(with-offset o offset)

Sets the offset to the specified value ensuring that the local time stays the same.

(offset-time 10 30 0 0 +2) => #<java.time.OffsetTime 10:30+02:00> (with-offset *1 +3) => #<java.time.OffsetTime 10:30+03:00>

-

with-offset-same-instant

(with-offset-same-instant o offset)

Sets the offset to the specified value ensuring that the result has the same instant, e.g.:

+

with-offset-same-instant

(with-offset-same-instant o offset)

Sets the offset to the specified value ensuring that the result has the same instant, e.g.:

(offset-time 10 30 0 0 +2) => #<java.time.OffsetTime 10:30+02:00> (with-offset-same-instant *1 +3) => #<java.time.OffsetTime 11:30+03:00>

-

with-smallest-max-value

(with-smallest-max-value p)

Underlying temporal entity with the value set to the smallest maximum available for this property

-

with-value

(with-value p v)

Underlying temporal entity with the value of this property set to v

-

with-zone

(with-zone o z)

Returns this temporal entity with the specified ZoneId

-

with-zone-same-instant

(with-zone-same-instant zdt z)

Sets the zone to the specified value ensuring that the result has the same instant, e.g.:

+

with-smallest-max-value

(with-smallest-max-value p)

Underlying temporal entity with the value set to the smallest maximum available for this property

+

with-value

(with-value p v)

Underlying temporal entity with the value of this property set to v

+

with-zone

(with-zone o z)

Returns this temporal entity with the specified ZoneId

+

with-zone-same-instant

(with-zone-same-instant zdt z)

Sets the zone to the specified value ensuring that the result has the same instant, e.g.:

(zoned-date-time 2015) => #<java.time.ZonedDateTime 2015-01-01T00:00+00:00Europe/London> (with-zone-same-instant *1 “America/New_York”) => #<java.time.ZonedDateTime 2014-12-31T18:00-05:00America/New_York>

-

year

(year)(year arg)(year fmt arg)

Returns the Year for the given entity, string, clock, zone or number. Current year if no arguments given.

-

year-month

(year-month)(year-month arg)(year-month a b)

Returns the YearMonth for the given entity, string, clock, zone or month/day combination. Current year-month if no arguments given.

-

year-month?

(year-month? o)

Returns true if o is java.time.YearMonth, otherwise false.

-

year-quarter

(year-quarter)(year-quarter arg)(year-quarter a b)

Returns the YearQuarter for the given entity, clock, zone or year with quarter. Current year quarter if no arguments given.

-

year-quarter?

(year-quarter? o)

Returns true if o is org.threeten.extra.YearQuarter, otherwise false.

-

year?

(year? o)

Returns true if o is java.time.Year, otherwise false.

-

years

(years i)

Returns a Period of i years.

-

zero?

(zero? a)

True if the amount is zero

-

zone-id

(zone-id)(zone-id arg0)(zone-id arg0 arg1)

Creates a ZoneId from a string identifier, java.util.TimeZone or extracts from another temporal entity.

+

year

(year)(year arg)(year fmt arg)

Returns the Year for the given entity, string, clock, zone or number. Current year if no arguments given.

+

year-month

(year-month)(year-month arg)(year-month a b)

Returns the YearMonth for the given entity, string, clock, zone or month/day combination. Current year-month if no arguments given.

+

year-month?

(year-month? o)

Returns true if o is java.time.YearMonth, otherwise false.

+

year-quarter

(year-quarter)(year-quarter arg)(year-quarter a b)

Returns the YearQuarter for the given entity, clock, zone or year with quarter. Current year quarter if no arguments given.

+

year-quarter?

(year-quarter? o)

Returns true if o is org.threeten.extra.YearQuarter, otherwise false.

+

year?

(year? o)

Returns true if o is java.time.Year, otherwise false.

+

years

(years i)

Returns a Period of i years.

+

zero?

(zero? a)

True if the amount is zero

+

zone-id

(zone-id)(zone-id arg0)(zone-id arg0 arg1)

Creates a ZoneId from a string identifier, java.util.TimeZone or extracts from another temporal entity.

Returns default system zone id if no arguments provided.

Given two arguments will use the second as the offset.

-

zone-id?

(zone-id? v)

Returns true if v is an instance of java.time.ZoneId, otherwise false.

-

zone-offset

(zone-offset)(zone-offset o)(zone-offset h m)(zone-offset h m s)

Creates a ZoneOffset from a string identifier (e.g. “+01”), a number of hours/hours and minutes/hours, minutes and seconds or extracts from another temporal entity.

+

zone-id?

(zone-id? v)

Returns true if v is an instance of java.time.ZoneId, otherwise false.

+

zone-offset

(zone-offset)(zone-offset o)(zone-offset h m)(zone-offset h m s)

Creates a ZoneOffset from a string identifier (e.g. “+01”), a number of hours/hours and minutes/hours, minutes and seconds or extracts from another temporal entity.

Returns default system zone offset if no arguments provided.

-

zoned-date-time

(zoned-date-time)(zoned-date-time y m d h)(zoned-date-time y mo d h m)(zoned-date-time y mo d h m s)(zoned-date-time y mo d h m s n)(zoned-date-time y mo d h m s n o)(zoned-date-time arg0)(zoned-date-time arg0 arg1)(zoned-date-time arg0 arg1 arg2)

Creates a ZonedDateTime. The following arguments are supported:

+

zoned-date-time

(zoned-date-time)(zoned-date-time y m d h)(zoned-date-time y mo d h m)(zoned-date-time y mo d h m s)(zoned-date-time y mo d h m s n)(zoned-date-time y mo d h m s n o)(zoned-date-time arg0)(zoned-date-time arg0 arg1)(zoned-date-time arg0 arg1 arg2)

Creates a ZonedDateTime. The following arguments are supported:

  • no arguments - current date-time in the default zone
  • one argument @@ -500,5 +503,5 @@
  • eight arguments - last is the zone id

If zone id is not specified, default zone id will be used. You can check the default zone by invoking (zone-id).

-

zoned-date-time?

(zoned-date-time? v)

Returns true if v is an instance of java.time.ZonedDateTime, otherwise false.

-
\ No newline at end of file +

zoned-date-time?

(zoned-date-time? v)

Returns true if v is an instance of java.time.ZonedDateTime, otherwise false.

+
\ No newline at end of file diff --git a/docs/java-time.repl.html b/docs/java-time.repl.html index 78098e4..42ae322 100644 --- a/docs/java-time.repl.html +++ b/docs/java-time.repl.html @@ -1,3 +1,3 @@ -java-time.repl documentation

java-time.repl

show-adjusters

(show-adjusters)

show-fields

(show-fields)

show-formatters

(show-formatters)

show-graph

(show-graph)

show-path

(show-path from to)

show-timezones

(show-timezones)

show-units

(show-units)
\ No newline at end of file +java-time.repl documentation

java-time.repl

show-adjusters

(show-adjusters)

show-fields

(show-fields)

show-formatters

(show-formatters)

show-graph

(show-graph)

show-path

(show-path from to)

show-timezones

(show-timezones)

show-units

(show-units)
\ No newline at end of file diff --git a/src/java_time.clj b/src/java_time.cljc similarity index 96% rename from src/java_time.clj rename to src/java_time.cljc index 48becd0..260a061 100644 --- a/src/java_time.clj +++ b/src/java_time.cljc @@ -1,5 +1,5 @@ ;; NOTE: This namespace is generated by java-time.dev.gen -(ns ^{:deprecated "1.1.0", :doc "This namespace has been deprecated due to [#91](https://github.com/dm3/clojure.java-time/issues/91).\n Please migrate to [[java-time.api]]\n\n This namespace will continue to exist and be updated. For\n maximum JVM compatibility, please migrate to `java-time.api`,\n which provides the same interface. `java-time` and `java-time.api`\n and can be freely intermixed within the same library, so you can\n safely migrate your own code even if your dependencies use the old namespace.\n \n Migration steps:\n\n 1. rename all references from `java-time` to [[java-time.api]].\n eg., `(:require [java-time :as jt])` => `(:require [java-time.api :as jt])`", :superseded-by "java-time.api"} java-time (:refer-clojure :exclude (zero? range iterate max min contains? format abs)) (:require [java-time core properties temporal amount zone single-field local chrono convert sugar seqs adjuster interval format joda clock pre-java8 mock])) +(ns ^{:deprecated "1.1.0", :doc "This namespace has been deprecated due to [#91](https://github.com/dm3/clojure.java-time/issues/91).\n Please migrate to [[java-time.api]]\n\n This namespace will continue to exist and be updated. For\n maximum JVM compatibility, please migrate to `java-time.api`,\n which provides the same interface. `java-time` and `java-time.api`\n and can be freely intermixed within the same library, so you can\n safely migrate your own code even if your dependencies use the old namespace.\n \n Migration steps:\n\n 1. rename all references from `java-time` to [[java-time.api]].\n eg., `(:require [java-time :as jt])` => `(:require [java-time.api :as jt])`", :superseded-by "java-time.api"} java-time (:refer-clojure :exclude (zero? range iterate max min contains? format abs)) (:require [java-time core properties temporal amount zone single-field local chrono convert sugar seqs adjuster interval format joda clock pre-java8 #?@(:bb [] :default [mock])])) (defmacro with-clock {:doc "Executes the given `forms` in the scope of the provided `clock`.\n\n All the temporal entities that get created without parameters will inherit\n their values from the clock:\n\n (with-clock (system-clock \"Europe/London\")\n (zone-id))\n => #"} [c & forms] (list* (quote java-time.clock/with-clock) c forms)) (defmacro when-joda-time-loaded {:doc "Execute the `body` when Joda-Time classes are found on the classpath.\n\n Take care - when AOT-compiling code using this macro, the Joda-Time classes\n must be on the classpath at compile time!"} [& body] (list* (quote java-time.util/when-joda-time-loaded) body)) (def ^{:arglists (quote ([^Clock c f])), :doc "Executes the given function in the scope of the provided clock. All the\n temporal entities that get created without parameters will inherit their\n values from the clock."} with-clock-fn java-time.clock/with-clock-fn) @@ -94,9 +94,9 @@ (def ^{:arglists (quote ([^ZonedDateTime zdt z])), :doc "Sets the zone to the specified value ensuring that the result has the same instant, e.g.:\n\n (zoned-date-time 2015)\n => #\n (with-zone-same-instant *1 \"America/New_York\")\n => #"} with-zone-same-instant java-time.zone/with-zone-same-instant) (def ^{:arglists (quote ([o offset])), :doc "Sets the offset to the specified value ensuring that the local time stays\n the same.\n\n (offset-time 10 30 0 0 +2)\n => #\n (with-offset *1 +3)\n => #"} with-offset java-time.zone/with-offset) (def ^{:arglists (quote ([o offset])), :doc "Sets the offset to the specified value ensuring that the result has the same instant, e.g.:\n\n (offset-time 10 30 0 0 +2)\n => #\n (with-offset-same-instant *1 +3)\n => #"} with-offset-same-instant java-time.zone/with-offset-same-instant) -(def ^{:arglists (quote ([] [instant] [instant zone])), :doc "Returns a mock implementation of the `java.time.Clock`. The mock supports\n `advance-clock!` operation which allows to move the time in the clock, e.g.:\n\n ```\n (let [clock (mock-clock 0 \"UTC\")]\n (with-clock clock\n (is (= (value clock) 0))\n (is (= (instant) (instant 0)))\n (advance-clock! clock (j/millis 1))\n (is (= (value clock) 1))\n (is (= (instant) (instant 1)))))\n ```\n\n You can move the clock back via advancing by a negative temporal amount.\n\n Creates a clock at epoch in the default time zone when called without arguments.", :tag java.time.Clock} mock-clock java-time.mock/mock-clock) -(def ^{:arglists (quote ([^IMockClock clock amount])), :doc "Advances the `clock` by the given time `amount`.\n\n This mutates the mock clock."} advance-clock! java-time.mock/advance-clock!) -(def ^{:arglists (quote ([^Clock clock time])), :doc "Sets the `clock` to the given `time`.\n\n This mutates the mock clock."} set-clock! java-time.mock/set-clock!) +#?(:bb [] :default (def ^{:arglists (quote ([] [instant] [instant zone])), :doc "Returns a mock implementation of the `java.time.Clock`. The mock supports\n `advance-clock!` operation which allows to move the time in the clock, e.g.:\n\n ```\n (let [clock (mock-clock 0 \"UTC\")]\n (with-clock clock\n (is (= (value clock) 0))\n (is (= (instant) (instant 0)))\n (advance-clock! clock (j/millis 1))\n (is (= (value clock) 1))\n (is (= (instant) (instant 1)))))\n ```\n\n You can move the clock back via advancing by a negative temporal amount.\n\n Creates a clock at epoch in the default time zone when called without arguments.\n \n Not available in babashka.", :tag java.time.Clock} mock-clock java-time.mock/mock-clock)) +#?(:bb [] :default (def ^{:arglists (quote ([^IMockClock clock amount])), :doc "Advances the `clock` by the given time `amount`.\n\n This mutates the mock clock.\n \n Not available in babashka."} advance-clock! java-time.mock/advance-clock!)) +#?(:bb [] :default (def ^{:arglists (quote ([^Clock clock time])), :doc "Sets the `clock` to the given `time`.\n\n This mutates the mock clock.\n\n Not available in babashka."} set-clock! java-time.mock/set-clock!)) (def ^{:arglists (quote ([e] [e value-fn])), :doc "Converts a time entity to a map of property key -> value as defined by the\n passed in `value-fn`. By default the actual value of the unit/field is\n produced.\n\n ```\n (as-map (duration))\n => {:nanos 0, :seconds 0}\n\n (as-map (local-date 2015 1 1))\n => {:year 2015, :month-of-year 1, :day-of-month 1, ...}\n ```"} as-map java-time.convert/as-map) (def ^{:arglists (quote ([amount from-unit to-unit])), :doc "Converts an amount from one unit to another. Returns a map of:\n\n * `:whole` - the whole part of the conversion in the `to` unit\n * `:remainder` - the remainder in the `from` unit\n\n Arguments may be keywords or instances of `TemporalUnit`.\n\n Converts between precise units--nanos up to weeks---treating days as exact\n multiples of 24 hours. Also converts between imprecise units---months up to\n millennia. See `ChronoUnit` and `IsoFields` for all of the supported units.\n Does not convert between precise and imprecise units.\n\n Throws `ArithmeticException` if long overflow occurs during computation.\n\n ```\n (convert-amount 10000 :seconds :hours)\n => {:remainder 2800 :whole 2}\n ```"} convert-amount java-time.convert/convert-amount) (def ^{:arglists (quote ([o])), :deprecated true, :doc "Converts a date entity to a `java.util.Date`.\n\n *Deprecated*:\n This function only has a single arity and works for entities directly\n convertible to `java.time.Instant`. Please consider using [[java-date]]\n instead.", :tag java.util.Date} to-java-date java-time.convert/to-java-date) diff --git a/src/java_time/api.clj b/src/java_time/api.cljc similarity index 96% rename from src/java_time/api.clj rename to src/java_time/api.cljc index f25bcc5..77d8d26 100644 --- a/src/java_time/api.clj +++ b/src/java_time/api.cljc @@ -1,5 +1,5 @@ ;; NOTE: This namespace is generated by java-time.dev.gen -(ns ^{:supercedes "java-time"} java-time.api (:refer-clojure :exclude (zero? range iterate max min contains? format abs)) (:require [java-time core properties temporal amount zone single-field local chrono convert sugar seqs adjuster interval format joda clock pre-java8 mock])) +(ns ^{:supercedes "java-time"} java-time.api (:refer-clojure :exclude (zero? range iterate max min contains? format abs)) (:require [java-time core properties temporal amount zone single-field local chrono convert sugar seqs adjuster interval format joda clock pre-java8 #?@(:bb [] :default [mock])])) (defmacro with-clock {:doc "Executes the given `forms` in the scope of the provided `clock`.\n\n All the temporal entities that get created without parameters will inherit\n their values from the clock:\n\n (with-clock (system-clock \"Europe/London\")\n (zone-id))\n => #"} [c & forms] (list* (quote java-time.clock/with-clock) c forms)) (defmacro when-joda-time-loaded {:doc "Execute the `body` when Joda-Time classes are found on the classpath.\n\n Take care - when AOT-compiling code using this macro, the Joda-Time classes\n must be on the classpath at compile time!"} [& body] (list* (quote java-time.util/when-joda-time-loaded) body)) (def ^{:arglists (quote ([^Clock c f])), :doc "Executes the given function in the scope of the provided clock. All the\n temporal entities that get created without parameters will inherit their\n values from the clock."} with-clock-fn java-time.clock/with-clock-fn) @@ -94,9 +94,9 @@ (def ^{:arglists (quote ([^ZonedDateTime zdt z])), :doc "Sets the zone to the specified value ensuring that the result has the same instant, e.g.:\n\n (zoned-date-time 2015)\n => #\n (with-zone-same-instant *1 \"America/New_York\")\n => #"} with-zone-same-instant java-time.zone/with-zone-same-instant) (def ^{:arglists (quote ([o offset])), :doc "Sets the offset to the specified value ensuring that the local time stays\n the same.\n\n (offset-time 10 30 0 0 +2)\n => #\n (with-offset *1 +3)\n => #"} with-offset java-time.zone/with-offset) (def ^{:arglists (quote ([o offset])), :doc "Sets the offset to the specified value ensuring that the result has the same instant, e.g.:\n\n (offset-time 10 30 0 0 +2)\n => #\n (with-offset-same-instant *1 +3)\n => #"} with-offset-same-instant java-time.zone/with-offset-same-instant) -(def ^{:arglists (quote ([] [instant] [instant zone])), :doc "Returns a mock implementation of the `java.time.Clock`. The mock supports\n `advance-clock!` operation which allows to move the time in the clock, e.g.:\n\n ```\n (let [clock (mock-clock 0 \"UTC\")]\n (with-clock clock\n (is (= (value clock) 0))\n (is (= (instant) (instant 0)))\n (advance-clock! clock (j/millis 1))\n (is (= (value clock) 1))\n (is (= (instant) (instant 1)))))\n ```\n\n You can move the clock back via advancing by a negative temporal amount.\n\n Creates a clock at epoch in the default time zone when called without arguments.", :tag java.time.Clock} mock-clock java-time.mock/mock-clock) -(def ^{:arglists (quote ([^IMockClock clock amount])), :doc "Advances the `clock` by the given time `amount`.\n\n This mutates the mock clock."} advance-clock! java-time.mock/advance-clock!) -(def ^{:arglists (quote ([^Clock clock time])), :doc "Sets the `clock` to the given `time`.\n\n This mutates the mock clock."} set-clock! java-time.mock/set-clock!) +#?(:bb [] :default (def ^{:arglists (quote ([] [instant] [instant zone])), :doc "Returns a mock implementation of the `java.time.Clock`. The mock supports\n `advance-clock!` operation which allows to move the time in the clock, e.g.:\n\n ```\n (let [clock (mock-clock 0 \"UTC\")]\n (with-clock clock\n (is (= (value clock) 0))\n (is (= (instant) (instant 0)))\n (advance-clock! clock (j/millis 1))\n (is (= (value clock) 1))\n (is (= (instant) (instant 1)))))\n ```\n\n You can move the clock back via advancing by a negative temporal amount.\n\n Creates a clock at epoch in the default time zone when called without arguments.\n \n Not available in babashka.", :tag java.time.Clock} mock-clock java-time.mock/mock-clock)) +#?(:bb [] :default (def ^{:arglists (quote ([^IMockClock clock amount])), :doc "Advances the `clock` by the given time `amount`.\n\n This mutates the mock clock.\n \n Not available in babashka."} advance-clock! java-time.mock/advance-clock!)) +#?(:bb [] :default (def ^{:arglists (quote ([^Clock clock time])), :doc "Sets the `clock` to the given `time`.\n\n This mutates the mock clock.\n\n Not available in babashka."} set-clock! java-time.mock/set-clock!)) (def ^{:arglists (quote ([e] [e value-fn])), :doc "Converts a time entity to a map of property key -> value as defined by the\n passed in `value-fn`. By default the actual value of the unit/field is\n produced.\n\n ```\n (as-map (duration))\n => {:nanos 0, :seconds 0}\n\n (as-map (local-date 2015 1 1))\n => {:year 2015, :month-of-year 1, :day-of-month 1, ...}\n ```"} as-map java-time.convert/as-map) (def ^{:arglists (quote ([amount from-unit to-unit])), :doc "Converts an amount from one unit to another. Returns a map of:\n\n * `:whole` - the whole part of the conversion in the `to` unit\n * `:remainder` - the remainder in the `from` unit\n\n Arguments may be keywords or instances of `TemporalUnit`.\n\n Converts between precise units--nanos up to weeks---treating days as exact\n multiples of 24 hours. Also converts between imprecise units---months up to\n millennia. See `ChronoUnit` and `IsoFields` for all of the supported units.\n Does not convert between precise and imprecise units.\n\n Throws `ArithmeticException` if long overflow occurs during computation.\n\n ```\n (convert-amount 10000 :seconds :hours)\n => {:remainder 2800 :whole 2}\n ```"} convert-amount java-time.convert/convert-amount) (def ^{:arglists (quote ([o])), :deprecated true, :doc "Converts a date entity to a `java.util.Date`.\n\n *Deprecated*:\n This function only has a single arity and works for entities directly\n convertible to `java.time.Instant`. Please consider using [[java-date]]\n instead.", :tag java.util.Date} to-java-date java-time.convert/to-java-date) diff --git a/src/java_time/defconversion.clj b/src/java_time/defconversion.clj index 139e31b..518ef2c 100644 --- a/src/java_time/defconversion.clj +++ b/src/java_time/defconversion.clj @@ -60,7 +60,9 @@ (or (try (first (f args)) (catch Exception e (throw - (ex-info "Conversion failed" + (ex-info (str "Conversion failed: " + "Path: " (pr-str path) + ) {:path (:path path), :arguments args, :to tp} e)))) (throw (ex-info diff --git a/src/java_time/graph.cljc b/src/java_time/graph.cljc index 67dfe9c..6aba0f7 100644 --- a/src/java_time/graph.cljc +++ b/src/java_time/graph.cljc @@ -1,9 +1,7 @@ (ns java-time.graph - (:require [clojure.set :as sets] - [clojure.string :as string] - [java-time.potemkin.util :as u]) #?@(:bb [] - :default [(:import [java.util PriorityQueue])])) + :default [(:require [java-time.potemkin.util :as u]) + (:import [java.util PriorityQueue])])) ;; Concept heavily inspired by Zach Tellman's ByteStreams ;; https://github.com/ztellman/byte-streams/blob/master/src/byte_streams/graph.clj @@ -64,7 +62,7 @@ (def assignable? ^{:doc "True if `a` is assignable to `b`, e.g. Integer is assignable to Number."} - (u/fast-memoize + (#?(:bb memoize :default u/fast-memoize) (fn [^Types a ^Types b] (or (= a b) (and (= (.arity a) (.arity b)) @@ -97,12 +95,10 @@ (map first (combos n s)))) (def continuous-combinations - (u/fast-memoize + (#?(:bb memoize :default u/fast-memoize) (fn [n] (let [rng (range n)] - (into [] (comp (map inc) - (map #(combinations % rng)) - cat + (into [] (comp (mapcat #(combinations (inc %) rng)) (filter #(apply = 1 (map - (rest %) %)))) rng))))) @@ -169,19 +165,21 @@ (ConversionGraph. (zipmap (map inc (range max-arity)) (repeat {})) #{})) +(declare conversion-path-comparator) + (defrecord ConversionPath [path fns visited? cost] #?@(:bb [] :default [ Comparable - (compareTo [_ x] - (let [cmp (compare cost (.cost ^ConversionPath x))] - (if (zero? cmp) - (compare (count path) (count (.path ^ConversionPath x))) - cmp))) + (compareTo [this x] (conversion-path-comparator this x)) ]) Object (toString [_] (str path cost))) +(defn conversion-path-comparator [^ConversionPath p1 ^ConversionPath p2] + (compare [(.cost p1) (count (.path p1))] + [(.cost p2) (count (.path p2))])) + (defn- conj-path [^ConversionPath p src dst ^Conversion c] (ConversionPath. (conj (.path p) [src dst]) @@ -196,9 +194,8 @@ (let [q #?(:bb (atom ()) :default (PriorityQueue.)) add #?(:bb #(swap! q (fn [prev] - (sort-by (fn [^ConversionPath p] - [(.cost p) (count (.path p))]) - (fn [a b] (compare b a)) + (sort-by identity + conversion-path-comparator (conj prev %)))) :default #(.add q %)) poll #?(:bb #(-> (swap-vals! q next) ffirst) @@ -306,13 +303,14 @@ (let [more-conversions (sub-conversions g next-src) [new-conversions g'] (with-conversions g more-conversions) accepted-conversions (filter (fn [[conv-src _ _ cost]] - (>= max-cost cost)) new-conversions)] + (>= max-cost cost)) + new-conversions)] (recur g' (reduce (fn [q [_ dst _ _]] (conj q [dst (inc step)])) (pop q) accepted-conversions)))) g))) (def conversion-path - (u/fast-memoize + (#?(:bb memoize :default u/fast-memoize) (fn [^ConversionGraph g, ^Types src, ^Types dst] (when (has-source-type? g src dst) (let [g' (expand-frontier g src max-extent)] diff --git a/src/java_time/mock.clj b/src/java_time/mock.clj index 6dcbf25..38a5533 100644 --- a/src/java_time/mock.clj +++ b/src/java_time/mock.clj @@ -25,7 +25,9 @@ You can move the clock back via advancing by a negative temporal amount. - Creates a clock at epoch in the default time zone when called without arguments." + Creates a clock at epoch in the default time zone when called without arguments. + + Not available in babashka." ([] (mock-clock 0)) ([instant] (mock-clock instant (zone/zone-id))) ([instant zone] @@ -55,14 +57,18 @@ (defn advance-clock! "Advances the `clock` by the given time `amount`. - This mutates the mock clock." + This mutates the mock clock. + + Not available in babashka." [^IMockClock clock amount] (.advanceClock clock amount)) (defn set-clock! "Sets the `clock` to the given `time`. - This mutates the mock clock." + This mutates the mock clock. + + Not available in babashka." [^Clock clock time] (let [current (.instant clock)] (->> (core/time-between :millis current (temporal/instant time)) diff --git a/test/java_time/api_test.clj b/test/java_time/api_test.cljc similarity index 99% rename from test/java_time/api_test.clj rename to test/java_time/api_test.cljc index b356823..b87e607 100644 --- a/test/java_time/api_test.clj +++ b/test/java_time/api_test.cljc @@ -578,6 +578,7 @@ (is (j/not-before? apr-1 jan-1)) (is (not (j/not-before? jan-1 apr-1)))))) +#?(:bb nil :default (deftest mock-clock-test (testing "constructors" (is (= (j/mock-clock) @@ -625,7 +626,7 @@ (testing "into past" (j/set-clock! clock 0) - (is (= 0 (j/value clock)))))))) + (is (= 0 (j/value clock))))))))) (deftest properties-test (testing "units" diff --git a/test/java_time/dev/gen.clj b/test/java_time/dev/gen.clj index 0d0a878..6122d24 100644 --- a/test/java_time/dev/gen.clj +++ b/test/java_time/dev/gen.clj @@ -36,7 +36,7 @@ (when (:macro m) (throw (IllegalArgumentException. (str "Calling import-fn on a macro: " sym)))) - (cond->> (list 'def (with-meta n forward-meta) sym) + (cond->> (list 'def (with-meta n forward-meta) (with-meta sym nil)) when-class (list 'java-time.util/when-class when-class)))) (defn import-macro [sym] @@ -60,6 +60,8 @@ (list* 'list (list 'quote sym) argv))))) arglists)))))) +(def special-string-prefix ":java-time.dev.gen/special-string ") + (defn import-vars "Imports a list of vars from other namespaces." [& syms] @@ -75,7 +77,7 @@ (when-let [n (namespace %)] (str "." n))) (name %)) - (meta %)))) + (merge (meta (first x)) (meta %))))) [x])) syms (mapcat unravel syms)] (map (fn [sym] @@ -84,10 +86,13 @@ (do (require (-> sym namespace symbol)) (resolve sym))) _ (assert vr (str sym " is unresolvable")) - m (meta vr)] - (if (:macro m) - (import-macro sym) - (import-fn sym)))) + m (meta vr) + form (if (:macro m) + (import-macro sym) + (import-fn sym))] + (if (-> sym meta ::no-babashka) + (reader-conditional (list :bb [] :default form) false) + form))) syms))) (def impl-info @@ -136,7 +141,8 @@ zone-id? zoned-date-time? offset-date-time? offset-time? with-zone-same-instant with-offset with-offset-same-instant] - '[java-time.mock mock-clock advance-clock! set-clock!] + '[^::no-babashka java-time.mock + mock-clock advance-clock! set-clock!] '[java-time.convert as-map convert-amount to-java-date to-sql-date to-sql-timestamp @@ -173,38 +179,47 @@ [";; NOTE: This namespace is generated by java-time.dev.gen" `(~'ns ~nsym (:refer-clojure :exclude ~'(zero? range iterate max min contains? format abs)) - (:require ~'[java-time core properties temporal amount zone single-field local chrono - convert sugar seqs adjuster interval format joda clock pre-java8 mock]))] + (:require ~(-> '[java-time core properties temporal amount zone single-field local chrono + convert sugar seqs adjuster interval format joda clock pre-java8] + (conj (reader-conditional (list :bb [] :default ['mock]) true)))))] (apply import-vars (:macros impl-info)) (apply import-vars (:fns impl-info)) [(list* 'java-time.util/when-class "org.threeten.extra.Temporals" (apply import-vars (:threeten-extra-fns impl-info)))]))) +(defn print-form-str [form] + (with-out-str + (with-bindings + (cond-> {#'*print-meta* true + #'*print-length* nil + #'*print-level* nil} + (resolve '*print-namespace-maps*) + (assoc (resolve '*print-namespace-maps*) false)) + (cond + (string? form) (print form) + :else (let [massage (fn massage [form] + (walk/postwalk + (fn [v] + (if (reader-conditional? v) + (reader-conditional (massage (:form v)) + (:splicing? v)) + (if (meta v) + (if (symbol? v) + (vary-meta v #(not-empty + (cond-> (sorted-map) + (some? (:tag %)) (assoc :tag (:tag %)) + (some? (:doc %)) (assoc :doc (:doc %)) + ((some-fn true? string?) (:deprecated %)) (assoc :deprecated (:deprecated %)) + (string? (:superseded-by %)) (assoc :superseded-by (:superseded-by %)) + (string? (:supercedes %)) (assoc :supercedes (:supercedes %)) + (some? (:arglists %)) (assoc :arglists (list 'quote (doall (map normalize-argv (:arglists %)))))))) + (with-meta v nil)) + v))) + form))] + (print (pr-str (massage form)))))))) + (defn print-form [form] - (with-bindings - (cond-> {#'*print-meta* true - #'*print-length* nil - #'*print-level* nil} - (resolve '*print-namespace-maps*) - (assoc (resolve '*print-namespace-maps*) false)) - (cond - (string? form) (println form) - :else (println (pr-str (walk/postwalk - (fn [v] - (if (meta v) - (if (symbol? v) - (vary-meta v #(not-empty - (cond-> (sorted-map) - (some? (:tag %)) (assoc :tag (:tag %)) - (some? (:doc %)) (assoc :doc (:doc %)) - ((some-fn true? string?) (:deprecated %)) (assoc :deprecated (:deprecated %)) - (string? (:superseded-by %)) (assoc :superseded-by (:superseded-by %)) - (string? (:supercedes %)) (assoc :supercedes (:supercedes %)) - (some? (:arglists %)) (assoc :arglists (list 'quote (doall (map normalize-argv (:arglists %)))))))) - (with-meta v nil)) - v)) - form))))) - nil) + (println (print-form-str form))) (defn print-java-time-ns [nsym] (run! print-form (gen-java-time-ns-forms nsym))) @@ -234,8 +249,8 @@ {:supercedes "java-time"})) (def gen-source->nsym - {"src/java_time.clj" java-time-nsym - "src/java_time/api.clj" java-time-api-nsym}) + {"src/java_time.cljc" java-time-nsym + "src/java_time/api.cljc" java-time-api-nsym}) (defn spit-java-time-ns [] (doseq [[source nsym] gen-source->nsym] diff --git a/test/java_time_test.clj b/test/java_time_test.clj deleted file mode 100644 index 0907717..0000000 --- a/test/java_time_test.clj +++ /dev/null @@ -1,25 +0,0 @@ -(ns java-time-test - "Tests live in java-time.api-test, but we rename the - alias j to point to java-time here." - (:require [java-time :as j])) - -(with-open [rdr (-> (slurp "test/java_time/api_test.clj") - java.io.StringReader. - clojure.lang.LineNumberingPushbackReader.)] - (let [ns-form (read rdr) ;;rm ns form - _ (assert (= '(ns java-time.api-test - (:require [java-time.api :as j])) - (remove string? ns-form)) - (pr-str ns-form)) - s (str (slurp rdr) - "\n(assert (= *ns* (the-ns 'java-time-test)) *ns*)")] - #_ - (println "DEBUG\n" s) - (load-string s))) -(assert (= *ns* (the-ns 'java-time-test)) *ns*) -(assert (= #'java-time-test/constructors-test - (resolve 'constructors-test)) - (resolve 'constructors-test)) -(require 'java-time.api-test) -(assert (= (set (keys (ns-publics 'java-time-test))) - (set (keys (ns-publics 'java-time.api-test))))) diff --git a/test/java_time_test.cljc b/test/java_time_test.cljc new file mode 100644 index 0000000..5a33701 --- /dev/null +++ b/test/java_time_test.cljc @@ -0,0 +1,32 @@ +(ns java-time-test + "Tests live in java-time.api-test, but we rename the + alias j to point to java-time here." + (:require [java-time :as j])) + +;; prefer over (load "common") to not compromise repl experience in java-time.api-test +(with-open [rdr (-> (slurp "test/java_time/api_test.cljc") + java.io.StringReader. + clojure.lang.LineNumberingPushbackReader.)] + (let [opts {:read-cond :allow + :eof (Object.) + :features (-> #{:clj} #?(:bb (conj :bb) + ;for linter + :default identity))} + ns-form (read opts rdr) ;;rm ns form + _ (assert (= '(ns java-time.api-test + (:require [java-time.api :as j])) + (remove string? ns-form)) + (pr-str ns-form))] + (loop [] + (let [form (read opts rdr)] + (when-not (identical? (:eof opts) form) + ;(println "DEBUG\n" form) + (eval form) + (recur)))))) +(assert (= *ns* (the-ns 'java-time-test)) *ns*) +(assert (= #'java-time-test/constructors-test + (resolve 'constructors-test)) + (resolve 'constructors-test)) +(require 'java-time.api-test) +(assert (= (set (keys (ns-publics 'java-time-test))) + (set (keys (ns-publics 'java-time.api-test)))))