Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2019-08-11 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  Ben Buchwald |Owner:  Simon
 |  Charette
 Type:  New feature  |   Status:  closed
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  fixed
 Keywords:  datetime duration| Triage Stage:  Ready for
  expression |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Mariusz Felisiak ):

 In [changeset:"088a6fab1ccd1efcd4ce28b353df3c03dcfa0caf" 088a6fa]:
 {{{
 #!CommitTicketReference repository=""
 revision="088a6fab1ccd1efcd4ce28b353df3c03dcfa0caf"
 Refs #24793 -- Removed bogus connection argument from
 SQLCompiler.compile() calls.

 The method doesn't expect a connection object to be passed as its second
 argument.
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.3b12c31b2916de09d8f53f7707f2dab8%40djangoproject.com.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2016-02-26 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  charettes
 Type:  New feature  |   Status:  closed
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  fixed
 Keywords:  datetime duration| Triage Stage:  Ready for
  expression |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Simon Charette ):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"766afc22a1dfa7d34a08de85356b7bc9dba025e7" 766afc22]:
 {{{
 #!CommitTicketReference repository=""
 revision="766afc22a1dfa7d34a08de85356b7bc9dba025e7"
 Fixed #24793 -- Unified temporal difference support.
 }}}

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.f2e8bc7c260feedd51593fb83b69e95f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2016-02-26 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  charettes
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Ready for
  expression |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by timgraham):

 * stage:  Accepted => Ready for checkin


--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.dc620e40bba3fcecdefe1e7f66a9de05%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2016-01-23 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  charettes
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by charettes):

 * needs_docs:  1 => 0
 * version:  1.8 => master


--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.5fe322794fe63de56438e4125e9d9be7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2016-01-23 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  charettes
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  1|  Needs documentation:  1
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by timgraham):

 * needs_docs:  0 => 1


Comment:

 Needs a mention in the release notes for third-party database backends.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.c2e25d175ae5d0997ece2dd7b58cd9c5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2016-01-19 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  charettes
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by charettes):

 * has_patch:  0 => 1


Comment:

 [https://github.com/django/django/pull/5997 PR]

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.860ec50d87f044145b52bef7d0341561%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2016-01-19 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  charettes
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by charettes):

 * status:  new => assigned
 * owner:  nobody => charettes


--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.f4361a415a5dc9629f9ed12cab1e5ff2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2016-01-19 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by charettes):

 * cc: charettes (added)


