Skip to content

Conversation

swanson
Copy link
Contributor

@swanson swanson commented May 3, 2022

Summary

Adds a quarter method to date/time.

ActiveSupport has existing beginning_of_quarter and end_of_quarter methods. This PR adds quarter to complete the conceptual symmetry.

For dates we have year / beginning_of_year / end_of_year. Same for month, week, etc

I think this feature is useful outside of "financial" applications that use fiscal year math; Rails applications of all varieties and business domains include reports and data aggregations based on quarters.

Since ActiveSupport has an opinion on the "quarter boundaries" (the traditional [3, 6, 9, 12] months), it makes sense to also have a matching quarter method.

@swanson swanson changed the title Add quarter Add quarter to date/time May 3, 2022
@swanson swanson force-pushed the add-quarter branch 2 times, most recently from 6c93e0c to c77bcb6 Compare May 3, 2022 13:36
@swanson
Copy link
Contributor Author

swanson commented Jun 22, 2022

Per discussion with @eileencodes - it probably makes more sense to deprecate the beginning_of_quarter and end_of_quarter methods to eliminate the mismatch in APIs instead of adding new methods to ActiveSupport. The fact that ActiveSupport has a "stance" on the quarter boundaries is not necessarily good as companies/apps may use a different fiscal calendar anyways.

Developers wishing to use quarter in their apps can patch it in, it's a trivial method to implement.

@swanson
Copy link
Contributor Author

swanson commented Jun 23, 2022

From discussion with @dhh:

Expanding #quarter calculations to match the other durations makes fine sense to me, imo.
Yes, some companies have financial quarters. But they also have financial years.
That's separate from dealing with basic quarters. Q1 as a calendar term is indeed always the same (jan 1 - march 31).

@dhh dhh merged commit 959d46e into rails:main Jul 14, 2022
jamis added a commit to basecamp/rails that referenced this pull request Jul 18, 2022
* main: (169 commits)
  Add endless range example to the Active Record Querying guide
  Added default values to raise_delivery_errors guide (rails#45616)
  better docs for ActiveSupport::EncryptedFile#read
  Fix caching of missed translations
  Fix extra changelog entry added in 959d46e (rails#45604)
  Add `quarter` method to date/time (rails#45009)
  Fix testing changing yaml_column_permitted_classes
  Remove unnecessary or incorrect calls to connection_handler
  Defer constant loading of `ActiveRecord::DestroyAssociationAsyncJob` via a String instead of a class constant
  ActiveRecord::Store encode store as a regular Hash
  Appease rubocop
  Fix failing test with mysql 5.7
  Fix cases where CTE's are not supported
  Allow Symbols by default in YAML serialized columns
  Remove unnecessary initializers
  Preserve `job.enqueued_at` timestamp precision
  Improve performance by removing respond_to? from runtime code
  Move configuration to the right section
  Fix ivar name in PoolManager
  Change ActiveRecord::Coders::YAMLColumn default to safe_load
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants