Difference between revisions of "Mu c streamftime"

From Mailutils
Jump to navigationJump to search
Line 1: Line 1:
 
{{DISPLAYTITLE:mu_c_streamftime}}
 
{{DISPLAYTITLE:mu_c_streamftime}}
 +
== mu_c_streamftime ==
 
<syntaxhighlight lang="C">
 
<syntaxhighlight lang="C">
 
int mu_c_streamftime (mu_stream_t str, const char *fmt, struct tm *input_tm,
 
int mu_c_streamftime (mu_stream_t str, const char *fmt, struct tm *input_tm,
Line 5: Line 6:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The function <tt>mu_c_streamftime</tt> formats the broken-down time <tt>tm</tt> with optional [[struct mu_timezone|timezone information]] <tt>tz</tt> according to the format specification <tt>format</tt> and writes the result to the stream <tt>str</tt>.  The function returns 0 on success and error code on error.
+
The function <tt>mu_c_streamftime</tt> formats the broken-down time <tt>tm</tt> with optional [[struct mu_timezone|timezone information]] <tt>tz</tt> according to the format specification <tt>format</tt> and writes the result to the stream <tt>str</tt>.  If no timezone information is available, <tt>tz</tt> should be <tt>NULL</tt>. The function returns 0 on success and error code on error.
  
 
The format string is similar to that of [http://www.manpagez.com/man/3/strftime/ strftime(3)].  The function is designed to format timestamps for protocol exchange and therefore ignores locale settings (which is reflected by <tt>_c_</tt> in its name).  A detailed description of the format string follows.
 
The format string is similar to that of [http://www.manpagez.com/man/3/strftime/ strftime(3)].  The function is designed to format timestamps for protocol exchange and therefore ignores locale settings (which is reflected by <tt>_c_</tt> in its name).  A detailed description of the format string follows.
  
 +
=== Format string ===
 
Ordinary characters placed in the format string are copied to the output stream without conversion.  Conversion specifications are introduced by a <tt>%</tt> character, and terminated by a conversion specifier  character.  They are replaced in s as follows:
 
Ordinary characters placed in the format string are copied to the output stream without conversion.  Conversion specifications are introduced by a <tt>%</tt> character, and terminated by a conversion specifier  character.  They are replaced in s as follows:
  
Line 100: Line 102:
 
A percent sign followed by any character not listed above is written to the output stream verbatim.
 
A percent sign followed by any character not listed above is written to the output stream verbatim.
  
 +
=== Examples ===
 +
 +
<div id="MU_DATETIME_FROM"></div>
 +
* UNIX mailbox from line:
 +
::"%a %b %e %H:%M:%S %Y"
 +
:It is available as <tt>MU_DATETIME_FROM</tt> macro, defined in <tt>mailutils/datetime.h</tt>
 +
<div id="MU_DATETIME_FORM_RFC822"></div>
 +
* RFC-822 date/time format:
 +
::"%a, %e %b %Y %H:%M:%S %z"
 +
:It is available as <tt>MU_DATETIME_FORM_RFC822</tt> macro.
 +
<div id="MU_DATETIME_IMAP"></div>
 +
* IMAP INTERNALDATE format:
 +
::"%d-%b-%Y%$ %H:%M:%S %z"
 +
:It is available as <tt>MU_DATETIME_IMAP</tt> and <tt>MU_DATETIME_INTERNALDATE</tt> macros.
 
== See also ==
 
== See also ==
 
[[mu_strftime]]
 
[[mu_strftime]]

Revision as of 10:45, 17 December 2011

mu_c_streamftime

int mu_c_streamftime (mu_stream_t str, const char *fmt, struct tm *input_tm,
                      struct mu_timezone *tz)

The function mu_c_streamftime formats the broken-down time tm with optional timezone information tz according to the format specification format and writes the result to the stream str. If no timezone information is available, tz should be NULL. The function returns 0 on success and error code on error.

The format string is similar to that of strftime(3). The function is designed to format timestamps for protocol exchange and therefore ignores locale settings (which is reflected by _c_ in its name). A detailed description of the format string follows.

Format string

Ordinary characters placed in the format string are copied to the output stream without conversion. Conversion specifications are introduced by a % character, and terminated by a conversion specifier character. They are replaced in s as follows:

%a
The abbreviated weekday name.
%A
The full weekday name.
%b %h
The abbreviated month name.
%B
The full month name.
%c
Equivalent to "%a %b %e %H:%M:%S %Y".
%C
The century number (year/100) as a 2-digit integer.
%d
The day of the month as a decimal number (range 01 to 31).
%D
Equivalent to "%m/%d/%y".
%e
Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space.
%E
A modifier. Actual conversion specifier must follow, e.g. %Ec. The Single Unix Specification mentions %Ec, %EC, %Ex, %EX, %Ey, and %EY, which are supposed to use a corresponding locale-dependent alternative representation. Since mu_c_streamftime explicitly operates in POSIX locale, this is a no-op.
%F
Equivalent to "%Y-%m-%d" (the ISO 8601 date format).
%G
The ISO 8601 year with century as a decimal number. The 4-digit year corresponding to the ISO week number (see %V below). This has the same format and value as %y, except that if the ISO week number belongs to the previous or next year, that year is used instead.
%g
Like %G, but without century, that is, with a 2-digit year (00-99).
%H
The hour as a decimal number using a 24-hour clock (range 00 to 23).
%I
The hour as a decimal number using a 12-hour clock (range 01 to 12).
%j
The day of the year as a decimal number (range 001 to 366).
%k
The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.
%l
The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.
%m
The month as a decimal number (range 01 to 12).
%M
The minute as a decimal number (range 00 to 59).
%n
A newline character.
%O
A no-op modifier. Actual conversion specifier must follow (The Single Unix Specification mentions %Od, %Oe, %OH, %OI, %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, and %Oy, which are supposed to use alternative numeric symbols).
%p
Either "AM" or "PM" according to the given time value. Noon is treated as "PM" and midnight as "AM".
%P
Like %p but in lowercase: "am" or "pm".
%r
The time in a.m. or p.m. notation, i.e. equivalent to "%I:%M:%S %p".
%R
The time in 24-hour notation: %H:%M
%s
The number of seconds since the Epoch.
%S
The second as a decimal number (range 00 to 60).
%t
A tab character.
%T
The time in 24-hour notation: "%H:%M:%S".
%u
The day of the week as a decimal, range 1 to 7, Monday being 1.
%U
The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01.
%V
The ISO 8601:1988 week number of the current year as a decimal number range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.;%w
The day of the week as a decimal, range 0 to 6, Sunday being 0.
%W
The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01.
%x
The preferred date representation without the time: equivalent to "%D".
%X
The preferred date representation without the date: "%H:%M:%S".
%y
The year as a decimal number without a century (range 00 to 99).
%Y
The year as a decimal number including the century.
%Z
The timezone name or abbreviation, if available. Otherwise equivalent to "%z".
%z
The time-zone as hour offset from GMT.
%%
A literal '%' character.
%$
Ignored for compatibilty with mu_scan_datetime.

A percent sign followed by any character not listed above is written to the output stream verbatim.

Examples

  • UNIX mailbox from line:
"%a %b %e %H:%M:%S %Y"
It is available as MU_DATETIME_FROM macro, defined in mailutils/datetime.h
  • RFC-822 date/time format:
"%a, %e %b %Y %H:%M:%S %z"
It is available as MU_DATETIME_FORM_RFC822 macro.
  • IMAP INTERNALDATE format:
"%d-%b-%Y%$ %H:%M:%S %z"
It is available as MU_DATETIME_IMAP and MU_DATETIME_INTERNALDATE macros.

See also

mu_strftime