From owner-svn-src-all@FreeBSD.ORG Sat May 3 14:04:05 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2006EDBA; Sat, 3 May 2014 14:04:05 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0BF1A1083; Sat, 3 May 2014 14:04:05 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s43E44NR084430; Sat, 3 May 2014 14:04:04 GMT (envelope-from dumbbell@svn.freebsd.org) Received: (from dumbbell@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s43E44uY084428; Sat, 3 May 2014 14:04:04 GMT (envelope-from dumbbell@svn.freebsd.org) Message-Id: <201405031404.s43E44uY084428@svn.freebsd.org> From: Jean-Sebastien Pedron Date: Sat, 3 May 2014 14:04:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r265266 - stable/9/bin/date X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 May 2014 14:04:05 -0000 Author: dumbbell Date: Sat May 3 14:04:04 2014 New Revision: 265266 URL: http://svnweb.freebsd.org/changeset/base/265266 Log: date(1): Add "-R" flag to use RFC 2822 date and time output format [MFC] As stated in the man page, this is equivalent to use "%a, %d %b %Y %T %z" as the output format while LC_TIME is set to the "C" locale. This is compatible with date(1) from the GNU core utilities. This is an MFC of r264968 and r264970. Modified: stable/9/bin/date/date.1 stable/9/bin/date/date.c Directory Properties: stable/9/bin/date/ (props changed) Modified: stable/9/bin/date/date.1 ============================================================================== --- stable/9/bin/date/date.1 Sat May 3 13:19:11 2014 (r265265) +++ stable/9/bin/date/date.1 Sat May 3 14:04:04 2014 (r265266) @@ -32,7 +32,7 @@ .\" @(#)date.1 8.3 (Berkeley) 4/28/95 .\" $FreeBSD$ .\" -.Dd June 3, 2010 +.Dd April 26, 2014 .Dt DATE 1 .Os .Sh NAME @@ -40,7 +40,7 @@ .Nd display or set date and time .Sh SYNOPSIS .Nm -.Op Fl ju +.Op Fl jRu .Op Fl r Ar seconds .Oo .Fl v @@ -58,7 +58,7 @@ .Ar MM Op Ar .ss .Sm on .Nm -.Op Fl jnu +.Op Fl jnRu .Fl f Ar input_fmt new_date .Op Cm + Ns Ar output_fmt .Nm @@ -130,6 +130,16 @@ The .Fl n option suppresses this behavior and causes the time to be set only on the current machine. +.It Fl R +Use RFC 2822 date and time output format. This is equivalent to use +.Dq Li %a, %d %b %Y \&%T %z +as +.Ar output_fmt +while +.Ev LC_TIME +is set to the +.Dq C +locale . .It Fl r Ar seconds Print the date and time represented by .Ar seconds , Modified: stable/9/bin/date/date.c ============================================================================== --- stable/9/bin/date/date.c Sat May 3 13:19:11 2014 (r265265) +++ stable/9/bin/date/date.c Sat May 3 14:04:04 2014 (r265266) @@ -69,12 +69,14 @@ static void setthetime(const char *, con static void badformat(void); static void usage(void); +static const char *rfc2822_format = "%a, %d %b %Y %T %z"; + int main(int argc, char *argv[]) { struct timezone tz; int ch, rflag; - int jflag, nflag; + int jflag, nflag, Rflag; const char *format; char buf[1024]; char *endptr, *fmt; @@ -89,9 +91,9 @@ main(int argc, char *argv[]) (void) setlocale(LC_TIME, ""); tz.tz_dsttime = tz.tz_minuteswest = 0; rflag = 0; - jflag = nflag = 0; + jflag = nflag = Rflag = 0; set_timezone = 0; - while ((ch = getopt(argc, argv, "d:f:jnr:t:uv:")) != -1) + while ((ch = getopt(argc, argv, "d:f:jnRr:t:uv:")) != -1) switch((char)ch) { case 'd': /* daylight savings time */ tz.tz_dsttime = strtol(optarg, &endptr, 10) ? 1 : 0; @@ -108,6 +110,9 @@ main(int argc, char *argv[]) case 'n': /* don't set network */ nflag = 1; break; + case 'R': /* RFC 2822 datetime format */ + Rflag = 1; + break; case 'r': /* user specified seconds */ rflag = 1; tval = strtoq(optarg, &tmp, 0); @@ -145,6 +150,9 @@ main(int argc, char *argv[]) format = "%+"; + if (Rflag) + format = rfc2822_format; + /* allow the operands in any order */ if (*argv && **argv == '+') { format = *argv + 1; @@ -169,6 +177,14 @@ main(int argc, char *argv[]) usage(); } vary_destroy(v); + + if (format == rfc2822_format) + /* + * When using RFC 2822 datetime format, don't honor the + * locale. + */ + setlocale(LC_TIME, "C"); + (void)strftime(buf, sizeof(buf), format, <); (void)printf("%s\n", buf); if (fflush(stdout)) @@ -301,7 +317,7 @@ static void usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: date [-jnu] [-d dst] [-r seconds] [-t west] " + "usage: date [-jnRu] [-d dst] [-r seconds] [-t west] " "[-v[+|-]val[ymwdHMS]] ... ", " " "[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]");