Opened 8 years ago

Closed 7 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 Mariusz Felisiak, 8 years ago

Summary: Add ExtractQuarter to DateFieldAdd "quarter" lookup to DateField/DateTimeField
Triage Stage: UnreviewedAccepted
Version: 1.11master

comment:2 by Mariusz Felisiak, 8 years ago

Cc: Mariusz Felisiak added

comment:3 by Mariusz Felisiak, 8 years ago

You can take a look at very similar #25240 ticket.

comment:4 by Mads Jensen, 8 years ago

Has patch: set
Owner: changed from nobody to Mads Jensen
Status: newassigned

comment:5 by Tim Graham, 8 years ago

Easy pickings: unset
Patch needs improvement: set

comment:6 by Mads Jensen, 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 Mads Jensen, 8 years ago

Patch needs improvement: unset

comment:8 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In c7f6ffbd:

Fixed #28103 -- Added quarter extract, truncation, and lookup.

Thanks Mariusz Felisiak, Tim Graham, and Adam Johnson for review.

Note: See TracTickets for help on using tickets.
Back to Top