Opened 8 years ago
Closed 8 years ago
#28103 closed New feature (fixed)
Add "quarter" lookup to DateField/DateTimeField
Reported by: | Matthew Pava | Owned by: | Mads Jensen |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | ORM Extract Trunc |
Cc: | Mariusz Felisiak | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I was able to successfully add it to my project, but it seems so basic and general that I would like to see it added to Django.
class ExtractQuarter(Extract): lookup_name = "quarter" DateField.register_lookup(ExtractQuarter)
You probably also want to add a corresponding Trunc function, though I haven't tested it.
class TruncQuarter(TruncBase): kind = "quarter"
Change History (8)
comment:1 by , 8 years ago
Summary: | Add ExtractQuarter to DateField → Add "quarter" lookup to DateField/DateTimeField |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 1.11 → master |
comment:2 by , 8 years ago
Cc: | added |
---|
comment:3 by , 8 years ago
comment:5 by , 8 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
comment:6 by , 8 years ago
Oracle and PostgreSQL have built-in functionality for truncating a date to the first month of a quarter. However, in Oracle, it rounds up (https://docs.oracle.com/database/121/SQLRF/functions271.htm#SQLRF52058) and in PostgreSQL, it's always rounded down (https://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC). Neither SQLite or MySQL has a convenient built-in functionality and it's a matter of interpretation.
The Extract functionality is implemented, and has the same behavior on all backends.
comment:7 by , 8 years ago
Patch needs improvement: | unset |
---|
You can take a look at very similar #25240 ticket.