chive
1 time
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
yesterday-date
parse-date
previous-date/  month
yesterday-date
last-oclock/  time
last-oclock/  date
last-oclock
oclocks-between
oclocks-between/  time
oclocks-between/  date
time-utc->date->string
time-utc->string
2 system
system/  verbose
system/  v
3 base64
base64-encode-string
base64-decode-string
4 port
port->bytes/  base64
port->string/  base64
5 smtp
mail
mail-from
mail-tos
mail-subject
mail-content
mail-attachment-files
mail-header
mail-header/  info
mail-header/  attachment
mail-send
6 phone-number
phone-number-attribution
7.3

chive

 (require chive) package: chive

an extended scheme library to easily cook practical applications. source code

    1 time

    2 system

    3 base64

    4 port

    5 smtp

    6 phone-number

1 time

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.

same kind of rule comes to procedures days-ago and days-from-now, and the plural procedure name can be singular such as hour-ago.

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

(yesterday-date d)  date?

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

procedure

(parse-date 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

(yesterday-date d)  date?

  d : date?
end-date is an alias procedure of last-month-date.

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.

Examples:
(require chive/time)
 
(hours-ago 5)
;=> (date* 55 50 11 8 5 2019 3 127 #f 28800 996000000 "")
 
(time-in-range? (days-ago 2) (hours-ago 1) unix-epoch-time)
;=> #t
 
(last-olock (current-date))
;=> #[#{date pfwa3r0havo3glvxa5oa6eoyh-24} 0 0 0 15 5 11 2018 28800]
 
(last-olock/time (current-time))
;=> #[#{date pfwa3r0havo3glvxa5oa6eoyh-24} 0 0 0 15 5 11 2018 28800]
 
> (oclocks-between (hours-ago 2) (hours-ago 5))
(#[#{date pfwa3r0havo3glvxa5oa6eoyh-24} 0 0 0 10 5 11 2018 28800]
 #[#{date pfwa3r0havo3glvxa5oa6eoyh-24} 0 0 0 11 5 11 2018 28800]
 #[#{date pfwa3r0havo3glvxa5oa6eoyh-24} 0 0 0 12 5 11 2018 28800]
 #[#{date pfwa3r0havo3glvxa5oa6eoyh-24} 0 0 0 13 5 11 2018 28800])
 
> (oclocks-between/time (hours-ago/time 2) (hours-ago/time 5))
(#[#{time pfwa3r0havo3glvxa5oa6eoyh-25} time-utc 0 1541383200]
 #[#{time pfwa3r0havo3glvxa5oa6eoyh-25} time-utc 0 1541386800]
 #[#{time pfwa3r0havo3glvxa5oa6eoyh-25} time-utc 0 1541390400]
 #[#{time pfwa3r0havo3glvxa5oa6eoyh-25} time-utc 0 1541394000])
 
 
(require srfi/19)
(beginning-date (current-date))
;=> (date* 0 0 0 5 5 2019 0 124 #f 28800 0 "")
 
(beginning-date/month (current-date))
;=> (date* 0 0 0 1 5 2019 3 120 #f 28800 0 "")
 
(beginning-date/year (current-date))
;=> (date* 0 0 0 1 1 2019 2 0 #f 28800 0 "")
 
(date->string (parse-date "2018-01-01 11:11:11 +0800"))
;=> "Mon Jan 01 11:11:11+0800 2018"
 
(date->string (parse-date "2018/01/01 12"))
;=> "Mon Jan 01 12:00:00+0800 2018"

2 system

procedure

(system/verbose cmd)  boolean?

  cmd : string?
displays the executed logs and returns a boolean result of the executing of the cmd.

procedure

(system/v cmd)  boolean?

  cmd : string?
an alias procedure of system/verbose.

Examples:
 
(system/v "pwd")
==executed==> pwd
/Users/yanying/chive/
; => #t

3 base64

procedure

(base64-encode-string str)  string?

  str : string?
encode a string in base64.

procedure

(base64-decode-string str)  string?

  str : string?
decode a string in base64.

Examples:
 
(base64-encode-string "str")  ;=> "c3Ry\r\n"
(base64-decode-string "c3Ry=\r\n")   ;=> "str"

4 port

procedure

(port->bytes/base64 p)  bytes?

  p : port?
read content from a port and convert it to bytes.

procedure

(port->string/base64 p)  string?

  p : port?
read content from a port and convert it to a string.

Examples:
 
(port->bytes/base64 (open-input-file "/Users/ken/temp.rkt")) ;=> #"c3Ry=\r\n"
(port->string/base64 (open-input-file "/Users/ken/temp.rkt")) ;=> "c3Ry=\r\n"
 

5 smtp

procedure

(mail sender    
  recipients    
  subject    
  content    
  attachments)  mail?
  sender : string?
  recipients : list?
  subject : string?
  content : string?
  attachments : list?
make an email data with mail struct.

procedure

(mail-from email)  string?

  email : mail?
returns info about who the email was sent from.

procedure

(mail-tos email)  list?

  email : mail?
returns info about who this email was sent to.

procedure

(mail-subject email)  string?

  email : mail?
returns the email subject.

procedure

(mail-content email)  string?

  email : mail?
returns the email content.

procedure

(mail-attachment-files email)  list?

  email : mail?
returns a list of the email attachment file paths.

procedure

(mail-header email)  string?

  email : mail?
returns header string of the email.

procedure

(mail-header/info email)  string?

  email : mail?
returns sender, recipients, subject infos of an email’s header.

procedure

(mail-header/attachment email)  string?

  email : mail?
returns sender, recipients, subject infos of an email’s header.

procedure

(mail-send email    
  #:host host    
  [#:port port    
  #:usrename username]    
  #:password password)  void?
  email : mail?
  host : string?
  port : integer? = 25
  username : string? = (mail-from mail)
  password : string?
commit the email sending action.

Examples:
 
(define email (mail "user@qq.com" ; sent from
                    '("user1@qq.com") ; sent to
                    "the subject" ; subject
                    "the content" ; content
                    '("file-path1" "file-path2"); attachments
                    ))
 
(mail-header/info email)
(mail-header/attachment email)
 
(mail-send email
           #:host "smtp.qq.com"
           #:password "the_password")

6 phone-number

procedure

(phone-number-attribution ph-num conuntry)  (or string? #f)

  ph-num : string?
  conuntry : symbol?
inquery and retrun ph-num’s number attribution(location). currently, it only support phone numbers of China and the library is from google/libphonenumber

Examples:
 
> (phone-number-attribution "13838282689" 'cn)
; => "86138382|河南省郑州市"