- static const char *months[12] =
- {
- "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
- "JUL", "AUG", "SEP", "OCT", "NOV", "DEC",
- };
-
- char buf[64] = {0};
- int ofs = number / 86400.;
- int month, day, year;
-
- if (ofs < 1)
- return 0;
-
- calendar_offset_to_gregorian (ofs, &year, &month, &day);
- switch (fp->type)
- {
- case FMT_DATE:
- if (fp->w >= 11)
- sprintf (buf, "%02d-%s-%04d", day, months[month - 1], year);
- else
- sprintf (buf, "%02d-%s-%02d", day, months[month - 1], year % 100);
- break;
- case FMT_EDATE:
- if (fp->w >= 10)
- sprintf (buf, "%02d.%02d.%04d", day, month, year);
- else
- sprintf (buf, "%02d.%02d.%02d", day, month, year % 100);
- break;
- case FMT_SDATE:
- if (fp->w >= 10)
- sprintf (buf, "%04d/%02d/%02d", year, month, day);
- else
- sprintf (buf, "%02d/%02d/%02d", year % 100, month, day);
- break;
- case FMT_ADATE:
- if (fp->w >= 10)
- sprintf (buf, "%02d/%02d/%04d", month, day, year);
- else
- sprintf (buf, "%02d/%02d/%02d", month, day, year % 100);
- break;
- case FMT_JDATE:
- {
- int yday = calendar_offset_to_yday (ofs);
-
- if (fp->w < 7)
- sprintf (buf, "%02d%03d", year % 100, yday);
- else if (year4 (year))
- sprintf (buf, "%04d%03d", year, yday);
- else
- break;
- }
- case FMT_QYR:
- if (fp->w >= 8)
- sprintf (buf, "%d Q% 04d", (month - 1) / 3 + 1, year);
- else
- sprintf (buf, "%d Q% 02d", (month - 1) / 3 + 1, year % 100);
- break;
- case FMT_MOYR:
- if (fp->w >= 8)
- sprintf (buf, "%s% 04d", months[month - 1], year);
- else
- sprintf (buf, "%s% 02d", months[month - 1], year % 100);
- break;
- case FMT_WKYR:
- {
- int yday = calendar_offset_to_yday (ofs);
-
- if (fp->w >= 10)
- sprintf (buf, "%02d WK% 04d", (yday - 1) / 7 + 1, year);
- else
- sprintf (buf, "%02d WK% 02d", (yday - 1) / 7 + 1, year % 100);
- }
- break;
- case FMT_DATETIME:
- {
- char *cp;
-
- cp = spprintf (buf, "%02d-%s-%04d %02d:%02d",
- day, months[month - 1], year,
- (int) fmod (floor (number / 60. / 60.), 24.),
- (int) fmod (floor (number / 60.), 60.));
- if (fp->w >= 20)
- {
- int w, d;
-
- if (fp->w >= 22 && fp->d > 0)
- {
- d = min (fp->d, fp->w - 21);
- w = 3 + d;
- }
- else
- {
- w = 2;
- d = 0;
- }
-
- cp = spprintf (cp, ":%0*.*f", w, d, fmod (number, 60.));
- }
- }
- break;
- default:
- NOT_REACHED ();
- }