1;; Simple time manipulation library.
2;;
3;; Copyright (C) 2017 g10 Code GmbH
4;;
5;; This file is part of GnuPG.
6;;
7;; GnuPG is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation; either version 3 of the License, or
10;; (at your option) any later version.
11;;
12;; GnuPG is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15;; GNU General Public License for more details.
16;;
17;; You should have received a copy of the GNU General Public License
18;; along with this program; if not, see <http://www.gnu.org/licenses/>.
19
20;; This library mimics what GnuPG thinks about expiration times.
21;; Granularity is one second.  Its focus is not on correctness.
22
23;; Conversion functions.
24(define (minutes->seconds minutes)
25  (* minutes 60))
26(define (hours->seconds hours)
27  (* hours 60 60))
28(define (days->seconds days)
29  (* days 24 60 60))
30(define (weeks->seconds weeks)
31  (days->seconds (* weeks 7)))
32(define (months->seconds months)
33  (days->seconds (* months 30)))
34(define (years->seconds years)
35  (days->seconds (* years 365)))
36
37(define (time-matches? a b slack)
38  (< (abs (- a b)) slack))
39(assert (time-matches? (hours->seconds 1) (hours->seconds 2) (hours->seconds 2)))
40(assert (time-matches? (hours->seconds 2) (hours->seconds 1) (hours->seconds 2)))
41(assert (not (time-matches? (hours->seconds 4) (hours->seconds 1) (hours->seconds 2))))
42(assert (not (time-matches? (hours->seconds 1) (hours->seconds 4) (hours->seconds 2))))
43