PARSEDATE(3)
π PARSEDATE π β the parsedate(3) page, bestie edition
okay so we're in the Library Functions Manual, section 3, and this lil function is called parsedate. she's been around since forever (iykyk, we'll get to the lore at the end π«Ά).
β¨ NAME β¨
parsedate β convert time and date string to number
πΈ SYNOPSIS πΈ
#include <sys/types.h>
typedef struct _TIMEINFO {
time_t time;
long usec;
long tzone;
} TIMEINFO;
time_t
parsedate(text, now)
char *text;
TIMEINFO *now;
like. look at her. struct, args, everything. π
π¦ DESCRIPTION π¦
parsedate takes a whole bunch of the time specifications people actually type and turns them into the number of seconds since the epoch β aka a time_t. see time(2) if you need the deets on what an epoch even is, bestie.
parsedate returns the time, or -1 on error. (yes, -1. she's dramatic like that. π)
textis a character string containing the time and date.nowis a pointer to the time that should be used for calculating relative dates. IfnowisNULL, thenGetTimeInfoinlibinn(3)is used to obtain the current time and timezone.
π what's actually inside the string π
The character string consists of zero or more specifications of the following form:
timeβ a time of day, which is of the formhh[:mm[:ss]] [meridian] [zone]orhhmm [meridian] [zone]. If no meridian is specified,hhis interpreted on a 24-hour clock.dateβ a specific month and day with optional year. The acceptable formats aremm/dd[/yy],yyyy/mm/dd,monthname dd[, yy],dd monthname [yy], andday, dd monthname yy. The default year is the current year. If the year is less then 100, then 1900 is added to it; if it is less then 21, then 2000 is added to it.relative timeβ a specification relative to the current time. The format isnumber unit; acceptable units areyear,month,week,day,hour,minute(ormin), andsecond(orsec). The unit can be specified as a singular or plural, as in3 weeks.
β οΈ heads up: the year logic is literally written as "less then 100" and "less then 21" in the source lore β so 21 gets 2000 added, and anything under 100 gets 1900 added. yes, that's how it works. no, don't ask me to make it cuter, those are the numbers. π
π« how she actually calculates the date π«
The actual date is calculated according to the following steps, in order, no skipping:
- First, any absolute date and/or time is processed and converted.
- Using that time as the base, day-of-week specifications are added.
- Next, relative specifications are used.
- If a date or day is specified, and no absolute or relative time is given, midnight is used.
- Finally, a correction is applied so that the correct hour of the day is produced after allowing for daylight savings time differences.
π§ case, abbreviations and unknown words π§
parsedate ignores case when parsing all words β she's not picky, she's flexible. π
Unknown words are taken to be unknown timezones, which are treated as GMT.
The names of the months and days of the week can be abbreviated to their first three letters, with optional trailing period.
Periods are ignored in any timezone or meridian values. (<- cute. slay. periodt. literally.)
π BUGS π
ngl, she has some flaws and we're gonna be honest about them:
parsedatedoes not accept all desirable and unambiguous constructions.- Semantically incorrect dates such as ``February 31'' are accepted. (yes really. she will just let you do that. π)
- Daylight savings time is always taken as a one-hour change which is wrong for some places.
- The daylight savings time correction can get confused if parsing a time within an hour of when the reckoning changes, or if given a partial date.
π¨ so fr fr: if you're near a DST boundary or you handed her a partial date, do a vibe check on the result before you trust it.
π HISTORY π
the lore is genuinely iconic:
- Originally written by Steven M. Bellovin
<smb@research.att.com>while at the University of North Carolina at Chapel Hill and distributed under the namegetdate. - A major overhaul was done by Rich $alz
<rsalz@bbn.com>and Jim Berets<jberets@bbn.com>in August, 1990. - It was further revised (primarily to remove obsolete constructs and timezone names) a year later by Rich (now
<rsalz@osf.org>) for InterNetNews, and the name was changed. - This is revision
1.10, dated1993/01/29.
π SEE ALSO π
and that's the whole page, bestie!! πβ¨ she lives in the Library Functions Manual as parsedate(3), she's still sitting at revision 1.10 from 1993/01/29, and honestly? main character energy for a function that old. go parse something. ππ¦πΈπ
π«Ά
π¦ where this page comes from
- debian bookworm: inn 1:1.7.2q-47
- debian trixie: inn 1:1.7.2q-52
- ubuntu jammy: inn 1:1.7.2q-46build3
- ubuntu noble: inn 1:1.7.2q-50
- ubuntu questing: inn 1:1.7.2q-52
- ubuntu resolute: inn 1:1.7.2q-52build1
- ubuntu stonking: inn 1:1.7.2q-52build2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms