From 3b03bee19abd8ed1a4e9e93b970b08836a8399e5 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 1 Mar 2023 13:55:46 -0500 Subject: [PATCH] Add time --- .idea/codeStyles/codeStyleConfig.xml | 5 ++ .../src/ca/cosc3p91/a2/util/Print.java | 7 +++ .../src/ca/cosc3p91/a2/util/Time.java | 48 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 Assignment 2/src/ca/cosc3p91/a2/util/Print.java create mode 100644 Assignment 2/src/ca/cosc3p91/a2/util/Time.java diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/Assignment 2/src/ca/cosc3p91/a2/util/Print.java b/Assignment 2/src/ca/cosc3p91/a2/util/Print.java new file mode 100644 index 0000000..0cf0ac4 --- /dev/null +++ b/Assignment 2/src/ca/cosc3p91/a2/util/Print.java @@ -0,0 +1,7 @@ +package ca.cosc3p91.a2.util; + +public class Print { + + + +} diff --git a/Assignment 2/src/ca/cosc3p91/a2/util/Time.java b/Assignment 2/src/ca/cosc3p91/a2/util/Time.java new file mode 100644 index 0000000..d006449 --- /dev/null +++ b/Assignment 2/src/ca/cosc3p91/a2/util/Time.java @@ -0,0 +1,48 @@ +package ca.cosc3p91.a2.util; + +public class Time { + + private long timeSeconds; + + protected Time(long timeSeconds) { + this.timeSeconds = timeSeconds; + } + + public Time offsetSeconds(long seconds){ + timeSeconds += seconds; + return this; + } + + public Time offsetMinutes(long minutes) { + return offsetSeconds(minutes * 60); + } + + public Time offsetHours(long hours) { + return offsetMinutes(hours * 60); + } + + public Time offsetDays(long days){ + return offsetHours(days * 24); + } + + public long get(){ + return timeSeconds; + } + + public static class FutureTime { + private final Time futureTime; + + public FutureTime(Time futureTime){ + this.futureTime = futureTime; + } + + public boolean occurred(){ + return getTime().timeSeconds >= futureTime.timeSeconds; + } + } + + public static Time getTime(){ + return new Time(System.currentTimeMillis() / 1000); + } + +}