Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
TIME.cpp@33:3b5096f0126a, 2018-01-07 (annotated)
- Committer:
- chills
- Date:
- Sun Jan 07 00:45:11 2018 +0000
- Revision:
- 33:3b5096f0126a
- Parent:
- 31:4a88bf97b53e
- Child:
- 34:c0b8705f183d
2018_01_07 00:41; Write using in-built time class;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 31:4a88bf97b53e | 1 | #include "TIME.hpp" |
thomasmorris | 31:4a88bf97b53e | 2 | |
thomasmorris | 31:4a88bf97b53e | 3 | |
thomasmorris | 31:4a88bf97b53e | 4 | using namespace std; |
thomasmorris | 31:4a88bf97b53e | 5 | |
chills | 33:3b5096f0126a | 6 | Mutex Time_Lock; |
chills | 33:3b5096f0126a | 7 | |
thomasmorris | 31:4a88bf97b53e | 8 | int current_time_global = 0; |
thomasmorris | 31:4a88bf97b53e | 9 | int new_time = 0; |
thomasmorris | 31:4a88bf97b53e | 10 | |
thomasmorris | 31:4a88bf97b53e | 11 | int get_current_time() //Get Current Time |
thomasmorris | 31:4a88bf97b53e | 12 | { |
chills | 33:3b5096f0126a | 13 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 14 | current_time_global = time(0); |
chills | 33:3b5096f0126a | 15 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 16 | return current_time_global; |
thomasmorris | 31:4a88bf97b53e | 17 | } |
thomasmorris | 31:4a88bf97b53e | 18 | |
thomasmorris | 31:4a88bf97b53e | 19 | void Add_Second() //Seconds to Seconds |
thomasmorris | 31:4a88bf97b53e | 20 | { |
chills | 33:3b5096f0126a | 21 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 22 | new_time = time(0) + 1; |
chills | 33:3b5096f0126a | 23 | set_time(new_time); |
chills | 33:3b5096f0126a | 24 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 25 | } |
thomasmorris | 31:4a88bf97b53e | 26 | |
thomasmorris | 31:4a88bf97b53e | 27 | void Subtract_Second() |
thomasmorris | 31:4a88bf97b53e | 28 | { |
chills | 33:3b5096f0126a | 29 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 30 | new_time = time(0) - 1; |
chills | 33:3b5096f0126a | 31 | set_time(new_time); |
chills | 33:3b5096f0126a | 32 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 33 | } |
thomasmorris | 31:4a88bf97b53e | 34 | |
thomasmorris | 31:4a88bf97b53e | 35 | void Add_Minute() //Minutes to Seconds |
thomasmorris | 31:4a88bf97b53e | 36 | { |
chills | 33:3b5096f0126a | 37 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 38 | new_time = time(0) + 60; |
chills | 33:3b5096f0126a | 39 | set_time(new_time); |
chills | 33:3b5096f0126a | 40 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 41 | } |
thomasmorris | 31:4a88bf97b53e | 42 | |
thomasmorris | 31:4a88bf97b53e | 43 | void Subtract_Minute() |
thomasmorris | 31:4a88bf97b53e | 44 | { |
chills | 33:3b5096f0126a | 45 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 46 | new_time = time(0) - 60; |
chills | 33:3b5096f0126a | 47 | set_time(new_time); |
chills | 33:3b5096f0126a | 48 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 49 | } |
thomasmorris | 31:4a88bf97b53e | 50 | |
thomasmorris | 31:4a88bf97b53e | 51 | void Add_Hour() //Hours to Seconds |
thomasmorris | 31:4a88bf97b53e | 52 | { |
chills | 33:3b5096f0126a | 53 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 54 | new_time = time(0) + 3600; |
thomasmorris | 31:4a88bf97b53e | 55 | set_time(new_time); |
chills | 33:3b5096f0126a | 56 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 57 | } |
thomasmorris | 31:4a88bf97b53e | 58 | |
thomasmorris | 31:4a88bf97b53e | 59 | void Subtract_Hour() |
thomasmorris | 31:4a88bf97b53e | 60 | { |
chills | 33:3b5096f0126a | 61 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 62 | new_time = time(0) - 3600; |
chills | 33:3b5096f0126a | 63 | set_time(new_time); |
chills | 33:3b5096f0126a | 64 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 65 | } |
thomasmorris | 31:4a88bf97b53e | 66 | |
thomasmorris | 31:4a88bf97b53e | 67 | void Add_Day() //Days to Seconds |
thomasmorris | 31:4a88bf97b53e | 68 | { |
chills | 33:3b5096f0126a | 69 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 70 | new_time = time(0) + 86400; |
chills | 33:3b5096f0126a | 71 | set_time(new_time); |
chills | 33:3b5096f0126a | 72 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 73 | } |
thomasmorris | 31:4a88bf97b53e | 74 | |
thomasmorris | 31:4a88bf97b53e | 75 | void Subtract_Day() |
thomasmorris | 31:4a88bf97b53e | 76 | { |
chills | 33:3b5096f0126a | 77 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 78 | new_time = time(0) - 86400; |
chills | 33:3b5096f0126a | 79 | set_time(new_time); |
chills | 33:3b5096f0126a | 80 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 81 | } |
thomasmorris | 31:4a88bf97b53e | 82 | |
thomasmorris | 31:4a88bf97b53e | 83 | void Add_Month() //Months to Seconds |
thomasmorris | 31:4a88bf97b53e | 84 | { |
chills | 33:3b5096f0126a | 85 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 86 | new_time = time(0) + 2629743; |
thomasmorris | 31:4a88bf97b53e | 87 | set_time(new_time); |
chills | 33:3b5096f0126a | 88 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 89 | } |
thomasmorris | 31:4a88bf97b53e | 90 | |
thomasmorris | 31:4a88bf97b53e | 91 | void Subtract_Month() |
thomasmorris | 31:4a88bf97b53e | 92 | { |
chills | 33:3b5096f0126a | 93 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 94 | new_time = time(0) - 2629743; |
thomasmorris | 31:4a88bf97b53e | 95 | set_time(new_time); |
chills | 33:3b5096f0126a | 96 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 97 | } |
thomasmorris | 31:4a88bf97b53e | 98 | |
thomasmorris | 31:4a88bf97b53e | 99 | void Add_Year() //Years to Seconds |
thomasmorris | 31:4a88bf97b53e | 100 | { |
chills | 33:3b5096f0126a | 101 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 102 | new_time = time(0) + 31556926; |
chills | 33:3b5096f0126a | 103 | set_time(new_time); |
chills | 33:3b5096f0126a | 104 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 105 | } |
thomasmorris | 31:4a88bf97b53e | 106 | |
thomasmorris | 31:4a88bf97b53e | 107 | void Subtract_Year() |
thomasmorris | 31:4a88bf97b53e | 108 | { |
chills | 33:3b5096f0126a | 109 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 110 | new_time = time(0) - 31556926; |
chills | 33:3b5096f0126a | 111 | set_time(new_time); |
chills | 33:3b5096f0126a | 112 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 113 | } |