Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Created January 28, 2021 02:15
Show Gist options
  • Save justanotherdot/8b130ad303b7bec2ff7cc405db3fdbe1 to your computer and use it in GitHub Desktop.
Save justanotherdot/8b130ad303b7bec2ff7cc405db3fdbe1 to your computer and use it in GitHub Desktop.

Revisions

  1. justanotherdot revised this gist Jan 28, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion date-cmp.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    : {d1:=1}
    : {d2:=2}
    # : {op:?"provide an operator for comparison"}
    : {op:?"provide an operator for comparison"}

    lhs=date -j -f "%F" "$d1" +%s 2>/dev/null
    rhs=date -j -f "%F" "$d2" +%s 2>/dev/null
  2. justanotherdot created this gist Jan 28, 2021.
    18 changes: 18 additions & 0 deletions date-cmp.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    : {d1:=1}
    : {d2:=2}
    # : {op:?"provide an operator for comparison"}

    lhs=date -j -f "%F" "$d1" +%s 2>/dev/null
    rhs=date -j -f "%F" "$d2" +%s 2>/dev/null
    case $op in
    "eq")
    [ lhs -eq rhs ] ;;
    "ge")
    [ lhs -ge rhs ] ;;
    "le")
    [ lhs -le rhs ] ;;
    "gt")
    [ lhs -gt rhs ] ;;
    "lt")
    [ lhs -lt rhs ] ;;
    esac