Sha256: 525b32c968af208a5cdb979d755b89feb7e3f09c8fd41a50f5a7a35b68a21e1e
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true require "how_is/version" require "date" module HowIs ## # Various helper functions for working with DateTime objects. module DateTimeHelpers # Check if +left+ is less than or equal to +right+, where both are string # representations of a date. # # @param left [String] A string representation of a date. # @param right [String] A string representation of a date. # @return [Boolean] True if +left+ is less-than-or-equal to +right+, # otherwise false. def date_le(left, right) left = str_to_dt(left) right = str_to_dt(right) left <= right end # Check if +left+ is greater than or equal to +right+, where both are string # representations of a date. # # @param left [String] A string representation of a date. # @param right [String] A string representation of a date. # @return [Boolean] True if +left+ is greater-than-or-equal to +right+, # otherwise false. def date_ge(left, right) left = str_to_dt(left) right = str_to_dt(right) left >= right end private # Converts a +String+ representation of a date to a +DateTime+. # # @param str [String] A date. # @return [DateTime] A DateTime representation of +str+. def str_to_dt(str) DateTime.parse(str) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
how_is-25.0.0 | lib/how_is/date_time_helpers.rb |