bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] date: Add `seconds since midnight' and `day of year (000..365)'


From: Shaun Jackman
Subject: [PATCH] date: Add `seconds since midnight' and `day of year (000..365)'
Date: Mon, 10 Jul 2006 10:22:09 -0600

This patch adds two useful formats to date:

        %i -- seconds since midnight
        %J -- day of year (000..365)

These formats are useful in constructing a time format which is
zero-based and includes a minimum number of arbitrary bases, such as
%Y-%J-%i.%N.

Cheers,
Shaun

2006-07-10  Shaun Jackman  <address@hidden>

        * lib/strftime.c (strftime_case_): Add %i -- seconds since midnight.
        Add %J -- day of year (000..365).
        * src/date.c (usage): Ditto.

diff -ur coreutils-5.96.orig/lib/strftime.c coreutils-5.96/lib/strftime.c
--- coreutils-5.96.orig/lib/strftime.c  2006-05-20 13:44:59.000000000 -0600
+++ coreutils-5.96/lib/strftime.c       2006-07-10 09:55:16.000000000 -0600
@@ -1061,6 +1061,12 @@

          DO_NUMBER (2, tp->tm_hour);

+       case L_('i'):
+         if (modifier == L_('E'))
+           goto bad_format;
+
+         DO_NUMBER (5, 60 * (60 * tp->tm_hour + tp->tm_min) + tp->tm_sec);
+
        case L_('I'):
          if (modifier == L_('E'))
            goto bad_format;
@@ -1085,6 +1091,12 @@

          DO_SIGNED_NUMBER (3, tp->tm_yday < -1, tp->tm_yday + 1U);

+       case L_('J'):
+         if (modifier == L_('E'))
+           goto bad_format;
+
+         DO_SIGNED_NUMBER (3, tp->tm_yday < -1, tp->tm_yday);
+
        case L_('M'):
          if (modifier == L_('E'))
            goto bad_format;
diff -ur coreutils-5.96.orig/src/date.c coreutils-5.96/src/date.c
--- coreutils-5.96.orig/src/date.c      2006-07-10 09:44:36.000000000 -0600
+++ coreutils-5.96/src/date.c   2006-07-10 09:53:02.000000000 -0600
@@ -179,8 +179,10 @@
      fputs (_("\
  %h   same as %b\n\
  %H   hour (00..23)\n\
+  %i   seconds since midnight\n\
  %I   hour (01..12)\n\
  %j   day of year (001..366)\n\
+  %J   day of year (000..365)\n\
 "), stdout);
      fputs (_("\
  %k   hour ( 0..23)\n\

Attachment: date-seconds.diff
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]