Giter VIP home page Giter VIP logo

y2038's Introduction

This is an implementation of POSIX time.h which solves the year 2038
bug on systems where time_t is only 32 bits.  It is implemented in
bog-standard ANSI C.  The latest version can be found at
http://y2038.googlecode.com/

It makes use of the system's native 32 bit functions to perform time
zone and daylight savings time calculations and thus does *not* need
to ship its own time zone table.

Here is a list of the currently implemented functions in time64.h and
their POSIX time.h equivalents.

  time64.h                      time.h
  --------                      ------
  localtime64_r                 localtime_r
  localtime64                   localtime
  gmtime64_r                    gmtime_r
  gmtime64                      gmtime
  asctime64_r                   asctime_r
  asctime64                     asctime
  ctime64_r                     ctime_r
  ctime64                       ctime
  timelocal64                   mktime
  mktime64                      mktime
  timegm64                      timegm (a GNU extension)

To install, simply copy time64.c and time64.h into your project and
make use of the functions.

To test, run "make test".  You must have Perl, prove (which comes with
a recent version of the Test::Harness Perl module) and bzdiff
installed to run the full test suite.  It will do a number of unit
tests, plus test against a large table of known good values in
different time zones.


Limitations, Issues, etc...
---------------------------

localtime64_r() gets its time zone and daylight savings time
information by mappping the future year back to a similar one between
2010 and 2037, safe for localtime_r().  The calculations are accurate
according to current time zone and daylight savings information, but
may become inaccurate if a change is made that takes place after 2010.
But its better to be off by an hour than 137 years.

Future versions will probe for a 64 bit safe system localtime_r() and
gmtime_r() and use that.  You can manually set the safe range of your
system in time64_config.h.

The maximum date is still limited by your tm struct.  Most 32 bit
systems use a signed integer tm_year which means the practical upper
limit is the year 2147483647 which is somewhere around 2**54.  You can
use a 64 bit clean tm struct by setting USE_TM64 in time64_config.h


Portability
-----------

I would like to add some configuration detection stuff in the future, but
for now all I can do is document the assumptions...

This code assumes that long longs are 64 bit integers which is technically
in violation of the C standard.  This can be changed in time64.h by
changing the Time64_T and Int64 typedefs.

There are a number of configuration options in time64.h.

y2038's People

Contributors

bulk88 avatar chromatic avatar craigberry avatar schwern avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.