/*----------------------------------------------------------------------------*/ char * qfits_get_datetime_iso8601(void) { static char date_iso8601[20]; long curdate; long curtime; curdate = qfits_date_now(); curtime = qfits_time_now(); sprintf(date_iso8601, "%04d-%02d-%02dT%02d:%02d:%02d", GET_CCYEAR(curdate), GET_MONTH(curdate), GET_DAY(curdate), GET_HOUR(curtime), GET_MINUTE(curtime), GET_SECOND(curtime)); return date_iso8601; }
char * conv_date_pict ( long date, const char *picture) { static char *month_name [] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }, *day_name [] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }, formatted [FORMAT_MAX + 1]; /* Formatted return string */ int century, /* Century component of date */ year, /* Year component of date */ month, /* Month component of date */ day, /* Day component of date */ cursize; /* Size of current component */ char *dest, /* Store formatted data here */ ch, /* Next character in picture */ lastch = '0'; /* Last character we output */ long full_date = date; conv_reason = 0; /* No conversion errors so far */ /* Zero date is returned as empty string */ if (date == 0) { strclr (formatted); return (formatted); } default_century (&full_date); century = GET_CENTURY (full_date); year = GET_YEAR (full_date); month = GET_MONTH (full_date); day = GET_DAY (full_date); ASSERT (month > 0 && month <= 12); ASSERT (day > 0 && day <= 31); /* Scan through picture, converting each component */ dest = formatted; *dest = 0; /* string is empty */ while (*picture) { /* Get character and count number of occurences */ ch = *picture++; for (cursize = 1; *picture == ch; cursize++) picture++; switch (ch) { /* cc century 2 digits, 01-99 */ case 'c': if (cursize == 2) sprintf (dest, "%02d", century); break; /* y day of year, 1-366 */ /* yy year 2 digits, 00-99 */ /* yyyy year 4 digits, 0100-9999 */ case 'y': /* y = day of year */ if (cursize == 1) sprintf (dest, "%d", julian_date (full_date)); else if (cursize == 2) sprintf (dest, "%02d", year); else if (cursize == 4) sprintf (dest, "%02d%02d", century, year); break; /* m month, 1-12 */ /* mm month, 01-12 */ /* mmm month, 3 letters */ /* mmmm month, full name */ case 'm': if (cursize == 1) sprintf (dest, (isdigit (lastch)? "%2d": "%d"), month); else if (cursize == 2) sprintf (dest, "%02d", month); else if (cursize == 3) { memcpy (dest, month_name [month - 1], 3); dest [3] = 0; } else if (cursize == 4) strcpy (dest, month_name [month - 1]); break; /* MMM month, 3-letters, ucase */ /* MMMM month, full name, ucase */ case 'M': if (cursize == 3) { memcpy (dest, month_name [month - 1], 3); dest [3] = 0; strupc (dest); } else if (cursize == 4) { strcpy (dest, month_name [month - 1]); strupc (dest); } break; /* d day, 1-31 */ /* dd day, 01-31 */ /* ddd day of week, Sun-Sat */ /* dddd day of week, Sunday-Saturday */ case 'd': if (cursize == 1) sprintf (dest, (isdigit (lastch)? "%2d": "%d"), day); else if (cursize == 2) sprintf (dest, "%02d", day); else if (cursize == 3) { memcpy (dest, day_name [day_of_week (full_date)], 3); dest [3] = 0; } else if (cursize == 4) strcpy (dest, day_name [day_of_week (full_date)]); break; /* DDD day of week, SUN-SAT */ /* DDDD day of week, SUNDAY-SATURDAY */ case 'D': if (cursize == 3) { memcpy (dest, day_name [day_of_week (full_date)], 3); dest [3] = 0; strupc (dest); } else if (cursize == 4) { strcpy (dest, day_name [day_of_week (full_date)]); strupc (dest); } break; /* w day of week, 1-7 (1=Sunday) */ /* ww week of year, 1-53 */ case 'w': if (cursize == 1) sprintf (dest, "%d", day_of_week (full_date) + 1); else if (cursize == 2) sprintf (dest, "%d", week_of_year (full_date)); break; /* q year quarter, 1-4 */ case 'q': if (cursize == 1) sprintf (dest, "%d", year_quarter (full_date)); break; /* \x literal character x */ case '\\': ch = *picture++; } if (*dest) /* If something was output, */ while (*dest) /* skip to end of string */ dest++; else while (cursize--) /* Else output ch once or more */ *dest++ = ch; /* and bump dest pointer */ lastch = *(dest - 1); /* Get previous character */ *dest = 0; /* Terminate the string nicely */ } return (formatted); }