Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getdate(3c) — NEWS-os 5.0.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

setlocale(3C)

ctype(3C)

environ(5)

getdate(3C)



getdate(3C)             LIBRARY FUNCTIONS             getdate(3C)



NAME
     getdate - convert user format date and time

SYNOPSIS
     #include <time.h>

     struct tm *getdate (const char *string);

     extern int getdateerr;

DESCRIPTION
     getdate converts user-definable date and/or time  specifica-
     tions  pointed to by string into a tm structure.  The struc-
     ture declaration is in the  time.h  header  file  [see  also
     ctime(3C)].

     User-supplied templates are used to parse and interpret  the
     input  string.   The templates are text files created by the
     user and identified via the  environment  variable  DATEMSK.
     Each  line  in  the  template  represents an acceptable date
     and/or time specification  using  some  of  the  same  field
     descriptors as the ones used by the date command.  The first
     line in the template that matches the input specification is
     used  for  interpretation  and  conversion into the internal
     time format.  If successful, the function getdate returns  a
     pointer  to  a  tm structure; otherwise, it returns NULL and
     sets the global variable getdateerr to indicate the error.

     The following field descriptors are supported:

          %%   same as %
          %a   abbreviated weekday name
          %A   full weekday name
          %b   abbreviated month name
          %B   full month name
          %c   locale's appropriate date and time representation
          %d   day of month ( 01 - 31; the leading 0 is  optional
               )
          %e   same as %d
          %D   date as %m/%d/%y
          %h   abbreviated month name
          %H   hour ( 00 - 23 )
          %I   hour ( 01 - 12 )
          %m   month number ( 01 - 12 )
          %M   minute ( 00 - 59 )
          %n   same as \n
          %p   locale's equivalent of either AM or PM
          %r   time as %I:%M:%S %p
          %R   time as %H:%M
          %S   seconds ( 00 - 59 )
          %t   insert a tab
          %T   time as %H:%M:%S



                                                                1





getdate(3C)             LIBRARY FUNCTIONS             getdate(3C)



          %w   weekday number ( Sunday = 0 - 6)
          %x   locale's appropriate date representation
          %X   locale's appropriate time representation
          %y   year with century ( 00 - 99 )
          %Y   year as ccyy ( e.g. 1986)
          %Z   time zone name or no characters if  no  time  zone
               exists

     The month and weekday names can consist of  any  combination
     of  upper and lower case letters.  The user can request that
     the input date  or  time  specification  be  in  a  specific
     language  by  setting the categories LCTIME and LCCTYPE of
     setlocale(3C).

     The following example shows the possible contents of a  tem-
     plate:

          %m
          %A %B %d %Y, %H:%M:%S
          %A
          %B
          %m/%d/%y %I %p
          %d,%m,%Y %H:%M
          at %A the %dst of %B in %Y
          run job at %I %p,%B %dnd
          %A den %d. %B %Y %H.%M Uhr

     The following are examples of valid input specifications for
     the above template:

          getdate("10/1/87 4 PM")
          getdate("Friday")
          getdate("Friday September 19 1987, 10:30:30")
          getdate("24,9,1986 10:30")
          getdate("at monday the 1st of december in 1986")
          getdate("run job at 3 PM, december %2nd")

     If the LANG environment variable is set to german, the  fol-
     lowing is valid:

          getdate("freitag den 10. oktober 1986 10.30 Uhr")

     Local time and date specification are also  supported.   The
     following  examples  show how local date and time specifica-
     tion can be defined in the template.
           _______________________________________________
                    Invocation           Line in Template
           _______________________________________________
            getdate("11/27/86")          %m/%d/%y
            getdate("27.11.86")          %d.%m.%y
            getdate("86-11-27")          %y-%m-%d
            getdate("Friday 12:00:00")   %A %H:%M:%S



                                                                2





getdate(3C)             LIBRARY FUNCTIONS             getdate(3C)



           _______________________________________________
          |                           |                  |
     The fo
|
llowing rules are applied f
|
or converting the
|
input specif
|
ication into the internal fo
|
rmat: | | | | I
|
f only the weekday is given,
|
today is assumed |if the g
|
iven day is equal to the cu
|
rrent day and next|week if i
|
t is less. | | | | | I
|
f only the month is given
|
, the current mo
|
nth is a
|
ssumed if the given mont
|
h is equal to the|current m
|
onth and next year if it is|less and no year is
|
given. (
|
The first day of month is as
|
sumed if no day is|given.) | | | I
|
f no hour, minute, and secon
|
d are given, the |current h
|
our, minute, and second are|assumed. | | | | I
|
f no date is given, today is
|
assumed if the gi↓en hour i
|
s greater than the curre
|
nt hour and tomo
|
rrow is a
|
ssumed if it is less. | | | | | The fo
|
llowing examples illustrate|the above rules. | Assume that |the current date is Mon Se
|
p 22 12:19:47 EDT 1
|
986 and the LANG environment variable is n
|
ot set. | _______|___________________________|__________________|_________ | Inpu
|
t | Line in Template| | Date | | |_______|_____|__________________|__|__________________|________| | Mon | | %a | M
|
on Sep 22 12:19:48|EDT 1986| | Sun | | %a | S
|
un Sep 28 12:19:49|EDT 1986| | Fri | | %a | F
|
ri Sep 26 12:19:49|EDT 1986| | September | %B | M
|
on Sep 1 12:19:49|EDT 1986| | January | %B | T
|
hu Jan 1 12:19:49|EST 1987| | December | %B | M
|
on Dec 1 12:19:49|EST 1986| | Sep Mon | %b %a | M
|
on Sep 1 12:19:50|EDT 1986| | Jan Fri | %b %a | F
|
ri Jan 2 12:19:50|EST 1987| | Dec Mon | %b %a | M
|
on Dec 1 12:19:50|EST 1986| | Jan Wed 1989| %b %a %Y | W
|
ed Jan 4 12:19:51|EST 1989| | Fri 9 | | %a %H | F
|
ri Sep 26 09:00:00|EDT 1986| | Feb 10:30 | %b %H:%S | S
|
un Feb 1 10:00:30|EST 1987| | 10:30 | | %H:%M | T
|
ue Sep 23 10:30:00|EDT 1986| | 13:30 | | %H:%M | M
|
on Sep 22 13:30:00|EDT 1986| |_______|_____|__________________|__|__________________|________| | | | FILES | | | /usr/lib/locale/<locale>/LCTIMEla
|
nguage specific pr
|
intable files| | | /usr/lib/locale/<locale>/LCCTYPEcode set specific printable files SEE ALSO setlocale(3C), ctype(3C), environ(5). 3


getdate(3C)             LIBRARY FUNCTIONS             getdate(3C)



DIAGNOSTICS
     On failure  getdate  returns  NULL  and  sets  the  variable
     getdateerr to indicate the error.

     The following is a complete list of the getdateerr settings
     and their meanings.

        1    The DATEMSK environment variable is  null  or  unde-
             fined.

        2    The template file cannot be opened for reading.

        3    Failed to get file status information.

        4    The template file is not a regular file.

        5    An error is encountered while reading  the  template
             file.

        6    malloc failed (not enough memory is available).

        7    There is no line in the template  that  matches  the
             input.

        8    The input specification is invalid  (e.g.,  February
             31).

NOTES
     Subsequent  calls  to  getdate(3C)  alter  the  contents  of
     getdateerr.   Dates before 1970 and after 2037 are illegal.
     getdate makes explicit use of macros described in ctype(3C).
























                                                                4



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026