#include "sflconv.h"
char *
conv_time_str (
long time,
int flags,
char timesep,
int width)
Synopsis
Converts a time to a string. The flags and width control the
resulting string. You can use one or more of these flags added
together:
FLAG T
HH AS H | Suppress leading zeroes on the
hours. |
FLAG T MM AS M | Suppress leading zeroes on the minutes. |
FLAG T SS AS S | Suppress
leading zeroes on the seconds. |
FLAG T
CC AS C | Suppress leading zeroes on the
centiseconds. |
FLAG T COMPACT | Show without delimiters. |
FLAG T 12 HOUR | Append
am/pm indicator. |
Returns a pointer to a static area
holding the string, or NULL if there was an error. If no flags
are used, the width argument gives these results (shown as a
picture, which is how conv_time_str works - see
conv_time_pict): 4 or less | Error. |
5 to 7 | "hh:mm" |
8 to 10 | "hh:mm:ss"
|
11 or more | "hh:mm:ss:cc" |
If FLAG_T_COMPACT is used,
width gives these results: 3 or less | Error. |
4 to 5 | "hhmm" |
6 to 7 | "hhmmss" |
8 or more | "hhmmsscc"
|
If FLAG_T_12_HOUR is used, width gives these results:
5 or less
| Error. |
6 to 8 | "hh:mma" |
9 to 11 | "hh:mm:ssa" |
12 or more
| "hh:mm:ss:cca" |
If FLAG_T_COMPACT and
FLAG_T_12_HOUR are used, width gives these results: 4 or less | Error. |
5 to 6 | "hhmma" |
7 to 8 | "hhmmssa" |
9 or more
| "hhmmsscca" |
Source Code - (sflcvts.c)
{
char
delim [2], /* Delimiter string, ":" or "" */
picture [13]; /* Largest picture: hh:mm:ss:cca */
int
delim_len;
int
space_left = width;
conv_reason = 0; /* No conversion errors so far */
if (flags & FLAG_T_COMPACT)
{
delim [0] = 0;
delim_len = 0;
}
else
{
delim [0] = timesep;
delim [1] = 0;
delim_len = 1;
}
if (flags & FLAG_T_12_HOUR)
space_left--; /* Subtract 1 if eventual "a" */
/* Build-up date picture components until we run out of space */
strcpy (picture, (flags & FLAG_T_HH_AS_H? "h": "hh"));
space_left -= 2;
if (space_left >= delim_len + 2)
{
strcat (picture, delim);
strcat (picture, (flags & FLAG_T_MM_AS_M? "m": "mm"));
space_left -= delim_len + 2;
}
else
return (NULL); /* Error - space_left is too small */
if (space_left >= delim_len + 2)
{
strcat (picture, delim);
strcat (picture, (flags & FLAG_T_SS_AS_S? "s": "ss"));
space_left -= delim_len + 2;
}
if (space_left >= delim_len + 2)
{
strcat (picture, delim);
strcat (picture, (flags & FLAG_T_CC_AS_C? "c": "cc"));
space_left -= delim_len + 2;
}
/* Append "a" (or "aa" if space) if 12-hour clock wanted */
if (flags & FLAG_T_12_HOUR)
strcat (picture, (space_left == 0? "a": "aa"));
return (conv time pict (time, picture));
}
| << | <
| > | >>
|
Copyright © 1996-2000 iMatix Corporation |