abashian@b11.ingr.com (Pete Abashian) (06/02/89)
Yikes! For fear that I just fell off the banana boat yesterday, prepare ye all your flame throwers... We all (theoretically) know the function of asctime(); right? ie: long ltime; struct tm *timedef; char *p; ltime = atol(pointer to number of seconds since epoch); timedef = localtime(<ime); p = asctime(timedef); return(p); Where p is now a pointer to a string similar to Jun 01, 1989 22:25:00 EST... Now the problem. I need to be able to take an ascii string and convert it back to the internal storage - number of seconds since epoch. The task would normally entail some simple mathematics to incorporate leap [gag] years, etc... But what about the sticky user(s) that want to be able to input virtually any valid combination of dates/times? 12MAY89, 12-MAY-89, May 12, 1989....etc. For the life of me I cannot remember EVER seeing an include file or archive with a reference to such a routine. Did I just fall off the boat, or what? _______________________________________________________________________________ | Jim Kazek, Intergraph Corporation, "It's my bosses opionion that I have none"| | ingr!e911!jimk (205) 464-8690 || "If you have a Studebaker, I've got a DEC Rainbow for the trunk..." |+______________________________________________________________________________+
jpr@dasys1.UUCP (Jean-Pierre Radley) (06/06/89)
In article <5178@b11.ingr.com> abashian@b11.ingr.com (Pete Abashian) writes: >Now the problem. I need to be able to take an ascii string and >convert it back to the internal storage - number of seconds since epoch. > >The task would normally entail some simple mathematics to incorporate leap >[gag] years, etc... But what about the sticky user(s) that want to be >able to input virtually any valid combination of dates/times? 12MAY89, >12-MAY-89, May 12, 1989....etc. For the life of me I cannot remember EVER >seeing an include file or archive with a reference to such a routine. In one of the LIBraries of the TANGENT Forum on CompuServe, there is DATECALC, which permits users to input 12-may-88, or May 12, 1988, or even 12;may;88, then compare it to anothr date, or add or subtract days to the original date. I do believe that in accomplishing this, input data are converted into seconds from the epoch. This what you're after? E-Mail me if you haven't Compuserve access. -- Jean-Pierre Radley CIS: 72160,1341 jpr@jpradley.UUCP
cline@sun.soe.clarkson.edu (Marshall Cline) (06/08/89)
In article <5178@b11.ingr.com> abashian@b11.ingr.com (Pete Abashian) writes: >....... I need to be able to take an ascii string and >convert it back to the internal storage - number of seconds since epoch. >The task would normally entail some simple mathematics to incorporate leap >[gag] years, etc... But what about the sticky user(s) that want to be >able to input virtually any valid combination of dates/times? 12MAY89, >12-MAY-89, May 12, 1989....etc. For the life of me I cannot remember EVER >seeing an include file or archive with a reference to such a routine. Don't the "at" and "calendar" utilities do something like that? The "at" syntax for a date/time isn't as general as you'd like. Man page extract from at(1): | Thus legitimate commands include: | at 0815am Jan 24 | at 8:15am Jan 24 | at now + 1 day | at 5 pm Friday The dates syntax of "calendar" is more flexible. From "calendar(1)" man page: |DESCRIPTION | ..................... Most reasonable month-day dates - | such as `Dec. 7,' `december 7,' and `12/7' - are recognized, | but `7 December' or `7/12' are not.......................... "calendar" uses /usr/lib/calendar (an a.out) to figure out todays and tomorrows date. It's an egrep expression, which is (for June 7, 1989): (^|[ (,;])((([Jj]un[^ ]*|\*)[ ]*|(06|6|\*)/)0*7)([^0123456789]|$) (^|[ (,;])((([Jj]un[^ ]*|\*)[ ]*|(06|6|\*)/)0*8)([^0123456789]|$) As EVERYBODY can PLAINLY see, this is a TRIVIAL representation for... well... It's... Ummm... so obvious I don't need to say anything. :-) Anyway, the point is that "calendar" waits until the date shown matches "today"'s date. That's not really what you want. But it may be a start. Marshall -- ________________________________________________________________ Marshall P. Cline ARPA: cline@sun.soe.clarkson.edu ECE Department UseNet: uunet!sun.soe.clarkson.edu!cline Clarkson University BitNet: BH0W@CLUTX Potsdam, NY 13676 AT&T: (315) 268-6591
dworkin@Solbourne.COM (Dieter Muller) (06/22/89)
In article <5178@b11.ingr.com> abashian@b11.ingr.com (Pete Abashian) writes: >Now the problem. I need to be able to take an ascii string and >convert it back to the internal storage - number of seconds since epoch. > >The task would normally entail some simple mathematics to incorporate leap >[gag] years, etc... But what about the sticky user(s) that want to be >able to input virtually any valid combination of dates/times? 12MAY89, >12-MAY-89, May 12, 1989....etc. For the life of me I cannot remember EVER >seeing an include file or archive with a reference to such a routine. You might be interested in the CCMD library from Columbia University. It's ``An Implementation of the TOPS-20 COMND Jsys in C''. Among many other things, it has a very nice date parser. I just tried all the forms you listed, and they all worked. The code is public domain (commercial rights reserved) and currently runs on BSD, SysV, Ultrix, and MS-DOS systems. It was written by Andrew Lowry and Howard Kaye at Columbia University. I know they're on the net, but I can't find an actual account name anywhere in the code. If you have Internet access, you can ftp it from cunixc.columbia.edu. Dieter -- Welcome to the island. You are number six. boulder!stan!dworkin dworkin%stan@boulder.colorado.edu dworkin@solbourne.com