Class: Readiness::Dates

Inherits:
Object
  • Object
show all
Defined in:
lib/support_readiness/dates.rb

Overview

Defines the class Dates within the module Readiness.

Author:

  • Jason Colyer

Since:

  • 1.0.12

Class Method Summary collapse

Class Method Details

.current_quarterString

Return the current GitLab quarter as of the current date in format “FY##Q#”

Examples:

require 'support_readiness'
pp Readiness::Dates.current_quarter
# => "FY25Q3"

Returns:

  • (String)

Since:

  • 1.0.12



19
20
21
# File 'lib/support_readiness/dates.rb', line 19

def self.current_quarter
  determine_quarter(Time.now)
end

.determine_quarter(date) ⇒ String

Returns the GitLab quarter in format “FY##Q#” from a give date

Examples:

require 'support_readiness'
pp Readiness::Dates.next_quarter
# => "FY25Q4"

Parameters:

  • date (Various)

    The date to reference. Can take a String, Date, DateTime, or Time object

Returns:

  • (String)

Since:

  • 1.0.12



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/support_readiness/dates.rb', line 72

def self.determine_quarter(date)
  date = Time.parse(date) unless [DateTime, Date, Time].include? date.class
  month = date.month
  year = date.year.digits(100).first
  case month
  when 1
    "FY#{year}Q4"
  when 2..4
    "FY#{year + 1}Q1"
  when 5..7
    "FY#{year + 1}Q2"
  when 8..10
    "FY#{year + 1}Q3"
  when 11..12
    "FY#{year + 1}Q4"
  end
end

.next_quarter(date = Time.now) ⇒ String

Return the next GitLab quarter in format “FY##Q#”. Defaults to assuming you mean for the current date

Examples:

require 'support_readiness'
pp Readiness::Dates.next_quarter
# => "FY25Q4"

Parameters:

  • date (Various) (defaults to: Time.now)

    The date to reference. Can take a String, Date, DateTime, or Time object

Returns:

  • (String)

Since:

  • 1.0.12



32
33
34
35
36
37
38
39
40
41
# File 'lib/support_readiness/dates.rb', line 32

def self.next_quarter(date = Time.now)
  current = determine_quarter(date)
  year = current.split('Q').first.split('FY').last.to_i
  quarter = current.split('Q').last.to_i
  if quarter == 4
    "FY#{year + 1}Q1"
  else
    "FY#{year}Q#{quarter + 1}"
  end
end

.previous_quarter(date = Time.now) ⇒ String

Return the previous GitLab quarter in format “FY##Q#”. Defaults to assuming you mean for the current date

Examples:

require 'support_readiness'
pp Readiness::Dates.next_quarter
# => "FY25Q4"

Parameters:

  • date (Various) (defaults to: Time.now)

    The date to reference. Can take a String, Date, DateTime, or Time object

Returns:

  • (String)

Since:

  • 1.0.12



52
53
54
55
56
57
58
59
60
61
# File 'lib/support_readiness/dates.rb', line 52

def self.previous_quarter(date = Time.now)
  current = determine_quarter(date)
  year = current.split('Q').first.split('FY').last.to_i
  quarter = current.split('Q').last.to_i
  if quarter == 1
    "FY#{year - 1}Q4"
  else
    "FY#{year}Q#{quarter - 1}"
  end
end