-round expiration times to full seconds
[oweals/gnunet.git] / src / fs / fs_misc.c
index d4afc0d55dcbb502a791d1577765a64e838c313f..ee24fa250fd20ba6a7a26bd47cd4f1d4f6ed544d 100644 (file)
@@ -202,11 +202,30 @@ GNUNET_FS_year_to_time (unsigned int year)
   t.tm_yday = 1;
   tp = mktime (&t);
   GNUNET_break (tp != (time_t) - 1);
-  ret.abs_value = tp * 1000LL;  /* seconds to ms */
+  ret.abs_value_us = tp * 1000LL * 1000LL;  /* seconds to microseconds */
   return ret;
 }
 
 
+/**
+ * Convert an expiration time to the respective year (rounds)
+ *
+ * @param at absolute time 
+ * @return year a year (after 1970), 0 on error
+ */
+unsigned int 
+GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at)
+{
+  struct tm *t;
+  time_t tp;
+
+  tp = at.abs_value_us / 1000LL / 1000LL;    /* microseconds to seconds */
+  t = gmtime (&tp);
+  if (t == NULL)
+    return 0;
+  return t->tm_year + 1900;
+
+}
 
 
 /* end of fs_misc.c */