Wednesday, July 15, 2026 2:52:49 AM
> project show esm_bot
A sophisticated Discord bot that bridges Arma 3 Exile servers with Discord communities. Built in Ruby with secure TCP communication, it delivers territory management, real-time notifications, and comprehensive server administration right in your Discord channels.
Details
> time.rb
# frozen_string_literal: true

module ESM
  class Time
    include ActionView::Helpers::DateHelper
    include ActiveSupport::Inflector

    module Format
      TIME = "%F at %I:%M %p UTC"
      DATE = "%F"
      SQL_TIME = "%Y-%m-%dT%X"
    end

    def self.distance_of_time_in_words(to_time, from_time: ESM::Time.current, precise: true)
      distance = new.distance_of_time_in_words(from_time.utc, to_time.utc, include_seconds: precise)
      singularize(distance)
    end

    def self.singularize(distance)
      # #distance_of_time_in_words doesn't singularize the single types.
      # This converts 1 seconds -> 1 second; 1 minutes -> 1 minute, etc.
      distance.gsub(/(?<!\d)1 (?:seconds|minutes|hours|days|weeks|months|years)/i, &:singularize)
    end

    # Parses a stringed time as UTC time
    def self.parse(time)
      return time if time.is_a?(ActiveSupport::TimeWithZone)

      ::Time.find_zone("UTC").parse(time)
    end

    def self.current
      ::Time.find_zone("UTC").now
    end

    def self.now
      ::Time.zone.now
    end
  end
end
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 43aa0d7