aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c108
1 files changed, 62 insertions, 46 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 3c14d6210a5..0ba19e3ed01 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -787,46 +787,54 @@ lisp_time_argument (specified_time, result)
787 } 787 }
788} 788}
789 789
790DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 2, 0, 790DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
791 "Use FORMAT-STRING to format the time TIME.\n\ 791 "Use FORMAT-STRING to format the time TIME, or now if omitted.\n\
792TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from\n\ 792TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as returned by\n\
793`current-time' and `file-attributes'.\n\ 793`current-time' or `file-attributes'.\n\
794FORMAT-STRING may contain %-sequences to substitute parts of the time.\n\ 794The third, optional, argument UNIVERSAL, if non-nil, means describe TIME\n\
795%a is replaced by the abbreviated name of the day of week.\n\ 795as Universal Time; nil means describe TIME in the local time zone.\n\
796%A is replaced by the full name of the day of week.\n\ 796The value is a copy of FORMAT-STRING, but with certain constructs replaced\n\
797%b is replaced by the abbreviated name of the month.\n\ 797by text that describes the specified date and time in TIME:\n\
798%B is replaced by the full name of the month.\n\
799%c stands for the preferred date/time format of the C locale.\n\
800%d is replaced by the day of month, zero-padded.\n\
801%D is a synonym for \"%m/%d/%y\".\n\
802%e is replaced by the day of month, blank-padded.\n\
803%h is a synonym for \"%b\".\n\
804%H is replaced by the hour (00-23).\n\
805%I is replaced by the hour (00-12).\n\
806%j is replaced by the day of the year (001-366).\n\
807%k is replaced by the hour (0-23), blank padded.\n\
808%l is replaced by the hour (1-12), blank padded.\n\
809%m is replaced by the month (01-12).\n\
810%M is replaced by the minute (00-59).\n\
811%n is a synonym for \"\\n\".\n\
812%p is replaced by AM or PM, as appropriate.\n\
813%r is a synonym for \"%I:%M:%S %p\".\n\
814%R is a synonym for \"%H:%M\".\n\
815%S is replaced by the second (00-60).\n\
816%t is a synonym for \"\\t\".\n\
817%T is a synonym for \"%H:%M:%S\".\n\
818%U is replaced by the week of the year (00-53), first day of week is Sunday.\n\
819%w is replaced by the day of week (0-6), Sunday is day 0.\n\
820%W is replaced by the week of the year (00-53), first day of week is Monday.\n\
821%x is a locale-specific synonym, which defaults to \"%D\" in the C locale.\n\
822%X is a locale-specific synonym, which defaults to \"%T\" in the C locale.\n\
823%y is replaced by the year without century (00-99).\n\
824%Y is replaced by the year with century.\n\
825%Z is replaced by the time zone abbreviation.\n\
826\n\ 798\n\
827The number of options reflects the `strftime' function.") 799%Y is the year, %y within the century, %C the century.\n\
828 (format_string, time) 800%G is the year corresponding to the ISO week, %g within the century.\n\
829 Lisp_Object format_string, time; 801%m is the numeric month, %b and %h the abbreviated name, %B the full name.\n\
802%d is the day of the month, zero-padded, %e is blank-padded.\n\
803%u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6.\n\
804%a is the abbreviated name of the day of week, %A the full name.\n\
805%U is the week number starting on Sunday, %W starting on Monday,\n\
806 %V according to ISO 8601.\n\
807%j is the day of the year.\n\
808\n\
809%H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H\n\
810 only blank-padded, %l is like %I blank-padded.\n\
811%p is AM or PM.\n\
812%M is the minute.\n\
813%S is the second.\n\
814%Z is the time zone name, %z is the numeric form.\n\
815%s is the number of seconds since 1970-01-01 00:00:00 +0000.\n\
816\n\
817%c is the locale's date and time format.\n\
818%x is the locale's \"preferred\" date format.\n\
819%D is like \"%m/%d/%y\".\n\
820\n\
821%R is like \"%H:%M\", %T is like \"%H:%M:%S\", %r is like \"%I:%M:%S %p\".\n\
822%X is the locale's \"preferred\" time format.\n\
823\n\
824Finally, %n is like \n, %t is like \t, %% is a literal %.\n\
825\n\
826Certain flags and modifiers are available with some format controls.
827The flags are `_' and `-'. For certain characters X, %_X is like %X,\n\
828but padded with blanks; %-X is like %X, but without padding.\n\
829%NX (where N stands for an integer) is like %X,\n\
830but takes up at least N (a number) positions.\n\
831The modifiers are `E' and `O'. For certain characters X,\n\
832%EX is a locale's alternative version of %X;\n\
833%OX is like %X, but uses the locale's number symbols.\n\
834\n\
835For example, to produce full ISO 8601 format, use \"%Y-%m-%dT%T%z\".")
836 (format_string, time, universal)
837 Lisp_Object format_string, time, universal;
830{ 838{
831 time_t value; 839 time_t value;
832 int size; 840 int size;
@@ -841,14 +849,22 @@ The number of options reflects the `strftime' function.")
841 849
842 while (1) 850 while (1)
843 { 851 {
844 char *buf = (char *) alloca (size); 852 char *buf = (char *) alloca (size + 1);
845 *buf = 1; 853 int result;
846 if (emacs_strftime (buf, size, XSTRING (format_string)->data, 854
847 localtime (&value)) 855 result = emacs_strftime (buf, size, XSTRING (format_string)->data,
848 || !*buf) 856 (NILP (universal) ? localtime (&value)
857 : gmtime (&value)));
858 if (result > 0 && result < size)
849 return build_string (buf); 859 return build_string (buf);
850 /* If buffer was too small, make it bigger. */ 860 if (result < 0)
851 size *= 2; 861 error ("Invalid time format specification");
862
863 /* If buffer was too small, make it bigger and try again. */
864 result = emacs_strftime (buf, 0, XSTRING (format_string)->data,
865 (NILP (universal) ? localtime (&value)
866 : gmtime (&value)));
867 size = result + 1;
852 } 868 }
853} 869}
854 870