# Lab 4: Epoch Time Overflow

## Overview

There was a lot of scare and hype leading up to the year 2000 because of the so-called "Y2K Bug". Early computers had severely limited storage space, so programmers used only 2 digits to store the year, and it was assumed that the full year would be 19XX, where XX where the two digits. But as the year 2000 approached, people realized that most software with this assumption would suddenly assume it was the year 1900, which is a particularly big problem, for example, in banking software that computes interest rates.

Due to the diligent work of countless programmers updating legacy software, this never materialized into a major crisis. However, there is an even bigger, more subtle problem lurking on the horizon. Another common scheme for storing time is so-called "Unix Time" or "Epoch Time." In this scheme, every timestamp is represented as an integer, which is the number of seconds that have elapsed since midnight on December 1, 1970. For example, the due date of this lab, 11:59PM on Friday 2/21/2020, is 1582329540. As you may recall from week 1 of the course, there are limits to the possible values that can be stored by different variable types. In particular, if one uses the a 32-bit integer int type in Java to store Unix time, this will lead to overflow within the next 20 years, and the time will suddenly jump negative back to the early 1900s. Thus, the problems will be very similar to the Y2K bug, though possibly more far-reaching (every embedded device in cars, planes, buildings, etc is at risk). I expect we will see an FDR-esque public works project to update infrastructure in the years leading up to this problem.

NOTE: A similar problem happens with GPS devices nearly ever 20 years (most recently in 2019), because they store the number of weeks elapsed since 1980 as a 10-bit unsigned integer. Click here to read more about this.

## Code To Write

Your job in this assignment will be to pinpoint the exact year during which Unix time will overflow. You should write a void method printEpochOverflowYear() that prints the year of overflow, and then call this method from your main function (click here to review how to create a project from scratch in NetBeans). The easiest way to do this is to start at 0 seconds at the beginning of 1970, and then to loop through subsequent years, counting the number of seconds that go by each year as you go along. As soon as the seconds go negative, you know you've overflowed, and the loop should terminate. To receive full marks, you must also take into consideration whether a particular year is a leap year when determining the number of seconds to add. Of course, you may copy and paste in the leap year method you wrote in lab 2 to help with this.

## Extra Credit (+2)

To double your score on the lab, write a method printEpochOverflowDay() which prints the exact date in month/day/year format at which the overflow happens. The easiest way to count time at this level of granularity is to have several nested loops. The inner loop should count days, the middle loop should count months, and the outer loop should count years. To help with the months loop, you should write a helper method int getDaysInMonth(int month, boolean leap) which returns the number of days in a particular month, factoring in whether it's a leap year.

## What To Submit

You must submit a .zip file with your project to Canvas. Click here to review how to export your project as a .zip file.