changeset 13359:10bc9c3abe6e

643 date -R support would be helpful Reviewed by: Jason King <jason.brian.king@gmail.com> Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Reviewed by: Kartik Mistry <kartik@nexenta.com> Reviewed by: Rich Lowe <richlowe@richlowe.net> Approved by: Gordon Ross <gwr@nexenta.com>
author Garrett D'Amore <garrett@nexenta.com>
date Mon, 02 May 2011 11:46:10 -0700
parents f7ba8ec46a21
children c28d415b5009
files usr/src/cmd/date/date.c usr/src/man/man1/date.1
diffstat 2 files changed, 37 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/date/date.c	Thu Apr 28 12:40:06 2011 -0500
+++ b/usr/src/cmd/date/date.c	Mon May 02 11:46:10 2011 -0700
@@ -23,6 +23,9 @@
  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/*
+ * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
+ */
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
@@ -37,8 +40,6 @@
  * contributors.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  *	date - with format capabilities and international flair
  */
@@ -70,6 +71,7 @@
 	"usage:\tdate [-u] mmddHHMM[[cc]yy][.SS]\n\tdate [-u] [+format]\n"
 	"\tdate -a [-]sss[.fff]\n";
 static int uflag = 0;
+static int Rflag = 0;
 
 static int get_adj(char *, struct timeval *);
 static int setdate(struct tm *, char *);
@@ -89,20 +91,23 @@
 #endif
 	(void) textdomain(TEXT_DOMAIN);
 
-	while ((c = getopt(argc, argv, "a:u")) != EOF)
+	while ((c = getopt(argc, argv, "a:uR")) != EOF)
 		switch (c) {
 		case 'a':
 			aflag++;
 			if (get_adj(optarg, &tv) < 0) {
 				(void) fprintf(stderr,
 				    gettext("date: invalid argument -- %s\n"),
-						optarg);
+				    optarg);
 				illflag++;
 			}
 			break;
 		case 'u':
 			uflag++;
 			break;
+		case 'R':
+			Rflag++;
+			break;
 		default:
 			illflag++;
 		}
@@ -110,9 +115,11 @@
 	argc -= optind;
 	argv  = &argv[optind];
 
-	/* -u and -a are mutually exclusive */
+	/* -a is mutually exclusive with -u and -R */
 	if (uflag && aflag)
 		illflag++;
+	if (Rflag && aflag)
+		illflag++;
 
 	if (illflag) {
 		(void) fprintf(stderr, gettext(usage));
@@ -139,6 +146,8 @@
 			}
 			fmt = nl_langinfo(_DATE_FMT);
 		}
+	} else if (Rflag) {
+		fmt = "%a, %d %h %Y %H:%M:%S %z";
 	} else
 		fmt = nl_langinfo(_DATE_FMT);
 
@@ -244,7 +253,7 @@
 			dd_check++;
 	}
 	if (!((mm >= 1 && mm <= 12) && (dd >= 1 && dd <= dd_check) &&
-		(hh >= 0 && hh <= 23) && (min >= 0 && min <= 59))) {
+	    (hh >= 0 && hh <= 23) && (min >= 0 && min <= 59))) {
 		(void) fprintf(stderr, gettext("date: bad conversion\n"));
 		return (1);
 	}
--- a/usr/src/man/man1/date.1	Thu Apr 28 12:40:06 2011 -0500
+++ b/usr/src/man/man1/date.1	Mon May 02 11:46:10 2011 -0700
@@ -1,4 +1,5 @@
 '\" te
+.\" Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
 .\" Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved
 .\" Copyright 1989 AT&T
 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
@@ -9,13 +10,13 @@
 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH date 1 "11 May 2004" "SunOS 5.11" "User Commands"
+.TH date 1 "1 May 2011" "SunOS 5.11" "User Commands"
 .SH NAME
 date \- write the date and time
 .SH SYNOPSIS
 .LP
 .nf
-\fB/usr/bin/date\fR [\fB-u\fR] [+\fIformat\fR]
+\fB/usr/bin/date\fR [\fB-u\fR] [\fB-R\fR] [+\fIformat\fR]
 .fi
 
 .LP
@@ -30,7 +31,7 @@
 
 .LP
 .nf
-\fB/usr/xpg4/bin/date\fR [\fB-u\fR] [+\fIformat\fR]
+\fB/usr/xpg4/bin/date\fR [\fB-u\fR] [\fB-R\fR] [+\fIformat\fR]
 .fi
 
 .LP
@@ -107,6 +108,24 @@
 bypassing the normal conversion to (or from) local time.
 .RE
 
+.sp
+.ne 2
+.mk
+.na
+\fB-R\fR
+.ad
+.RS 24n
+.rt  
+Change the default format to the format used for mail message headers
+(similar to RFC 822 format).  The default format becomes
+.sp
+.in +2
+.nf
+\fI%a, %d %h %Y %H:%M:%S %z\fR
+.fi
+.in -2
+.RE
+
 .SH OPERANDS
 .sp
 .LP