forked from akka/akka-http
/
DateTime.java
135 lines (111 loc) · 4 KB
/
DateTime.java
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.http.javadsl.model;
import akka.http.impl.util.Util;
import java.util.Optional;
/**
* Immutable, fast and efficient Date + Time implementation without any dependencies.
* Does not support TimeZones, all DateTime values are always GMT based.
* Note that this implementation discards milliseconds (i.e. rounds down to full seconds).
*/
public abstract class DateTime {
/**
* Returns the year of this instant in GMT.
*/
public abstract int year();
/**
* Returns the month of this instant in GMT.
*/
public abstract int month();
/**
* Returns the day of this instant in GMT.
*/
public abstract int day();
/**
* Returns the hour of this instant in GMT.
*/
public abstract int hour();
/**
* Returns the minute of this instant in GMT.
*/
public abstract int minute();
/**
* Returns the second of this instant in GMT.
*/
public abstract int second();
/**
* Returns the weekday of this instant in GMT. Sunday is 0, Monday is 1, etc.
*/
public abstract int weekday();
/**
* Returns this instant as "clicks", i.e. as milliseconds since January 1, 1970, 00:00:00 GMT
*/
public abstract long clicks();
/**
* Returns if this instant interpreted as a Date in GMT belongs to a leap year.
*/
public abstract boolean isLeapYear();
/**
* Returns the day of the week as a 3 letter abbreviation:
* `Sun`, `Mon`, `Tue`, `Wed`, `Thu`, `Fri` or `Sat`
*/
public abstract String weekdayStr();
/**
* Returns the month as a 3 letter abbreviation:
* `Jan`, `Feb`, `Mar`, `Apr`, `May`, `Jun`, `Jul`, `Aug`, `Sep`, `Oct`, `Nov` or `Dec`
*/
public abstract String monthStr();
/**
* Returns a String representation like this: `yyyy-mm-dd`
*/
public abstract String toIsoDateString();
/**
* Returns a String representation like this: `yyyy-mm-ddThh:mm:ss`
*/
public abstract String toIsoDateTimeString();
/**
* Returns a String representation like this: `yyyy-mm-dd hh:mm:ss`
*/
public abstract String toIsoLikeDateTimeString();
/**
* Returns an RFC1123 date string, e.g. `Sun, 06 Nov 1994 08:49:37 GMT`
*/
public abstract String toRfc1123DateTimeString();
/**
* Returns a new DateTime instance representing the current instant.
*/
public static DateTime now() {
return akka.http.scaladsl.model.DateTime.now();
}
/**
* Creates a new `DateTime` that represents the point in time the given number of ms earlier.
*/
public abstract DateTime minus(long millis);
/**
* Creates a new `DateTime` that represents the point in time the given number of ms later.
*/
public abstract DateTime plus(long millis);
/**
* Returns a new DateTime instance parsed from IsoDateTimeString as Some(dateTime). Returns None if
* parsing has failed.
*/
public static Optional<DateTime> fromIsoDateTimeString(String isoDateTimeString) {
return Util.<DateTime, akka.http.scaladsl.model.DateTime>convertOption(akka.http.scaladsl.model.DateTime.fromIsoDateTimeString(isoDateTimeString));
}
/**
* Returns a new DateTime instance representing the instant as defined by "clicks"
* i.e. from the number of milliseconds since the start of "the epoch", namely
* January 1, 1970, 00:00:00 GMT.
* Note that this implementation discards milliseconds (i.e. rounds down to full seconds).
*/
public static DateTime create(long clicks) {
return akka.http.scaladsl.model.DateTime.apply(clicks);
}
/**
* Returns a new DateTime instance by interpreting the given date/time components as an instant in GMT.
*/
public static DateTime create(int year, int month, int day, int hour, int minute, int second) {
return akka.http.scaladsl.model.DateTime.apply(year, month, day, hour, minute, second);
}
}