Comment:

 I tried to help someone on the user mailing list with
 [https://groups.google.com/d/msg/django-users/xIP7hhp0WqQ/_ld98nL6EgAJ a
 similar issue with time fields].

 I came up with tests that shows that all but `DateField` combinations work
 on PostgreSQL while all combinations fails on `SQLite3`:

 {{{#!python
 from django.db import models


 class DateModel(models.Model):
 start = models.DateField()
 end = models.DateField()


 class TimeModel(models.Model):
 start = models.TimeField()
 end = models.TimeField()


 class DateTimeModel(models.Model):
 start = models.DateTimeField()
 end = models.DateTimeField()
 }}}

 {{{#!python
 import datetime

 from django.db.models import DurationField, ExpressionWrapper, F
 from django.test import TestCase
 from pytz import UTC

 from . import models


 class DurationTests(TestCase):
 @classmethod
 def setUpTestData(cls):
 models.DateModel.objects.create(
 start=datetime.date(2015, 5, 10),
 end=datetime.date(2015, 5, 12),
 )
 models.TimeModel.objects.create(
 start=datetime.time(10),
 end=datetime.time(13, 30),
 )
 models.DateTimeModel.objects.create(
 start=datetime.datetime(2015, 5, 10, 10, 00, tzinfo=UTC),
 end=datetime.datetime(2015, 5, 12, 13, 30, tzinfo=UTC),
 )

 def test_timemodel(self):
 self.assertEqual(
 models.TimeModel.objects.annotate(duration=ExpressionWrapper(
 F('end') - F('start'), output_field=DurationField()
 )).get().duration, datetime.timedelta(hours=3, minutes=30)
 )

 def test_datemodel(self):
 self.assertEqual(
 models.DateModel.objects.annotate(duration=ExpressionWrapper(
 F('end') - F('start'), output_field=DurationField()
 )).get().duration, datetime.timedelta(days=2)
 )

 def test_datetimemodel(self):
 self.assertEqual(
 models.DateTimeModel.objects.annotate(duration=ExpressionWrapper(
 F('end') - F('start'), output_field=DurationField()
 )).get().duration, datetime.timedelta(days=2, hours=3,
 minutes=30)
 )
 }}}

 PostgreSQL failure:
 {{{
 ==
 FAIL: test_datemodel (duration_expression.tests.DurationTests)
 --
 Traceback (most recent call last):
   File "/home/simon/workspace/ticketing/duration_expression/tests.py",
 line 40, in test_datemodel
 )).get().duration, timedelta(days=2)
 AssertionError: 2 != datetime.timedelta(2)

 --
 }}}

 SQLite3 failures:
 {{{
 ==
 FAIL: test_datemodel (duration_expression.tests.DurationTests)
 --
 Traceback (most recent call last):
   File "/home/simon/workspace/ticketing/duration_expression/tests.py",
 line 37, in test_datemodel
 )).get().duration, datetime.timedelta(days=2)
 AssertionError: datetime.timedelta(0) != datetime.timedelta(2)

 ==
 FAIL: test_datetimemodel (duration_expression.tests.DurationTests)
 --
 Traceback (most recent call last):
   File "/home/simon/workspace/ticketing/duration_expression/tests.py",
 line 44, in test_datetimemodel
 )).get().duration, datetime.timedelta(days=2, hours=3, minutes=30)
 AssertionError: datetime.timedelta(0) != datetime.timedelta(2, 12600)

 ==
 FAIL: test_timemodel (duration_expression.tests.DurationTests)
 --
 Traceback (most recent call last):
   File "/home/simon/workspace/ticketing/duration_expression/tests.py",
 line 

Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2015-11-07 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by jarshwah):

 Hi Lego,

 I'm really sorry I've taken so long to get back to you, I'll do better in
 future.

 Where I think you should be looking is
 django.db.models.expression.CombinedExpression.as_sql() method.

 You would put some handling in there to check left and right hand side for
 two dates, and then we'd probably have some backend specific SQL that
 knows how to handle date(+-)date.

 If you look in the as_sql method you'll see how DurationExpressions are
 handled. It's guarded by a feature flag (has_native_duration_field). You
 might want to guard by another feature flag, something like
 "supports_date_arithmetic". You could then create a DateExpression class
 that handles the backend specific way of doing date math.

 Hopefully that's enough information for you to get started. Please hit me
 up if you need some help or clarification.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.19c338adcd4e822c40d00c6b8333ff73%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2015-09-19 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by LegoStormtroopr):

 @jarshwah

 I've got a work around that I think works for SQLite using SQLites native
 `julianday` function, and am keen to progress this as an actual solution,
 but the code is a little dense for me.

 Would you be able to point me in the direction of where the subtract
 expressions are handled?

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.00e2db709d986fa071895b84bf05d6de%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #24793: Subtracting DateTime fields in a query expression should use timediff

2015-05-12 Thread Django
#24793: Subtracting DateTime fields in a query expression should use timediff
-+-
 Reporter:  sparkyb  |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  datetime duration| Triage Stage:  Accepted
  expression |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by jarshwah):

 * cc: josh.smeaton@… (added)
 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0
 * type:  Uncategorized => New feature
 * stage:  Unreviewed => Accepted


Comment:

 Backends that don't have native duration types (mysql and sqlite) do not
 have support for `date - date` annotations. This is guarded by the
 `has_native_duration_field` flag in tests.

 You can implement your own expression that uses timediff though:

 {{{

 class TimeDiff(Func):
 function = 'timediff'
 output_field = TimeField()
 # you could also implement __init__ to enforce only two date fields

 Event.objects.annotate(duration=TimeDiff('end_time', 'start_time')

 }}}

 Note that I've made the output_field a TimeField rather than a
 DurationField. MySQL returns Time as the result of `date-date`, not a
 duration/interval.

 Considering that adding/subtracting dates is relatively common, I wouldn't
 mind seeing better support for mysql and sqlite if it's possible. So, I'm
 accepting on that basis. If someone is able to provide a patch that makes
 `F('date') - F('otherdate')` work consistently on all backends, then we'd
 probably accept that.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.b4cfabef4e1f631316c64ab482d81603%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.