tupelo.java-time

*zone-id*

dynamic

->instant

(->instant arg)
Coerces an Instant, ZonedDateTime, or org.joda.time.ReadableInstant => Instant 

->str-date-compact

(->str-date-compact timestamp)
Returns a compact date-time string like `2018-09-05 23:05:19.123Z` => `20180905` 

->str-date-time-compact

(->str-date-time-compact timestamp)
Returns a compact date-time string like `2018-09-05 23:05:19.123Z` => `20180905-230519` 

->str-date-time-hyphens

(->str-date-time-hyphens timestamp)
Returns a compact date-time string like `2018-09-05 23:05:19.123Z` => `2018-09-05-23-05-19` 

->str-date-time-iso

(->str-date-time-iso timestamp)
Returns a ISO date-time string like `2018-09-05T23:05:19.123Z`

->str-date-time-nice

(->str-date-time-nice timestamp)
Returns an ISO date-time string like `2018-09-05 23:05:19.123Z`
(with a space instead of `T`)

->str-iso-date

(->str-iso-date zdt)
Returns a string like `2018-09-05`

->year-quarter

(->year-quarter arg)
Inputs: [arg]
Returns: tsk/Quarter

Given a date-ish value (e.g. LocalDate, et al), returns the quarter of the year
as one of #{ :Q1 :Q2 :Q3 :Q4 } 

->zoned-date-time

(->zoned-date-time arg)
Coerces a org.joda.time.ReadableInstant to java.time.ZonedDateTime

DateTimeStamp

daynum->LocalDate

(daynum->LocalDate arg)
Inputs: [arg :- s/Int]
Returns: LocalDate

Given a daynum, returns a LocalDate 

daynum->LocalDate-str

(daynum->LocalDate-str arg)
Inputs: [arg :- s/Int]
Returns: s/Str

Converts an integer daynum like 10956 (rel to epoch) into a LocalDate string like `1999-12-31` 

daynum->monthValue

(daynum->monthValue arg)
Inputs: [arg :- s/Int]
Returns: s/Int

Given a daynum, returns a monthValue in [1..12]

daynum->year

(daynum->year arg)
Inputs: [arg :- s/Int]
Returns: s/Int

Given a daynum, returns a year like 2013

daynum->year-quarter

(daynum->year-quarter daynum)
Inputs: [daynum :- s/Int]
Returns: tsk/Quarter

Like `->year-quarter` but works for DayNum values

fixed-time-point?

(fixed-time-point? it)
Returns true iff arg represents a fixed point in time. Examples:

[java.time       ZonedDateTime  Instant]
[org.joda.time        DateTime  Instant  ReadableInstant]

instant

(instant)
Wrapper for java.time.Instant/now 

instant?

(instant? it)
Returns true iff arg is an instance of java.time.Instant 

interval-LocalDate-str->daynum

(interval-LocalDate-str->daynum ldstr)
Inputs: [ldstr :- Interval]
Returns: Interval

iso-date-str

deprecated

(iso-date-str & args)
DEPRECATED: use `string-date-iso`

iso-date-time-str

deprecated

(iso-date-time-str & args)
DEPRECATED: use `string-date-time-iso`

iso-str->millis

(iso-str->millis iso-datetime-str)
Inputs: [iso-datetime-str :- s/Str]
Returns: s/Int

Convert an ISO 8601 string to a java.sql.Date

iso-str->sql-timestamp

(iso-str->sql-timestamp iso-datetime-str)
Inputs: [iso-datetime-str :- s/Str]

Convert an ISO 8601 string to a java.sql.Date

joda-instant?

(joda-instant? it)
Returns true iff arg is an instance of org.joda.time.ReadableInstant 

LocalDate->Date

(LocalDate->Date ld)
Inputs: [ld :- LocalDate]
Returns: Date

Converts a LocalDate to a java.util.Date, using midnight (start of day) and the UTC timezone.

LocalDate->daynum

(LocalDate->daynum arg)
Inputs: [arg :- LocalDate]
Returns: s/Int

Normalizes a LocalDate as the offset from 1970-1-1

LocalDate->Instant

(LocalDate->Instant ld)
Inputs: [ld :- LocalDate]
Returns: Instant

Converts a LocalDate to a java.util.Date, using midnight (start of day) and the UTC timezone.

LocalDate->tagval

(LocalDate->tagval ld)
Inputs: [ld :- LocalDate]
Returns: {:LocalDate s/Str}

Converts a java.time.LocalDate object to a tagval

LocalDate->trailing-interval

(LocalDate->trailing-interval localdate N)
Inputs: [localdate :- LocalDate N :- s/Num]

Returns a LocalDate interval of span N days ending on the date supplied

LocalDate-interval->days

(LocalDate-interval->days interval)
Inputs: [interval :- Interval]
Returns: s/Int

Returns the duration in days from the start to the end of a LocalDate Interval

LocalDate-str->daynum

(LocalDate-str->daynum arg)
Inputs: [arg :- s/Str]
Returns: s/Int

Parses a LocalDate string like `1999-12-31` into an integer daynum (rel to epoch) like 10956

LocalDate-str?

(LocalDate-str? arg)
Inputs: [arg :- s/Str]
Returns: s/Bool

Returns true iff string is a legal ISO LocalDate like '1999-12-31' (valid for years 1900-2100).

localdates->day-idxs

(localdates->day-idxs ld-vals)
Inputs: [ld-vals :- [LocalDate]]
Returns: [s/Int]

Converts a sequence of LocalDate objects into an integer series like [0 1 2 ...], relative to the first value.
Assumes LocalDate's are in ascending order.

millis->instant

(millis->instant millis)
Wrapper for java.time.Instant/ofEpochMilli 

now->instant

(now->instant)
Returns the current time as a java.lang.Instant

now->iso-str

(now->iso-str)
Returns an ISO string representation of the current time,
like '2019-02-19T18:44:01.123456Z' 

now->iso-str-simple

(now->iso-str-simple)
Returns a canonical string representation of the current time truncated to the current second,
like '2019-02-19 18:44:01Z' 

now->zdt

(now->zdt)
Returns the current time as a java.lang.ZonedDateTime (UTC)

parse-iso-str-nice

(parse-iso-str-nice iso-str)
Inputs: [iso-str :- s/Str]
Returns: Instant

Parse a near-iso string like '2019-09-19 18:09:35Z' (it is missing the 'T' between the
date & time fields) into an Instant

period?

(period? it)
Returns true iff arg is an instance of org.joda.time.ReadablePeriod.
Example:  (period (days 3)) => true 

range

(range start-inst stop-inst step-dur)
Returns a vector of instants in the half-open interval [start stop) (both instants)
with increment <step> (a period). Not lazy.  Example:

     (range (zoned-date-time 2018 9 1)
            (zoned-date-time 2018 9 5)
            (Duration/ofDays 1)))  => <vector of 4 ZonedDateTime's from 2018-9-1 thru 2018-9-4>

same-instant?

(same-instant? this & others)
Returns true iff two ZonedDateTime objects represent the same instant of time, regardless of time zone.
A thin wrapper over `ZonedDateTime/isEqual`

secs->instant

(secs->instant secs)
Wrapper for java.time.Instant/ofEpochSecs 

stringify-times

(stringify-times form)
Will recursively walk any data structure, converting any `fixed-time-point?` object to a string

tagval->LocalDate

(tagval->LocalDate ldtv)
Inputs: [ldtv :- {:LocalDate s/Str}]
Returns: LocalDate

Parses a tagval into a java.time.LocalDate

temporal?

(temporal? it)
Returns true iff arg is an instance of java.time.temporal.Temporal 

trunc-to-day

(trunc-to-day zdt)
Inputs: [zdt :- DateTimeStamp]

Returns a ZonedDateTime truncated to first instant of the day.

trunc-to-hour

(trunc-to-hour zdt)
Inputs: [zdt :- DateTimeStamp]

Returns a ZonedDateTime truncated to first instant of the hour.

trunc-to-midnight-friday

(trunc-to-midnight-friday temporal)
Inputs: [temporal :- Temporal]

For an instant T, truncate time to midnight and return the first Friday at or before T.

trunc-to-midnight-monday

(trunc-to-midnight-monday temporal)
Inputs: [temporal :- Temporal]

For an instant T, truncate time to midnight and return the first Monday at or before T.

trunc-to-midnight-saturday

(trunc-to-midnight-saturday temporal)
Inputs: [temporal :- Temporal]

For an instant T, truncate time to midnight and return the first Saturday at or before T.

trunc-to-midnight-sunday

(trunc-to-midnight-sunday temporal)
Inputs: [temporal :- Temporal]

For an instant T, truncate time to midnight and return the first Sunday at or before T.

trunc-to-midnight-thursday

(trunc-to-midnight-thursday temporal)
Inputs: [temporal :- Temporal]

For an instant T, truncate time to midnight and return the first thursday at or before T.

trunc-to-midnight-tuesday

(trunc-to-midnight-tuesday temporal)
Inputs: [temporal :- Temporal]

For an instant T, truncate time to midnight and return the first Tuesday at or before T.

trunc-to-midnight-wednesday

(trunc-to-midnight-wednesday temporal)
Inputs: [temporal :- Temporal]

For an instant T, truncate time to midnight and return the first Wednesday at or before T.

trunc-to-minute

(trunc-to-minute zdt)
Inputs: [zdt :- DateTimeStamp]

Returns a ZonedDateTime truncated to first instant of the minute.

trunc-to-month

(trunc-to-month zdt)
Inputs: [zdt :- ZonedDateTime]

Returns a ZonedDateTime truncated to first instant of the month.

trunc-to-second

(trunc-to-second zdt)
Inputs: [zdt :- DateTimeStamp]

Returns a ZonedDateTime truncated to first instant of the second.

trunc-to-year

(trunc-to-year zdt)
Inputs: [zdt :- ZonedDateTime]

Returns a ZonedDateTime truncated to first instant of the year.

walk-instant->str

(walk-instant->str tree)
Walks a tree-like data structure, calling `.toString` on any instances java.time.Instant

walk-instant->timestamp

(walk-instant->timestamp tree)
Walks a tree-like data structure, converting any instances of java.sql.Timestamp => java.time.Instant

walk-LocalDate->tagval

(walk-LocalDate->tagval data)

walk-timestamp->instant

(walk-timestamp->instant tree)
Walks a tree-like data structure, converting any instances of java.sql.Timestamp => java.time.Instant

with-zoneid

macro

(with-zoneid zone-id & forms)

year-quarter?

(year-quarter? arg)
Inputs: [arg]
Returns: s/Bool

Returns true iff arg is indicates a (financial) quarter in the year.

year-quarters

zoned-date-time

(zoned-date-time)(zoned-date-time year)(zoned-date-time year month)(zoned-date-time year month day)(zoned-date-time year month day hour)(zoned-date-time year month day hour minute)(zoned-date-time year month day hour minute second)(zoned-date-time year month day hour minute second nanos)(zoned-date-time year month day hour minute second nanos zone-id)
Returns a java.time.ZonedDateTime with the specified parameters and truncated values (day/month=1, hour/minute/sec=0)
for all other date/time components. Assumes time zone is UTC unless the maximum-arity constructor is used. Usage:

; Assumes UTC time zone
(zoned-date-time)          => current time
(zoned-date-time year)
(zoned-date-time year month)
(zoned-date-time year month day)
(zoned-date-time year month day hour)
(zoned-date-time year month day hour minute)
(zoned-date-time year month day hour minute second)
(zoned-date-time year month day hour minute second nanos)

; Explicit time zone
(zoned-date-time year month day hour minute second nanos zone-id)

; Explicit time zone alternate shortcut arities.
(with-zoneid zoneid-us-eastern
  (zoned-date-time year month day ...))  ; any arity w/o zone-id

zoned-date-time?

(zoned-date-time? it)
Returns true iff arg is an instance of java.time.ZonedDateTime

zoneid-us-alaska

zoneid-us-aleutian

zoneid-us-central

zoneid-us-eastern

zoneid-us-hawaii

zoneid-us-mountain

zoneid-us-pacific

zoneid-utc