From 8d2fe139a61ed2ad3cc89fdc569ce22daf41ba96 Mon Sep 17 00:00:00 2001
From: Ben Longbons <b.r.longbons@gmail.com>
Date: Thu, 25 Aug 2011 16:14:49 -0700
Subject: Add script function time_stamp, a replacement for gettimestr

---
 world/map/npc/functions/time.txt | 56 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 world/map/npc/functions/time.txt

(limited to 'world/map/npc')

diff --git a/world/map/npc/functions/time.txt b/world/map/npc/functions/time.txt
new file mode 100644
index 00000000..2527b853
--- /dev/null
+++ b/world/map/npc/functions/time.txt
@@ -0,0 +1,56 @@
+// A replacement for gettimestr()
+// At some point this should be a builtin in the server
+// Should I allow formatting of times other than the current time?
+
+// Variables:
+// output @ts_date$ "yyyy-mm-dd"
+// output @ts_time$ "hh:mm:ss"
+
+function|script|time_stamp|{
+    // local variables
+    // if there is reasonable demand, these might be exported
+    // (that is what the builtin is likely to do)
+    set @ts_year,       gettime(7);
+    set @ts_month,      gettime(6);
+    set @ts_mday,       gettime(5);
+    //set @ts_wday,       gettime(4);
+    set @ts_hour,       gettime(3);
+    set @ts_minute,     gettime(2);
+    set @ts_second,     gettime(1);
+
+    // locals used to generate leading zeroes
+    set @ts_month_pad$, "";
+    set @ts_mday_pad$,  "";
+    set @ts_hour_pad$,  "";
+    set @ts_minute_pad$, "";
+    set @ts_second_pad$, "";
+
+    if (@ts_month < 10)
+        set @ts_month_pad$, "0";
+    if (@ts_mday < 10)
+        set @ts_mday_pad$, "0";
+    if (@ts_hour < 10)
+        set @ts_hour_pad$, "0";
+    if (@ts_minute < 10)
+        set @ts_minute_pad$, "0";
+    if (@ts_second < 10)
+        set @ts_second_pad$, "0";
+
+    set @ts_date$, @ts_year + "-" + @ts_month_pad$ + @ts_month + "-" + @ts_mday_pad$ + @ts_mday;
+    set @ts_time$, @ts_hour_pad$ + @ts_hour + ":" + @ts_minute_pad$ + @ts_minute + ":" +@ts_second_pad$ + @ts_second;
+
+    // cleanup
+    set @ts_year,       0;
+    set @ts_month,      0;
+    set @ts_mday,       0;
+    set @ts_hour,       0;
+    set @ts_minute,     0;
+    set @ts_second,     0;
+    set @ts_month_pad$, "";
+    set @ts_mday_pad$,  "";
+    set @ts_hour_pad$,  "";
+    set @ts_minute_pad$, "";
+    set @ts_second_pad$, "";
+
+    return;
+}
-- 
cgit v1.2.3-70-g09d2