NetBSD Problem Report #47596

From www@NetBSD.org  Mon Feb 25 20:21:40 2013
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id C7A1A63E522
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 25 Feb 2013 20:21:40 +0000 (UTC)
Message-Id: <20130225202139.872E163E522@www.NetBSD.org>
Date: Mon, 25 Feb 2013 20:21:39 +0000 (UTC)
From: dsl@netbsd.org
Reply-To: dsl@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: parsedate() misparses 'last sunday -1 day'
X-Send-Pr-Version: www-1.0

>Number:         47596
>Category:       lib
>Synopsis:       parsedate() misparses 'last sunday -1 day'
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 25 20:25:00 +0000 2013
>Last-Modified:  Tue Feb 26 09:30:05 +0000 2013
>Originator:     David Laight
>Release:        6.0
>Organization:
None
>Environment:
>Description:
The parsedate() code (in libutil/parsedate.y) always processes the 'last sunday' after adjusting the current time for any relative time offsets.

This means that "date -d 'last sunday -5 days" reports the sunday before 5 days ago - not the intended tuesday of last week.

(Discovered when moving a small script from a different OS.)

Workaround:
date -d "@$(date -d 'last sunday' +%s) -5 days"
>How-To-Repeat:

>Fix:
Rewrite the parser so that it modifies the time as it processes the input string (instead of trying to remember the fields and doing the work afterwards).

>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/47596: parsedate() misparses 'last sunday -1 day'
Date: Tue, 26 Feb 2013 09:25:01 +0000

 On Mon, Feb 25, 2013 at 08:25:00PM +0000, dsl@netbsd.org wrote:
  > >Fix:
  > Rewrite the parser so that it modifies the time as it processes the
  > input string (instead of trying to remember the fields and doing
  > the work afterwards).

 That's almost always the wrong way.

 -- 
 David A. Holland
 dholland@netbsd.org

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.