Skip to content

Manipulating dates with Chronic

Alex Leferry 2 edited this page May 17, 2018 · 4 revisions

A natural language date and time parser.

Examples

Changing time format

Selection

2018-03-21

Command

|chronic '%A, %d %B %Y'

Result

Wednesday, 21 March 2018

Incrementing / Decrementing dates

Selection

2018-03-21

Command

|chronic tomorrow %F

Result

2018-03-22

Grepping

Examples

Grep things to do over the next 7 days:

grep-period 'To do' '%F' today week

Configuration

define-command grep-period -params 4.. -docstring 'grep-period <pattern> <format> <time-start> <time-end> [argument…]: Grep period' %{ %sh{
  pattern=$1
  format=$2
  start=$3
  end=$4
  shift 4
  factory=day
  format="($pattern.+$format)|($format.+$pattern)"
  regex=$(
    chronic-period "$format" "$start" "$end" "$factory" |
    paste --serial --delimiters '|'
  )
  printf "grep '%s' %s" "$regex" "$@"
}}
Clone this wiki locally