Article View: gnu.emacs.bug
Article #88103[19.25.92] new function: format-time-string
From: Erik Naggum
Date: Wed, 03 Aug 1994 19:28
Date: Wed, 03 Aug 1994 19:28
99 lines
5157 bytes
5157 bytes
In GNU Emacs 19.25.92.1 (sparc-sun-sunos4shr) of Wed Aug 3 1994 on naggum.no
I have been unhappy with the time printing abilities of GNU Emacs for a
while, so I created a new function `format-time-string', which works like
strftime() (because it is strftime() wrapper). this function could help
avoid lots of hairy code that takes the output from current-time-string and
chops it up into small pieces only to glue them together again. the
documentation is complete enough that I use this instead of looking up
strftime.3.
if this is accepted for distribution, many time-related functions can be
greatly simplified. however, not all systems have strftime, but other GNU
utilities include their own strftime, so it should be possible to link them
all together usefully. don't know enough about autoconf and such to know
how to do this. also, since I use gcc exclusively, I don't know whether
cpp will barf on the length of the documentation string. if you like this,
please help make it more portable.
should "invalid format specification" be an error?
best regards,
</Erik>
---------------------------------------------------------------------------
*** src/editfns.c.~1~ Mon Jul 25 21:20:05 1994
--- src/editfns.c Wed Aug 3 03:51:23 1994
***************
*** 589,594 ****
--- 589,648 ----
}
}
+ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 2, 2, 0,
+ "Format the time (1st arg) according to the control-string (2nd arg).\n\
+ The time is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from\n\
+ `current-time' and `file-attributes'.\n\
+ The control string may contain %-sequences to substitute parts of the time.\n\
+ %a is replaced by the abbreviated name of the day of week.\n\
+ %A is replaced by the full name of the day of week.\n\
+ %b is replaced by the abbreviated name of the month.\n\
+ %B is replaced by the full name of the month.\n\
+ %c is a synonym for \"%x %X\".\n\
+ %C is a locale-specific synonym, which defaults to \"%A, %B %e, %Y\" in the C locale.\n\
+ %d is replaced by the day of month, zero-padded.\n\
+ %D is a synonym for \"%m/%d/%y\".\n\
+ %e is replaced by the day of month, blank-padded.\n\
+ %h is a synonym for \"%b\".\n\
+ %H is replaced by the hour (00-23).\n\
+ %I is replaced by the hour (00-12).\n\
+ %j is replaced by the day of the year (001-366).\n\
+ %k is replaced by the hour (0-23), blank padded.\n\
+ %l is replaced by the hour (1-12), blank padded.\n\
+ %m is replaced by the month (01-12).\n\
+ %M is replaced by the minut (00-59).\n\
+ %n is a synonym for \"\\n\".\n\
+ %p is replaced by AM or PM, as appropriate.\n\
+ %r is a synonym for \"%I:%M:%S %p\".\n\
+ %R is a synonym for \"%H:%M\".\n\
+ %S is replaced by the seconds (00-60).\n\
+ %t is a synonym for \"\\t\".\n\
+ %T is a synonym for \"%H:%M:%S\".\n\
+ %U is replaced by the week of the year (01-52), first day of week is Sunday.\n\
+ %w is replaced by the day of week (0-6), Sunday is day 0.\n\
+ %W is replaced by the week of the year (01-52), first day of week is Monday.\n\
+ %x is a locale-specific synonym, which defaults to \"%D\" in the C locale.\n\
+ %X is a locale-specific synonym, which defaults to \"%T\" in the C locale.\n\
+ %y is replaced by the year without century (00-99).\n\
+ %Y is replaced by the year with century.\n\
+ %Z is replaced by the time zone abbreviation.\n\
+ \n\
+ The number of options reflects the strftime(3) function.")
+ (specified_time, format_string)
+ Lisp_Object specified_time, format_string;
+ {
+ time_t value;
+ char buf[256];
+
+ if (! lisp_time_argument (specified_time, &value))
+ return build_string ("Invalid time specification");
+
+ if (STRINGP (format_string) &&
+ (strftime (buf, 255, XSTRING (format_string)->data, localtime (&value))))
+ return build_string (buf);
+ return build_string ("Invalid format specification");
+ }
+
DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0,
"Return the current time, as a human-readable string.\n\
Programs can use this function to decode a time,\n\
***************
*** 1998,2003 ****
--- 2052,2058 ----
defsubr (&Suser_full_name);
defsubr (&Semacs_pid);
defsubr (&Scurrent_time);
+ defsubr (&Sformat_time_string);
defsubr (&Scurrent_time_string);
defsubr (&Scurrent_time_zone);
defsubr (&Ssystem_name);
Technical Details
Message-ID:
<19940803.3949@naggum.no>Path:
arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!uunet!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!naggum.no!erikShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,d6696ef281283df,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1994-08-04 01:40:12 PST Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!uunet!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!naggum.no!erik From: erik@naggum.no (Erik Naggum) Newsgroups: gnu.emacs.bug Subject: [19.25.92] new function: format-time-string Date: 3 Aug 1994 15:28:44 -0400 Organization: Naggum Software; +47 2295 0313 Lines: 100 Sender: daemon@cis.ohio-state.edu Approved: bug-gnu-emacs@prep.ai.mit.edu Distribution: gnu Message-ID: <19940803.3949@naggum.no>