-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.kts
More file actions
85 lines (76 loc) · 1.92 KB
/
Date.kts
File metadata and controls
85 lines (76 loc) · 1.92 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.text.SimpleDateFormat
import java.util.*
/**
* Pattern: yyyy-MM-dd HH:mm:ss
*/
fun Date.formatToServerDateTimeDefaults(): String{
val sdf= SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
return sdf.format(this)
}
fun Date.formatToTruncatedDateTime(): String{
val sdf= SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault())
return sdf.format(this)
}
/**
* Pattern: yyyy-MM-dd
*/
fun Date.formatToServerDateDefaults(): String{
val sdf= SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
return sdf.format(this)
}
/**
* Pattern: HH:mm:ss
*/
fun Date.formatToServerTimeDefaults(): String{
val sdf= SimpleDateFormat("HH:mm:ss", Locale.getDefault())
return sdf.format(this)
}
/**
* Pattern: dd/MM/yyyy HH:mm:ss
*/
fun Date.formatToViewDateTimeDefaults(): String{
val sdf= SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault())
return sdf.format(this)
}
/**
* Pattern: dd/MM/yyyy
*/
fun Date.formatToViewDateDefaults(): String{
val sdf= SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())
return sdf.format(this)
}
/**
* Pattern: HH:mm:ss
*/
fun Date.formatToViewTimeDefaults(): String{
val sdf= SimpleDateFormat("HH:mm:ss", Locale.getDefault())
return sdf.format(this)
}
/**
* Add field date to current date
*/
fun Date.add(field: Int, amount: Int): Date {
Calendar.getInstance().apply {
time = this@add
add(field, amount)
return time
}
}
fun Date.addYears(years: Int): Date{
return add(Calendar.YEAR, years)
}
fun Date.addMonths(months: Int): Date {
return add(Calendar.MONTH, months)
}
fun Date.addDays(days: Int): Date{
return add(Calendar.DAY_OF_MONTH, days)
}
fun Date.addHours(hours: Int): Date{
return add(Calendar.HOUR_OF_DAY, hours)
}
fun Date.addMinutes(minutes: Int): Date{
return add(Calendar.MINUTE, minutes)
}
fun Date.addSeconds(seconds: Int): Date{
return add(Calendar.SECOND, seconds)
}