OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] limits of the generic

[ Lists Home | Date Index | Thread Index ]

Dare Obasanjo scripsit:

> However I am have been curious about something; is
> there any programming environment that currently
> supports being able to add 4 years, 3 months, 2 days,
> 7 hours, 15 minutes and 12 seconds to September 28th,
> 2002 at 1:36:07PM ? 

Any modern C environment will allow this: forgive me if I am not
sure whether it is ANSI or POSIX that gives us the mktime() function.
It accepts a 'tm' struct containing years, months, days, hours, minutes,
seconds and normalizes it, returning a time_t (seconds since the epoch)
value which in this context is not interesting.

Here is a piece of code that computes your answer, written for clarity
not reusability:

# include <stdio.h>
# include <time.h>

struct tm foo;

main () {
        foo.tm_year = 102;      /* year is offset 1900 */
        foo.tm_mon = 8;         /* months are zero-based */
        foo.tm_mday = 28;
        foo.tm_hour = 13;
        foo.tm_min = 36;
        foo.tm_min = 7;

        foo.tm_year += 4;
        foo.tm_mon += 3;
        foo.tm_mday += 2;
        foo.tm_hour += 7;
        foo.tm_min += 15;
        foo.tm_sec += 12;

        mktime(&foo);

        printf("%d-%d-%d %d:%d:%d\n",
                foo.tm_year + 1900, foo.tm_mon + 1, foo.tm_mday,
                foo.tm_hour, foo.tm_min, foo.tm_sec);
        }


And when run, it prints:

2006-12-30 20:22:12

There may of course be a problem with leap seconds, which cannot be
predicted accurately in advance: the mktime algorithm presumes there
will be none.

-- 
One art / There is                      John Cowan <jcowan@reutershealth.com>
No less / No more                       http://www.reutershealth.com
All things / To do                      http://www.ccil.org/~cowan
With sparks / Galore                     -- Douglas Hofstadter




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS