1 ! Copyright (C) 2023 Zoltán Kéri.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors calendar hashcash hashcash.private kernel
4 literals namespaces sequences splitting tools.test ;
7 : generate-stamp ( -- stamp ) "foo@bar.com" mint ;
9 ! Generate the stamp iff it does not exist.
10 ! You can delete it with `generated-stamp global delete-at`.
11 INITIALIZED-SYMBOL: generated-stamp [ generate-stamp ]
13 ! Generate the stamp iff it is set to `f`.
14 ! You can change it to `f` with `f generated-stamp set-global`.
15 generated-stamp get f eq? [ generate-stamp generated-stamp set ] when
18 generated-stamp get dup ":" split third valid-date? swap drop
23 generated-stamp get valid-stamp?
29 generated-stamp get valid-stamp?
33 { t } [ generated-stamp get valid-stamp? ] unit-test
36 <hashcash> "foo@bar.com" >>resource 16 >>bits
41 [ 9999 expiry-days set
42 "1:20:220403:foo@bar.com::fAY*-p!s:23472" valid-stamp?
48 now-gmt-yymmdd valid-date?
54 now-gmt-yymmdd valid-date?
58 { t } [ now-gmt-yymmdd valid-date? ] unit-test
60 { 30 } [ "220131" "220101" yymmdd-gmt-diff ] unit-test
61 { -30 } [ "220101" "220131" yymmdd-gmt-diff ] unit-test
64 now-gmt 1 days time- timestamp>yymmdd on-or-before-today? nip
68 now-gmt timestamp>yymmdd on-or-before-today? nip
72 now-gmt 1 days time+ timestamp>yymmdd on-or-before-today? nip