File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
src/main/java/honours/ing/banq/time Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change
1
+ time.txt
1
2
2
3
# Created by https://www.gitignore.io/api/windows,linux,intellij
3
4
Original file line number Diff line number Diff line change 1
1
package honours .ing .banq .time ;
2
2
3
+ import java .io .*;
3
4
import java .util .Date ;
4
5
5
6
/**
@@ -11,7 +12,33 @@ public class TimeUtil {
11
12
12
13
private static final long DAY = 1000 * 60 * 60 * 24 ; // second * minute * hour * day
13
14
14
- private static long addedMillis = 0 ;
15
+ private static long addedMillis = init ();
16
+
17
+ private static long init () {
18
+ try {
19
+ File time = new File ("time.txt" );
20
+ if (!time .exists ()) {
21
+ time .createNewFile ();
22
+ PrintWriter out = new PrintWriter (new FileOutputStream (time ));
23
+ out .println (0L );
24
+ out .close ();
25
+ }
26
+
27
+ try (BufferedReader in = new BufferedReader (new FileReader (time ))) {
28
+ return Long .parseLong (in .readLine ());
29
+ }
30
+ } catch (Exception ignored ) { }
31
+ return 0 ;
32
+ }
33
+
34
+ private static void save () {
35
+ try {
36
+ File time = new File ("time.txt" );
37
+ PrintWriter out = new PrintWriter (new FileOutputStream (time ));
38
+ out .println (0L );
39
+ out .close ();
40
+ } catch (Exception ignored ) { }
41
+ }
15
42
16
43
/**
17
44
* Simulates the passing of x days.
@@ -23,13 +50,15 @@ public static void addDays(int days) {
23
50
}
24
51
25
52
addedMillis += days * DAY ;
53
+ save ();
26
54
}
27
55
28
56
/**
29
57
* Resets the simulation of time.
30
58
*/
31
59
public static void resetTime () {
32
60
addedMillis = 0 ;
61
+ save ();
33
62
}
34
63
35
64
/**
You can’t perform that action at this time.
0 commit comments