aboutsummaryrefslogtreecommitdiff
path: root/src/util/age_restriction.c
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-06-27 09:45:50 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2023-06-27 09:45:50 +0200
commit145310e20e1a80d7c3a4a76a27f1e415bea7b3ce (patch)
tree0ab96ce9160504ce2df2171f3a4cb9a2de068339 /src/util/age_restriction.c
parentddd0e0af136f694db6013abd0344f20c1931bad9 (diff)
downloadexchange-145310e20e1a80d7c3a4a76a27f1e415bea7b3ce.tar.xz
added birthdate parser
Diffstat (limited to 'src/util/age_restriction.c')
-rw-r--r--src/util/age_restriction.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/util/age_restriction.c b/src/util/age_restriction.c
index b667fa3a9..839ed7cd5 100644
--- a/src/util/age_restriction.c
+++ b/src/util/age_restriction.c
@@ -710,4 +710,57 @@ TALER_age_restriction_from_secret (
}
+enum GNUNET_GenericReturnValue
+TALER_parse_coarse_date (
+ const char *in,
+ const struct TALER_AgeMask *mask,
+ uint32_t *out)
+{
+ struct tm date = {0};
+ struct tm limit = {0};
+ time_t seconds;
+
+ if (NULL == in)
+ {
+ /* FIXME[oec]: correct behaviour? */
+ *out = 0;
+ return GNUNET_OK;
+ }
+
+ GNUNET_assert (NULL !=mask);
+ GNUNET_assert (NULL !=out);
+
+ if (NULL == strptime (in, "%Y-%0m-%0d", &date))
+ {
+ if (NULL == strptime (in, "%Y-%0m-00", &date))
+ if (NULL == strptime (in, "%Y-00-00", &date))
+ return GNUNET_SYSERR;
+
+ /* turns out that the day is off by one in the last two cases */
+ date.tm_mday += 1;
+ }
+
+ seconds = mktime (&date);
+ if (-1 == seconds)
+ return GNUNET_SYSERR;
+
+ /* calculate the limit date for the largest age group */
+ localtime_r (&(time_t){time (NULL)}, &limit);
+ limit.tm_year -= TALER_get_lowest_age (mask, 255);
+ GNUNET_assert (-1 != mktime (&limit));
+
+ if ((limit.tm_year < date.tm_year)
+ || ((limit.tm_year == date.tm_year)
+ && (limit.tm_mon < date.tm_mon))
+ || ((limit.tm_year == date.tm_year)
+ && (limit.tm_mon == date.tm_mon)
+ && (limit.tm_mday < date.tm_mday)))
+ *out = seconds / 60 / 60 / 24;
+ else
+ *out = 0;
+
+ return GNUNET_OK;
+}
+
+
/* end util/age_restriction.c */