Sha256: 7a231538104722faff388a4d574dbc8462aaf33d141459f0676a9814b8e45b0b
Contents?: true
Size: 937 Bytes
Versions: 22
Compression:
Stored size: 937 Bytes
Contents
# frozen_string_literal: true String.class_eval do # Return the quarter start date. # # @return [Date] # def quarter_start quarter_date.beginning_of_quarter end # Return the quarter end date. # # @return [Date] # def quarter_end quarter_date.end_of_quarter end private # Parses a string for a quarter date. Expects the string to follow: 'qQyy' where # q = 1/2/3/4 and yy to be the last two digits of the year. # # @raise [RubyRailsExtensions::Errors::InvalidFormatError] if `self` is not qQyy # # @return [Date] # def quarter_date unless match?(/\A[1-4]q\d\d\z/i) raise(RubyRailsExtensions::Errors::InvalidFormatError, "Unexpected format (given #{self}, expected qQyy)") end values = scan(/\d/) quarter = values.shift.to_i year = "20#{values.join('')}".to_i month = quarter * 3 Date.new(year, month, 1) end end
Version data entries
22 entries across 22 versions & 1 rubygems