aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/mauve_time.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-13 11:02:37 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-13 11:02:37 +0100
commitb22cbc87927553f6dbb5754281e95fe9bad2eed1 (patch)
tree5575791fe84492648a8cc92433c267815056507a /lib/mauve/mauve_time.rb
parent495c44445642cfae8f23fadde299ad5307f5be58 (diff)
* Tidied up mauveserver to handle HUP restarts
* Added HTML santizing to the alert class, so bad HTML is stripped as part of processing. * Alert#cleared? now means "not raised" * Better error handling in the Timer class, making sure that the timer never gets permanently frozen. * Moved notification and packet buffers to the Server class, meaning that if the Processor or Notifier threads crash, we don't lose all the items waiting to be processed/notified. * XMPP/Email Alerts now use templates, instead of instance methods. * Emails now get sent as multipart with HTML to allow detail fields to be shown as nature intended.
Diffstat (limited to 'lib/mauve/mauve_time.rb')
-rw-r--r--lib/mauve/mauve_time.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/mauve/mauve_time.rb b/lib/mauve/mauve_time.rb
index bf69d1b..504e6ae 100644
--- a/lib/mauve/mauve_time.rb
+++ b/lib/mauve/mauve_time.rb
@@ -9,6 +9,24 @@ module Mauve
self.iso8601
end
+ def to_s_relative(now = MauveTime.now)
+ diff = (self.to_f - now.to_f).to_i
+ case diff
+ when -5184000..-17200 then "in #{-diff/86400} days"
+ when -172799..-3600 then "in #{-diff/3600} hours"
+ when -3599..-300 then "in #{-diff/60} minutes"
+ when -299..-1 then "very soon"
+ when 0..299 then "just now"
+ when 300..3599 then "#{diff/60} minutes ago"
+ when 3600..172799 then "#{diff/3600} hours ago"
+ when 172800..5184000 then "#{diff/86400} days ago"
+ else
+ diff > 518400 ?
+ "#{diff/2592000} months ago" :
+ "in #{-diff/2592000} months"
+ end
+ end
+
end
end