Email List: Xaustin-group-lX
[All Lists]

[1003.1(2008)/Issue 7 0000047]: Missing specifiers for date utility

To: austin-group-l@xxxxxxxxxxxxx
Subject: [1003.1(2008)/Issue 7 0000047]: Missing specifiers for date utility
From: Austin Group Bug Tracker <noreply@xxxxxxxxxxxxx>
Date: Thu, 6 Aug 2009 00:40:59 +0000
Keywords: [1003.1(2008)/Issue 7] Shell and Utilities
A NOTE has been added to this issue. 
====================================================================== 
http://austingroupbugs.net/view.php?id=47 
====================================================================== 
Reported By:                eblake
Assigned To:                ajosey
====================================================================== 
Project:                    1003.1(2008)/Issue 7
Issue ID:                   47
Category:                   Shell and Utilities
Type:                       Enhancement Request
Severity:                   Objection
Priority:                   normal
Status:                     Resolved
Name:                       Eric Blake 
Organization:               BYU 
User Reference:              
Section:                    date 
Page Number:                2575 
Line Number:                82893 
Final Accepted Text:        Desired Action 
Resolution:                 Accepted
Fixed in Version:           
====================================================================== 
Date Submitted:             2009-06-25 12:05 UTC
Last Modified:              2009-08-06 00:40 UTC
====================================================================== 
Summary:                    Missing specifiers for date utility
====================================================================== 

---------------------------------------------------------------------- 
 (0000172) wpollock (reporter) - 2009-08-06 00:40
 http://austingroupbugs.net/view.php?id=47#c172 
---------------------------------------------------------------------- 
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. 

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                          
======================================================================

<Prev in Thread] Current Thread [Next in Thread>