summaryrefslogtreecommitdiff
path: root/src/datetime.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-18 15:23:02 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-18 15:23:02 +0200
commit9837632ea985b87eb6aaa7f619a0b859fc6c40f6 (patch)
treef143461843ba2fdaa8e7499ebf52afda3eb08cd4 /src/datetime.c
parent7b4d3ab22988d021d5f12b81aec746f7e486fa52 (diff)
update to 4.3.10HEADmaster
Diffstat (limited to 'src/datetime.c')
-rw-r--r--src/datetime.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/datetime.c b/src/datetime.c
index 3db5f7f..9048822 100644
--- a/src/datetime.c
+++ b/src/datetime.c
@@ -51,3 +51,37 @@ void datetime_tai(struct datetime *dt,datetime_sec t)
dt->mon = mon;
dt->mday = day + 1;
}
+
+/* roughly 100x faster than mktime() */
+
+datetime_sec datetime_untai(struct datetime *dt)
+{
+ int year;
+ int day;
+ int mon;
+
+ year = dt->year + 1900;
+
+ mon = dt->mon;
+ if (mon >= 2) { mon -= 2; }
+ else { mon += 10; --year; }
+
+ day = (dt->mday - 1) * 10 + 5 + 306 * mon;
+ day /= 10;
+
+ if (day == 365) { year -= 3; day = 1460; }
+ else { day += 365 * (year % 4); }
+ year /= 4;
+
+ day += 1461 * (year % 25);
+ year /= 25;
+
+ if (day == 36524) { year -= 3; day = 146096; }
+ else { day += 36524 * (year % 4); }
+ year /= 4;
+
+ day += 146097 * (year - 5);
+ day += 11017;
+
+ return ((day * 24 + dt->hour) * 60 + dt->min) * 60 + dt->sec;
+}