mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 12:33:45 +08:00
7c3a29c9d6
* Updates GitHub Actions * Switches from `bundler/inline` to an optional group in the `Gemfile` because the previous solution didn't work well with rspec * Adds the converter framework and tests * Allows loading private converters (see README) * Switches from multiple CLI tools to a single CLI * Makes DB connections reusable and adds a new abstraction for the `IntermediateDB` * `IntermediateDB` acts as an interface for IPC calls when a converter steps runs in parallel (forks). Only the main process writes to the DB. * Includes a simple example implementation of a converter for now.
23 lines
625 B
Ruby
23 lines
625 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Migrations
|
|
module DateHelper
|
|
# based on code from https://gist.github.com/emmahsax/af285a4b71d8506a1625a3e591dc993b
|
|
def self.human_readable_time(secs)
|
|
return "< 1 second" if secs < 1
|
|
|
|
[[60, :seconds], [60, :minutes], [24, :hours], [Float::INFINITY, :days]].map do |count, name|
|
|
next if secs <= 0
|
|
|
|
secs, number = secs.divmod(count)
|
|
unless number.to_i == 0
|
|
"#{number.to_i} #{number == 1 ? name.to_s.delete_suffix("s") : name}"
|
|
end
|
|
end
|
|
.compact
|
|
.reverse
|
|
.join(", ")
|
|
end
|
|
end
|
|
end
|