aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-09-27 19:41:21 +0000
committerRichard M. Stallman1994-09-27 19:41:21 +0000
commita82d387cfdb7b877841e28d62d7bba3463575581 (patch)
tree301570e5241ac262fed294452e01d851ecd8ddd5 /src
parent1825bea1065695ac80c959823698d2feb3d4e782 (diff)
downloademacs-a82d387cfdb7b877841e28d62d7bba3463575581.tar.gz
emacs-a82d387cfdb7b877841e28d62d7bba3463575581.zip
(Fformat_time_string): Mostly rewritten, to handle
unlimited size, and report errors properly. (Fformat_time_string): New function. (syms_of_editfns): Defsubr it.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 94c43ea1abe..d06b7607c41 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -589,6 +589,70 @@ lisp_time_argument (specified_time, result)
589 } 589 }
590} 590}
591 591
592DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 2, 2, 0,
593 "Use FORMAT-STRING to format the time TIME.\n\
594TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from\n\
595`current-time' and `file-attributes'.\n\
596FORMAT-STRING may contain %-sequences to substitute parts of the time.\n\
597%a is replaced by the abbreviated name of the day of week.\n\
598%A is replaced by the full name of the day of week.\n\
599%b is replaced by the abbreviated name of the month.\n\
600%B is replaced by the full name of the month.\n\
601%c is a synonym for \"%x %X\".\n\
602%C is a locale-specific synonym, which defaults to \"%A, %B %e, %Y\" in the C locale.\n\
603%d is replaced by the day of month, zero-padded.\n\
604%D is a synonym for \"%m/%d/%y\".\n\
605%e is replaced by the day of month, blank-padded.\n\
606%h is a synonym for \"%b\".\n\
607%H is replaced by the hour (00-23).\n\
608%I is replaced by the hour (00-12).\n\
609%j is replaced by the day of the year (001-366).\n\
610%k is replaced by the hour (0-23), blank padded.\n\
611%l is replaced by the hour (1-12), blank padded.\n\
612%m is replaced by the month (01-12).\n\
613%M is replaced by the minut (00-59).\n\
614%n is a synonym for \"\\n\".\n\
615%p is replaced by AM or PM, as appropriate.\n\
616%r is a synonym for \"%I:%M:%S %p\".\n\
617%R is a synonym for \"%H:%M\".\n\
618%S is replaced by the seconds (00-60).\n\
619%t is a synonym for \"\\t\".\n\
620%T is a synonym for \"%H:%M:%S\".\n\
621%U is replaced by the week of the year (01-52), first day of week is Sunday.\n\
622%w is replaced by the day of week (0-6), Sunday is day 0.\n\
623%W is replaced by the week of the year (01-52), first day of week is Monday.\n\
624%x is a locale-specific synonym, which defaults to \"%D\" in the C locale.\n\
625%X is a locale-specific synonym, which defaults to \"%T\" in the C locale.\n\
626%y is replaced by the year without century (00-99).\n\
627%Y is replaced by the year with century.\n\
628%Z is replaced by the time zone abbreviation.\n\
629\n\
630The number of options reflects the strftime(3) function.")
631 (format_string, time)
632 Lisp_Object format_string, time;
633{
634 time_t value;
635 int size;
636
637 CHECK_STRING (format_string, 1);
638
639 if (! lisp_time_argument (time, &value))
640 error ("Invalid time specification");
641
642 /* This is probably enough. */
643 size = XSTRING (format_string)->size * 6 + 50;
644
645 while (1)
646 {
647 char *buf = (char *) alloca (size);
648 if (strftime (buf, size, XSTRING (format_string)->data,
649 localtime (&value)))
650 return build_string (buf);
651 /* If buffer was too small, make it bigger. */
652 size *= 2;
653 }
654}
655
592DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0, 656DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0,
593 "Return the current time, as a human-readable string.\n\ 657 "Return the current time, as a human-readable string.\n\
594Programs can use this function to decode a time,\n\ 658Programs can use this function to decode a time,\n\
@@ -2090,6 +2154,7 @@ syms_of_editfns ()
2090 defsubr (&Suser_full_name); 2154 defsubr (&Suser_full_name);
2091 defsubr (&Semacs_pid); 2155 defsubr (&Semacs_pid);
2092 defsubr (&Scurrent_time); 2156 defsubr (&Scurrent_time);
2157 defsubr (&Sformat_time_string);
2093 defsubr (&Scurrent_time_string); 2158 defsubr (&Scurrent_time_string);
2094 defsubr (&Scurrent_time_zone); 2159 defsubr (&Scurrent_time_zone);
2095 defsubr (&Ssystem_name); 2160 defsubr (&Ssystem_name);