X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fcertregen%2Flib%2Fpuppet_x%2Fcertregen%2Futil.rb;fp=3rdparty%2Fmodules%2Fcertregen%2Flib%2Fpuppet_x%2Fcertregen%2Futil.rb;h=e21298a71070721d4b16ce918a5ffbc5b55eee85;hb=8c20cc97eaf30a0aaf9abfba2f33d5b5f9f06ae2;hp=0000000000000000000000000000000000000000;hpb=1f80b78f88d98160faf661374fc8e760252d131b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/certregen/lib/puppet_x/certregen/util.rb b/3rdparty/modules/certregen/lib/puppet_x/certregen/util.rb new file mode 100644 index 000000000..e21298a71 --- /dev/null +++ b/3rdparty/modules/certregen/lib/puppet_x/certregen/util.rb @@ -0,0 +1,27 @@ +module PuppetX + module Certregen + module Util + module_function + + def duration(epoch) + seconds = epoch.to_i + minutes = (epoch / 60).to_i; seconds %= 60 if minutes > 0 + hours = (minutes / 60).to_i; minutes %= 60 if hours > 0 + days = (hours / 24).to_i; hours %= 24 if days > 0 + years = (days / 365).to_i; days %= 365 if years > 0 + + list = [] + list << "#{years} #{pluralize('year', years)}" if years > 0 + list << "#{days} #{pluralize('day', days)}" if days > 0 + list << "#{hours} #{pluralize('hour', hours)}" if hours > 0 + list << "#{minutes} #{pluralize('minute', minutes)}" if minutes > 0 + list << "#{seconds} #{pluralize('second', seconds)}" if seconds > 0 + list.join(", ") + end + + def pluralize(str, count) + count == 1 ? str : str + 's' + end + end + end +end