This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 26638ceb += util
26638ceb is described below
commit 26638ceb914edab77249116fa0cbb989da8c3252
Author: Sebb <[email protected]>
AuthorDate: Sun Feb 18 13:13:01 2024 +0000
+= util
---
lib/whimsy/asf/time-utils.rb | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/lib/whimsy/asf/time-utils.rb b/lib/whimsy/asf/time-utils.rb
new file mode 100644
index 00000000..d4ad65cb
--- /dev/null
+++ b/lib/whimsy/asf/time-utils.rb
@@ -0,0 +1,25 @@
+# Time/date utilities
+
+# This addon must be required before use
+
+module ASFTime
+ # Convert seconds to number of days, hours or minutes
+ # Intended for countdown-style displays
+ def self.secs2text(secs)
+ m = secs / 60
+ s = secs - m*60
+ h = m / 60
+ m = m - h*60
+ d = h / 24
+ h = h - d*24
+ return "#{d} days" if d > 0
+ return "#{h} hours" if h > 0
+ return "#{m} minutes"
+ end
+end
+
+if __FILE__ == $0
+ p ASFTime.secs2text(120)
+ p ASFTime.secs2text(23101)
+ p ASFTime.secs2text(223911)
+end