Bug in Date.diff

Tuesday, 5 October 2010 · 4 messages · last reply 6 Oct 2010
CG
Christian Grünin reply to Dave Glick, 6 Oct 2010, 00:165 Oct 2010 22:35 #
Thanks, Dave, for the patch! We'll fix the code snippet with the commit. Do you have a query that helps us to reproduce the bug? Christian
Quoted text · Dave Glick · 56 lines
On Tue, Oct 5, 2010 at 10:18 PM, Dave Glick <dglick at dracorp.com> wrote: > I think there might be a bug in Date.diff – it looks like if the number of > days are the same, it attempts to directly cast the incoming Item to a Date > in order to compare seconds. However, if the incoming Item is actually a > string or something else a cast failure will occur. My fix is below: > > > > Old code: > > @Override > > public int diff(final InputInfo ii, final Item it) throws QueryException { > > final long d1 = days(); > > final Date d = (Date) (it.date() ? it : type.e(it, null, ii)); > > final long d2 = d.days(); > > if(d1 != d2) return (int) (d1 - d2); > > return seconds().subtract(((Date) it).seconds()).signum(); > > } > > > > New code: > > @Override > > public int diff(final InputInfo ii, final Item it) throws QueryException { > > final long d1 = days(); > > final Date d = (Date) (it.date() ? it : type.e(it, null, ii)); > > final long d2 = d.days(); > > if(d1 != d2) return (int) (d1 - d2); > > return seconds().subtract(d.seconds()).signum(); > > } > > > > Dave > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
DG
Dave Glick6 Oct 2010 00:16 #
I think there might be a bug in Date.diff - it looks like if the number of days are the same, it attempts to directly cast the incoming Item to a Date in order to compare seconds. However, if the incoming Item is actually a string or something else a cast failure will occur. My fix is below: Old code:
  @Override
  public int diff(final InputInfo ii, final Item it) throws QueryException {
    final long d1 = days();
    final Date d = (Date) (it.date() ? it : type.e(it, null, ii));
    final long d2 = d.days();
    if(d1 != d2) return (int) (d1 - d2);
    return seconds().subtract(((Date) it).seconds()).signum();
  }
New code:
  @Override
  public int diff(final InputInfo ii, final Item it) throws QueryException {
    final long d1 = days();
    final Date d = (Date) (it.date() ? it : type.e(it, null, ii));
    final long d2 = d.days();
    if(d1 != d2) return (int) (d1 - d2);
    return seconds().subtract(d.seconds()).signum();
  }
Dave
LW
Leonard Wörtelerin reply to Dave Glick, 6 Oct 2010, 01:086 Oct 2010 00:53 #
Hi all,
Quoted text · Dave Glick · 2 lines
Am 05.10.2010 22:35, schrieb Christian Grün: > Do you have a query that helps us to reproduce the bug?
try this one:
Quoted text · Dave Glick · 2 lines
> let $today := <date>2010-10-06</date> > return xs:date($today) = $today
Cheers Leo
DG
Dave Glickin reply to Christian Grün, 5 Oct 2010, 22:356 Oct 2010 01:08 #
Unfortunately not. The problem showed up in some complex queries driven by code. I didn't create a test case in the BaseX GUI, but I don't think it'll be too hard. I should be able to work one up if it would help. I did test the fix below with our situation and it appears to have resolved the issue. Dave
Quoted text · Christian Grün · 65 lines
-----Original Message----- From: Christian Grün [mailto:christian.gruen at gmail.com] Sent: Tuesday, October 05, 2010 4:36 PM To: Dave Glick Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Bug in Date.diff Thanks, Dave, for the patch! We'll fix the code snippet with the commit. Do you have a query that helps us to reproduce the bug? Christian On Tue, Oct 5, 2010 at 10:18 PM, Dave Glick <dglick at dracorp.com> wrote: > I think there might be a bug in Date.diff - it looks like if the number of > days are the same, it attempts to directly cast the incoming Item to a Date > in order to compare seconds. However, if the incoming Item is actually a > string or something else a cast failure will occur. My fix is below: > > > > Old code: > > @Override > > public int diff(final InputInfo ii, final Item it) throws QueryException { > > final long d1 = days(); > > final Date d = (Date) (it.date() ? it : type.e(it, null, ii)); > > final long d2 = d.days(); > > if(d1 != d2) return (int) (d1 - d2); > > return seconds().subtract(((Date) it).seconds()).signum(); > > } > > > > New code: > > @Override > > public int diff(final InputInfo ii, final Item it) throws QueryException { > > final long d1 = days(); > > final Date d = (Date) (it.date() ? it : type.e(it, null, ii)); > > final long d2 = d.days(); > > if(d1 != d2) return (int) (d1 - d2); > > return seconds().subtract(d.seconds()).signum(); > > } > > > > Dave > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >

⚡Generated with XQuery