Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0000047 [1003.1(2008)/Issue 7] Shell and Utilities Objection Enhancement Request 2009-06-25 12:05 2011-06-30 17:37
Reporter eblake View Status public  
Assigned To ajosey
Priority normal Resolution Duplicate  
Status Closed  
Name Eric Blake
Organization BYU
User Reference
Section date
Page Number 2575
Line Number 82893
Interp Status ---
Final Accepted Text
Summary 0000047: Missing specifiers for date utility
Description Although the date utility provides an interface similar to the
strftime function, there are several things specified only for the
latter (some with CX shading), which would be useful from a command
line interface. These include: missing specifiers, addition of flags,
addition of minimum field width.

This aardvark only addresses missing specifiers. An alternative
solution might be to couch the entire discussion of the format
argument of the date utility in terms of a call to strftime, so that
the next time the strftime interface is extended, the date utility
implicitly picks up that extension; this would also pick up the '0'
and '+' flags as well as minimum field width.
Desired Action At line 82893, insert:
%F Date in the format %Y-%m-%d

%g The last 2 digits of the week-based year (see %V) as a decimal
    number [00,99].

%G The week-based year (see %V) as a decimal number (for example,
    1977).

At line 82903, insert:
%R Time in the format %H:%M.

At line 82922, insert:
%z The offset from UTC in the ISO 8601:2000 standard format (+hhmm or
    -hhmm), or by no characters if no timezone is determinable. For
    example, "-0430" means 4 hours 30 minutes behind UTC (west of
    Greenwich).
Tags No tags attached.
Attached Files

- Relationships
duplicate of 0000466Appliedajosey date +%C problem 
related to 0000169Appliedajosey date utility needs ``%s'' 

-  Notes
(0000084)
Don Cragun (manager)
2009-06-25 12:13
edited on: 2009-06-26 06:34

Originally reported by ebb9:xxxxxxx
Fri, 9 Jan 2009 21:00:38 GMT
with Subject: Defect in XCU date

Transcribed by Don Cragun from xcubug3.txt ERN 3

Submitter tag "ebb.date"

(0000085)
Don Cragun (manager)
2009-06-25 12:14

This is an enhancement, and should be added SD5, items for consideration
for the next revision.

It should be noted that the proposed action does not address all the
issues raised in the problem specifications.
(0000114)
wpollock (reporter)
2009-06-26 12:04

I thought you had agreed to add "%s" to this aardvark? Please consider re-opening this, and add:

%s The number of seconds since the Epoch, i.e., since 1970-01-01
       00:00:00 UTC. (TZ)
(0000117)
Don Cragun (manager)
2009-06-26 12:27

The request we were given was to add missing specifiers from strftime()
and strptime() to the list of specifiers supported by the date utility.
The %s specifier is not in strftime() or strptime() in the standard.
(0000172)
wpollock (reporter)
2009-08-06 00:40

Opps, I must have accidentally checked my logal (Gnu) man page for strftime rather than the standard, sorry! However I can't help but feel this is a serious omission.

Currently the only way is to use the time function from <time.h>, but that isn't useful for shell scripting! I currently use code like this:

TIME=$(awk 'BEGIN { srand(); print srand(); }')

which works on all systems I've tried it on. But a careful reading of SUSv4 says this for the AWK srand function:
"srand([expr])
    Set the seed value for rand to expr or use the time of day if expr is
    omitted. The previous seed value shall be returned."

However this isn't guaranteed to be the "the value of time in seconds since the Epoch", as defined by time(). Therefore the only way is to caclulate this manually using the POSIX formula. A pure shell script had an overflow when I tried, so I ended up with this script using bc:

SEC=$(date +%S)
MIN=$(date +%M)
HOUR=$(date +%H) # 24 hour format
YDAY=$(date +%j) # Day of year (num of days since last December 31)
YEAR=$(date +%Y) # 4 digit year
YEAR=$(( YEAR - 1900 ))

SECONDS_SINCE_EPOCH=$(
bc <<END
scale = 0
$SEC + 60 * $MIN + $YDAY * 86400 + \
 ($YEAR-70)*31536000 + (($YEAR-69)/4) * 86400 - \
 (($YEAR-1)/100)*86400 + (($YEAR+299)/400)*86400
END
)

printf '%s\n' "$SECONDS_SINCE_EPOCH"

This is so ugly! Please, pretty please, consider adding '%s' to date?
You could add it to strftime as well, for consistency sake! This is often requested functionality for non Gnu users.
(0000872)
Don Cragun (manager)
2011-06-30 16:26

The suggested fix was originally accepted, but has been replaced by changes made in response to bug 0000466.

- Issue History
Date Modified Username Field Change
2009-06-25 12:05 Don Cragun New Issue
2009-06-25 12:05 Don Cragun Status New => Under Review
2009-06-25 12:05 Don Cragun Assigned To => ajosey
2009-06-25 12:05 Don Cragun Name => Eric Blake
2009-06-25 12:05 Don Cragun Organization => BYU
2009-06-25 12:05 Don Cragun Section => date
2009-06-25 12:05 Don Cragun Page Number => 2575
2009-06-25 12:05 Don Cragun Line Number => 82893
2009-06-25 12:13 Don Cragun Note Added: 0000084
2009-06-25 12:13 Don Cragun Status Under Review => Resolved
2009-06-25 12:13 Don Cragun Resolution Open => Accepted
2009-06-25 12:14 Don Cragun Note Added: 0000085
2009-06-25 12:19 Don Cragun Note Edited: 0000084
2009-06-25 16:38 Don Cragun Tag Attached: real bug in aardvark
2009-06-26 06:34 Don Cragun Note Edited: 0000084
2009-06-26 08:11 Don Cragun Final Accepted Text => Desired Action
2009-06-26 08:11 Don Cragun Reporter Don Cragun => eblake
2009-06-26 12:04 wpollock Note Added: 0000114
2009-06-26 12:11 wpollock Issue Monitored: wpollock
2009-06-26 12:27 Don Cragun Note Added: 0000117
2009-07-30 16:05 msbrown Tag Detached: real bug in aardvark
2009-08-06 00:40 wpollock Note Added: 0000172
2009-10-15 15:46 wpollock Issue End Monitor: wpollock
2010-09-09 15:35 Don Cragun Interp Status => ---
2010-09-09 15:35 Don Cragun Resolution Accepted => Future Enhancement
2010-09-09 15:35 Don Cragun Tag Attached: issue8
2011-06-24 21:00 eblake Relationship added related to 0000169
2011-06-24 21:13 eblake Relationship added related to 0000466
2011-06-30 16:26 Don Cragun Final Accepted Text Desired Action =>
2011-06-30 16:26 Don Cragun Note Added: 0000872
2011-06-30 16:26 Don Cragun Status Resolved => Closed
2011-06-30 16:26 Don Cragun Resolution Future Enhancement => Duplicate
2011-06-30 16:27 Don Cragun Tag Detached: issue8
2011-06-30 17:37 Don Cragun Relationship replaced duplicate of 0000466


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker