Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Time t 1970 check #203

Merged
merged 4 commits into from
Oct 3, 2013
Merged

Conversation

joakim-hove
Copy link
Contributor

  1. All calls to util_make_date() -> ecl_util_make_date() in the libecl library.
  2. Check if time_t/mktime() can accept values before 1970 during configuration.
  3. If mktime() can not accept dates before 1970 : use hysterical heuristics to shift year into the interval [1970 - 2038).

{
time_t t = mktime( &ts );
if (t == -1)
exit(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. Isn't this slightly backwards? exit(0) from main() typically means "successful" while mktime() returns -1 if an error occurred.

Also, is there a reason you're using POSIX interfaces when the standard <time.h> also provides mktime()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arggh: How to interleave answers in this interface?

I don't understand. Isn't this slightly backwards? exit(0) from main() typically means "successful" while mktime() returns -1 if an error occurred.

yes - it is backwards; I was waiting for that comment. Will fix before merging.

The POSIX thing was an oversight though. Will fix.

Thanks for the review.

@bska
Copy link
Contributor

bska commented Oct 1, 2013

Just to follow up on the previous comment. The program below ought to print [something along the lines of]

Time = Mon Jan  1 00:00:00 1900

(and return successfully) on all platforms that support a basic C runtime system.

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

int main(void) {
  int       ret;
  struct tm ts = { 0 };

  ts.tm_mday   =   1  ;
  ts.tm_isdst  =  -1  ;

  {
    time_t t = mktime( &ts );
    if (t == -1)
      ret = EXIT_FAILURE;
    else {
      ret = EXIT_SUCCESS;
      printf("Time = %s", ctime(&t));
    }
  }

  return ret;
}

@joakim-hove
Copy link
Contributor Author

Just to follow up on the previous comment. The program below ought to
print

Time = Mon Jan 1 00:00:00 1900

(and return successfully) on all platforms that support a basic C runtime
system.

You would have thought so - but no. The standard is unspecified as what to
do with times prior to Jan 1 00:00:00 1970, and the MS Visual Studio
runtime has decided to return -1 in that case.

http://stackoverflow.com/questions/471248/what-is-ultimately-a-time-t-typedef-to

Joakim

@bska
Copy link
Contributor

bska commented Oct 1, 2013

@joakim-hove

You would have thought [that mktime() would be able to process times prior to 1970-01-01T00:00:00+0000] - but no.

I stand corrected. Thanks a lot for bringing that to my attention. Apparently I never paid enough attention to the fine details of the specification.

joakim-hove added a commit that referenced this pull request Oct 3, 2013
@joakim-hove joakim-hove merged commit 873924c into Ensembles:master Oct 3, 2013
@joakim-hove joakim-hove deleted the time_t_1970_check branch March 25, 2014 19:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants