Req #76622 [Opn->Dup]: Support "quarter" keyword as relative format for DateTime

From: Date: Wed, 28 Jul 2021 10:17:47 +0000
Subject: Req #76622 [Opn->Dup]: Support "quarter" keyword as relative format for DateTime
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235429@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76622&edit=1

 ID:                 76622
 Updated by:         cmb@php.net
 Reported by:        thomas at landauer dot at
 Summary:            Support "quarter" keyword as relative format for
                     DateTime
-Status:             Open
+Status:             Duplicate
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   Any
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Bug #15184 has been re-opened in the meantime, so I'm closing this
as duplicate.


Previous Comments:
------------------------------------------------------------------------
[2018-07-15 11:36:40] thomas at landauer dot at

Sorry, that other bug didn't show up when I searched for "quarter".

When it comes to calendars, *anything* is a mess. E.g. it isn't even universally clear which
year we have: https://en.wikipedia.org/wiki/Hebrew_calendar

But: I have never heard from any other quarters than these: https://en.wikipedia.org/wiki/Calendar_year#Quarters
Even https://en.wikipedia.org/wiki/Fiscal_year
mainly sticks to that, some ambiguity is just about the *numbering* of the quarters. So
"first|last day of last|this|next quarter" should be fine for everybody.

And there have been even more tricky questions in the past, for which finally a common solution
could be agreed upon, e.g.:
http://php.net/manual/en/datetime.formats.relative.php
> Weeks always start on monday. Formerly, sunday would also be considered to start a week.

------------------------------------------------------------------------
[2018-07-15 08:32:42] requinix@php.net

Yeah, adding or subtracting months creates a risk of overflowing/underflowing dates resulting in
wrong results for a few days of each year. It's okay for the quarter-to-timestamp direction
since the quarter would "be" on the 1st of some month, but going in reverse you'd
have to deal with February and 31sts.

The issue is complicated enough to prove it needs its own library. As for PHP, I'm still hoping
there's some simple solution that can at least be a starting point for most use cases.

------------------------------------------------------------------------
[2018-07-15 07:51:49] a at b dot c dot de

That would work (I'd be using "+ 3 months" and "+ 5 months"); the
suggestion in the other bug you cite (#15184) for date('q') on the other hand would be
useless for a year starting in June.

It's the difference between "get a timestamp for a given quarter" and "get a
quarter for a given timestamp". The former would actually be easier.

------------------------------------------------------------------------
[2018-07-15 03:47:08] requinix@php.net

For some, yes, but most of them I saw are based on the calendar year so chaining one or two relative
amounts should get the job done. For example, US federal is one quarter behind the calendar; its Q1
2018 started Oct 1 2017 and you could get it with "quarter 1 2018 -3 months".

------------------------------------------------------------------------
[2018-07-15 03:37:50] a at b dot c dot de

Although in some of those "other" cases you still need to know the month to make the right
adjustment - and if you have that you can calculate the quarter anyway.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=76622


--
Edit this bug report at https://bugs.php.net/bug.php?id=76622&edit=1


Thread (8 messages)

« previous php.bugs (#235429) next »