Skip to content

Instantly share code, notes, and snippets.

@omalley
Created April 7, 2015 19:11
Show Gist options
  • Save omalley/f98dc64786933a53da22 to your computer and use it in GitHub Desktop.
Save omalley/f98dc64786933a53da22 to your computer and use it in GitHub Desktop.
The following program demonstrates a 2038 bug in Mac OS 10.10.2.
#include <stdio.h>
#include <time.h>
/*
Demonstrates the Mac OS bug for 2038. The output on Mac OS/X 10.10.2 in PDT:
In 2036 2093587200 - 2093562000 = 25200
In 2037 2125126800 - 2125101600 = 25200
In 2038 2156666400 - 2156637600 = 28800
In 2039 2188202400 - 2188173600 = 28800
*/
int main(int argc, char *argv[]) {
struct tm timeStruct;
timeStruct.tm_sec = 0;
timeStruct.tm_min = 0;
timeStruct.tm_hour = 0;
timeStruct.tm_mday = 5;
timeStruct.tm_mon = 4;
for(int year=2036; year < 2040; ++year) {
timeStruct.tm_year = year - 1900;
time_t local = mktime(&timeStruct);
time_t utc = timegm(&timeStruct);
printf("In %d %ld - %ld = %ld\n", year, local, utc, local - utc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment