timable
1 Procedures extended from srfi/  19
unix-epoch-time
unix-epoch-date
hours-ago
hours-ago/  time
hours-ago/  date
hours-from-now
hours-from-now/  time
hours-from-now/  date
time-in-range?
time-in-range<>?
time-in-range==?
time-in-range=<>=?
time-in-range=<>?
time-in-range<>=?
beginning-date
beginning-date/  day
beginning-date/  month
beginning-date/  year
end-date
end-date/  day
end-date/  month
end-date/  year
previous-date/  day
date-parse
previous-date/  month
last-oclock/  time
last-oclock/  date
last-oclock
oclocks-between
oclocks-between/  time
oclocks-between/  date
time-utc->date->string
time-utc->string
2 Procedures extended from gregor
->utc-offset/  hours
current-date
current-datetime
current-moment
current-moment/  utc
at-beginning/  day
at-end/  day
3 Procedures converting date/  time types
date->sql-timestamp
datetime->sql-timestamp
moment->sql-timestamp
->sql-timestamp
current-datetime/  sql
current-moment/  sql
today/  sql
4 Changelog
7.5

timable

Yanying Wang <yanyingwang1@gmail.com>

 (require timable) package: timable

extend racket’s various time/date libs and make them be able to work together more smoothly.

    1 Procedures extended from srfi/19

    2 Procedures extended from gregor

    3 Procedures converting date/time types

    4 Changelog

1 Procedures extended from srfi/19

 (require timable/srfi) package: timable

Examples:
> (require srfi/19)
> (require timable/srfi)
> (hours-ago 5)

(date* 6 14 5 13 12 2019 5 346 #f -25200 323000000 "")

> (time-in-range? (current-time) (hours-ago/time 1) (hours-from-now/time 1))

#t

> (last-oclock (current-date))

(date* 0 0 10 13 12 2019 5 346 #f -25200 0 "")

> (last-oclock/time (current-time))

(tm:time 'time-utc 0 1576256400)

> (oclocks-between (hours-ago 2) (hours-ago 5))

(list

 (date* 0 0 5 13 12 2019 5 346 #f -25200 0 "")

 (date* 0 0 6 13 12 2019 5 346 #f -25200 0 "")

 (date* 0 0 7 13 12 2019 5 346 #f -25200 0 "")

 (date* 0 0 8 13 12 2019 5 346 #f -25200 0 ""))

> (oclocks-between/time (hours-ago/time 2) (hours-ago/time 5))

(list

 (tm:time 'time-utc 0 1576238400)

 (tm:time 'time-utc 0 1576242000)

 (tm:time 'time-utc 0 1576245600)

 (tm:time 'time-utc 0 1576249200))

> (beginning-date (current-date))

(date* 0 0 0 13 12 2019 5 346 #f -25200 0 "")

> (beginning-date/month (current-date))

(date* 0 0 0 1 12 2019 0 334 #f -25200 0 "")

> (beginning-date/year (current-date))

(date* 0 0 0 1 1 2019 2 0 #f -25200 0 "")

> (date->string (date-parse "2018-01-01 11:11:11 +0800"))

"Mon Jan 01 11:11:11+0800 2018"

> (date->string (date-parse "2018/01/01 12"))

"Mon Jan 01 12:00:00-0700 2018"

value

unix-epoch-time : time?

returns the unix epoch time, which is 1970-01-01T00:00:00Z.

value

unix-epoch-date : date?

returns the unix-epoch-time in date type.

procedure

(hours-ago n)  date?

  n : number?
an alias procedure of hours-ago/date

procedure

(hours-ago/time n)  time?

  n : number?
returns a time of n hours ago.

procedure

(hours-ago/date n)  date?

  n : number?
returns a date of n hours ago.

procedure

(hours-from-now n)  date?

  n : number?
an alias procedure of hours-from-now/date

procedure

(hours-from-now/time n)  time?

  n : number?
returns a time of n hours from now on.

procedure

(hours-from-now/date n)  date?

  n : number?
returns a date of n hours from now on.

procedure

(time-in-range? time1 time2 time3)  boolean?

  time1 : time?
  time2 : time?
  time3 : time?
an alias procedure of time-in-range<>?

procedure

(time-in-range<>? time1 time2 time3)  boolean?

  time1 : time?
  time2 : time?
  time3 : time?
Is time1 in the range of time2 and time3?

procedure

(time-in-range==? time1 time2 time3)  boolean?

  time1 : time?
  time2 : time?
  time3 : time?
an alias procedure of time-in-range=<>=?

procedure

(time-in-range=<>=? time1 time2 time3)  boolean?

  time1 : time?
  time2 : time?
  time3 : time?
Is time1 in the range of time2 and time3(is in if time1 equals time2 or time3)?

procedure

(time-in-range=<>? time1 time2 time3)  boolean?

  time1 : time?
  time2 : time?
  time3 : time?
Is time1 in the range of time2 and time3(is in if time1 equals time2)?

procedure

(time-in-range<>=? time1 time2 time3)  boolean?

  time1 : time?
  time2 : time?
  time3 : time?
Is time1 in the range of time2 and time3(is in if time1 equals time3)?

procedure

(beginning-date d)  date?

  d : date?
beginning-date is an alias procedure of beginning-date/day.

procedure

(beginning-date/day d)  date?

  d : date?
beginning-date/day returns a new date which is the first date of the day of d.

procedure

(beginning-date/month d)  date?

  d : date?
beginning-date/month returns a new date which is the first date of the month of d.

procedure

(beginning-date/year d)  date?

  d : date?
beginning-date/year returns a new date which is the first date of the year of d.

procedure

(end-date d)  date?

  d : date?
end-date is an alias procedure of end-date/day.

procedure

(end-date/day d)  date?

  d : date?
end-date/day returns a new date which is the end date of the day of d.

procedure

(end-date/month d)  date?

  d : date?
end-date/month returns a new date which is the end date of the month of d.

procedure

(end-date/year d)  date?

  d : date?
end-date/year returns a new date which is the endt date of the year of d.

procedure

(previous-date/day d)  date?

  d : date?
returns a new date which is the same date of yesterday of d.

procedure

(date-parse str)  date?

  str : string?
try to returns a date with parsing the string str.

procedure

(previous-date/month d)  date?

  d : date?
returns a new date which is the same date of last month of d.

procedure

(last-oclock/time d)  time?

  d : time?
returns a new time which is the recently last oclock time of d.

procedure

(last-oclock/date d)  date?

  d : date?
returns a new date which is the recently last oclock time of d.

procedure

(last-oclock d)  date?

  d : date?
an alias procedure of last-oclock/date.

procedure

(oclocks-between d1 d2)  list?

  d1 : date?
  d2 : date?
an alias procedure of oclocks-between/date.

procedure

(oclocks-between/time t1 t2)  list?

  t1 : time?
  t2 : time?
returns a list of all the time oclocks between t1 and t2.

procedure

(oclocks-between/date d1 d2)  list?

  d1 : date?
  d2 : date?
returns a list of all the date oclocks between d1 and d2.

procedure

(time-utc->date->string t [format-string])  string?

  t : time?
  format-string : string? = "~c"
convert the time to date and then to string with format-string of PLT-specific extensions(string->date).

procedure

(time-utc->string t [format-string])  string?

  t : time?
  format-string : string? = "~c"
an alias procedure of time-utc->date->string.

2 Procedures extended from gregor

Examples:
> (require timable/gregor)
> (current-date)

#<date 2019-12-13>

> (current-datetime)

#<datetime 2019-12-13T10:14:06.680801025>

> (current-moment)

#<moment 2019-12-13T10:14:06.682009033-07:00[America/Denver]>

> (current-moment/utc)

#<moment 2019-12-13T17:14:06.683137939Z[Etc/UTC]>

> (require gregor)
> (prev-day (now))

#<datetime 2019-12-12T10:14:06.685215088>

> (prev-month (now))

#<datetime 2019-11-13T10:14:06.6865979>

> (next-month (now))

+months: arity mismatch;

 the expected number of arguments does not match the given

number

  expected: 2 plus an optional argument with keyword

#:resolve-offset

  given: 1

  arguments...:

   #<datetime 2019-12-13T10:14:06.688155029>

> (prev-year (now))

#<datetime 2018-12-13T10:14:06.688954102>

> (at-beginning/month (now))

#<datetime 2019-12-01T00:00:00>

> (at-end/month (now))

#<datetime 2019-12-31T23:59:59.999999999>

> (at-beginning/day (now))

#<datetime 2019-12-13T00:00:00>

> (at-end/year (now))

#<datetime 2019-12-31T23:59:59.999999999>

procedure

(->utc-offset/hours m)  number?

  m : moment?
return a number stands for the utc offset hours. While ->utc-offset returns the seconds.

procedure

(current-date)  date?

an alias procedure of today.

procedure

(current-datetime)  datetime?

an alias procedure of now.

procedure

(current-moment)  moment?

an alias procedure of now/moment.

procedure

(current-moment/utc)  moment?

an alias procedure of now/moment/utc.

procedure

(at-beginning/day d)  (or/c datetime? moment?)

  d : (or/c datetime? moment?)
the day beginning time of d.

procedure

(at-end/day d)  (or/c datetime? moment?)

  d : (or/c datetime? moment?)
the day end time of d.

3 Procedures converting date/time types

Examples:
> (require gregor)
> (->sql-timestamp (today))

(sql-timestamp 2019 12 13 0 0 0 0 #f)

> (->sql-timestamp (now))

(sql-timestamp 2019 12 13 10 14 6 990811035 #f)

> (->sql-timestamp (now/moment))

(sql-timestamp 2019 12 13 10 14 6 992886963 -7)

> (->sql-timestamp (now))

(sql-timestamp 2019 12 13 10 14 6 993774902 #f)

> (->sql-timestamp (now/moment #:tz "Asia/Shanghai"))

(sql-timestamp 2019 12 14 1 14 6 994632080 8)

> (today/sql)

(sql-date 2019 12 13)

> (now/sql)

(sql-timestamp 2019 12 13 10 14 6 995774902 #f)

> (now/moment/sql #:tz "Asia/Shanghai")

(sql-timestamp 2019 12 13 10 14 6 996711914 -7)

procedure

(date->sql-timestamp d)  sql-timestamp?

  d : date?
convert d from gregor date to sql-timestamp.

procedure

(datetime->sql-timestamp d)  sql-timestamp?

  d : datetime?
convert d from gregor datetime to sql-timestamp.

procedure

(moment->sql-timestamp d)  sql-timestamp?

  d : moment?
convert d from gregor moment to sql-timestamp.

procedure

(->sql-timestamp d)  sql-timestamp?

  d : (or/c date? datetime? moment?)
convert d from gregor moment to sql-timestamp.

procedure

(current-datetime/sql d)  sql-timestamp?

  d : datetime?
return current-datetime in sql-timestamp type.

procedure

(current-moment/sql d)  sql-timestamp?

  d : moment?
return current-moment in sql-timestamp-tz type.

procedure

(today/sql d)  sql-date?

  d : date?
return today in sql-date type.

4 Changelog