summaryrefslogtreecommitdiff
path: root/world/map/npc/functions/time.txt
diff options
context:
space:
mode:
Diffstat (limited to 'world/map/npc/functions/time.txt')
-rw-r--r--world/map/npc/functions/time.txt71
1 files changed, 71 insertions, 0 deletions
diff --git a/world/map/npc/functions/time.txt b/world/map/npc/functions/time.txt
index 9f141d3e..695c4cec 100644
--- a/world/map/npc/functions/time.txt
+++ b/world/map/npc/functions/time.txt
@@ -55,3 +55,74 @@ function|script|time_stamp
return;
}
+
+
+
+// HumanTime - returns a human-readable time
+// author: meko
+
+// Variables:
+// input @ms integer
+// output @time$ string
+
+function|script|HumanTime
+{
+ set @time$, "now";
+ if(@ms < 1000) goto L_Millis; // under 1 second we have nothing to count
+ set @seconds, @ms / 1000;
+ set @ms, @ms % 1000;
+ if(@seconds < 60) goto L_Seconds;
+ set @minutes, @seconds / 60;
+ set @seconds, @seconds % 60;
+ if(@minutes < 60) goto L_Minutes;
+ set @hours, @minutes / 60;
+ set @minutes, @minutes % 60;
+ if(@hours < 60) goto L_Hours;
+ return;
+
+L_Millis:
+ set @time$, @ms + "ms";
+ return;
+
+L_Seconds:
+ set @unit$, "second";
+ if(@seconds > 1) set @unit$, "seconds";
+ set @unit2$, "millisecond";
+ if(@ms > 1) set @unit2$, "milliseconds";
+ set @time$, @seconds + " " + @unit$;
+ if(@ms) set @time$, @time$ + " and " + @ms + " " + @unit2$;
+ return;
+
+L_Minutes:
+ set @unit$, "minute";
+ if(@minutes > 1) set @unit$, "minutes";
+ set @unit2$, "second";
+ if(@seconds > 1) set @unit2$, "seconds";
+ set @unit3$, "millisecond";
+ if(@ms > 1) set @unit3$, "milliseconds";
+ set @time$, @minutes + " " + @unit$;
+ set @separator$, " and ";
+ if(@ms) set @separator$, ", ";
+ if(@seconds) set @time$, @time$ + @separator$ + @seconds + " " + @unit2$;
+ if(@ms) set @time$, @time$ + " and " + @ms + " " + @unit3$;
+ return;
+
+L_Hours:
+ set @unit$, "hour";
+ if(@hours > 1) set @unit$, "hours";
+ set @unit2$, "minute";
+ if(@minutes > 1) set @unit2$, "minutes";
+ set @unit3$, "second";
+ if(@seconds > 1) set @unit3$, "seconds";
+ set @unit4$, "millisecond";
+ if(@ms > 1) set @unit4$, "milliseconds";
+ set @time$, @hours + " " + @unit$;
+ set @separator$, " and ";
+ if(@seconds || @ms) set @separator$, ", ";
+ if(@minutes) set @time$, @time$ + @separator$ + @minutes + " " + @unit2$;
+ set @separator$, " and ";
+ if(@ms) set @separator$, ", ";
+ if(@seconds) set @time$, @time$ + @separator$ + @seconds + " " + @unit3$;
+ if(@ms) set @time$, @time$ + " and " + @ms + " " + @unit4$;
+ return;
+}