summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2023-05-07 12:39:26 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2023-05-07 13:33:29 +0200
commitbdcbf8589716c047a732db3cc349ee6114ccc25f (patch)
tree6c60331972e61cee30ef7835bb25935f1b435ba1 /util.c
parentccee88cb02cb54f586d22c53e8bb8865817c3dc4 (diff)
iterate on previous commit which adds $SFEED_NEW_MAX_SECS
Separate the common pattern to get the time to compare new items in format tools to the new util function: getcomparetime(). Some changes and notes: - Change it so it is OK to set this value to 0 or negative (in the future). - sfeed_curses: truncating newmaxsecs to an int would limit the value too much. - Just use strtotime() and parse the value to time_t. This is a signed long (32-bit, until 2038) or signed long long (64-bit) on most platforms. - sfeed_curses gets the comparison time on reload aswell and it needs errno = 0, because it uses die(). time() is not guaranteed to set an errno if it fails. - Rename environment variable to $SFEED_NEW_AGE.
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/util.c b/util.c
index 0b7da06..e5aec3b 100644
--- a/util.c
+++ b/util.c
@@ -318,6 +318,24 @@ strtotime(const char *s, time_t *t)
return 0;
}
+time_t
+getcomparetime(void)
+{
+ time_t now, t;
+ char *p;
+
+ if ((now = time(NULL)) == (time_t)-1)
+ return (time_t)-1;
+
+ if ((p = getenv("SFEED_NEW_AGE"))) {
+ if (strtotime(p, &t) == -1)
+ return (time_t)-1;
+ return now - t;
+ }
+
+ return now - 86400; /* 1 day is old news */
+}
+
/* Escape characters below as HTML 2.0 / XML 1.0. */
void
xmlencode(const char *s, FILE *fp)