-
Notifications
You must be signed in to change notification settings - Fork 2
/
Time.scala
54 lines (42 loc) · 1001 Bytes
/
Time.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package time
import utils.InputException
import utils.ExceptionMessages.WrongTimeInput
class Time(val input: Int) {
import Time._
/**
* Service functions
*/
private def up60: Int =
if (input < 0) throw new InputException(WrongTimeInput)
else input * 60
private def down60: Int =
if (input < 0) throw new InputException(WrongTimeInput)
else input / 60
/**
* Converts seconds to hours
*/
def hoursToSeconds: Int = (input up60) up60
/**
* Converts minutes to hours
*/
def minutesToSeconds: Int = input up60
/**
* Converts seconds to minutes
*/
def secondsToMinutes: Int = input down60
/**
* Converts seconds to hours
*/
def secondsToHours: Int = (input down60) down60
/**
* Converts hours to minutes
*/
def hoursToMinutes: Int = input up60
/**
* Converts minutes to hours
*/
def minutesToHours: Int = input down60
}
object Time {
implicit def intToTime(a: Int): Time = new Time(a)
}