• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trydofor / professional-mirana / #68

31 Aug 2024 02:56AM UTC coverage: 84.4% (+1.0%) from 83.382%
#68

push

web-flow
Merge pull request #45 from trydofor/develop

v2.7.3 with minor change

474 of 568 new or added lines in 27 files covered. (83.45%)

8 existing lines in 6 files now uncovered.

5237 of 6205 relevant lines covered (84.4%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/src/main/java/pro/fessional/mirana/time/DateNumber.java
1
package pro.fessional.mirana.time;
2

3
import org.jetbrains.annotations.NotNull;
4

5
import java.time.LocalDate;
6
import java.time.LocalDateTime;
7
import java.time.LocalTime;
8
import java.time.ZonedDateTime;
9

10

11
/**
12
 * <pre>
13
 * Bi-directional conversion of dates to numbers supports the following formats
14
 *
15
 * * date8 - yyyyMMdd
16
 * * datetime14 - yyyyMMddHHmmss
17
 * * datetime17 - yyyyMMddHHmmssSSS
18
 * * time6 - HHmmss
19
 * * time9 - HHmmssSSS
20
 *
21
 * All of the above date formats are supported for half-angle conversion when parsing.
22
 * </pre>
23
 *
24
 * @author trydofor
25
 * @see DateParser
26
 * @since 2017-02-06.
27
 */
UNCOV
28
public class DateNumber {
×
29

30
    /**
31
     * convert to yyyyMMdd
32
     */
33

34
    public static int date8(@NotNull LocalDate date) {
35
        return date.getYear() * 1_00_00 + date.getMonthValue() * 1_00 + date.getDayOfMonth();
1✔
36
    }
37

38
    /**
39
     * convert to yyyyMMdd
40
     */
41
    public static int date8(@NotNull LocalDateTime date) {
42
        return date.getYear() * 1_00_00 + date.getMonthValue() * 1_00 + date.getDayOfMonth();
1✔
43
    }
44

45
    /**
46
     * convert to yyyyMMdd
47
     */
48
    public static int date8(@NotNull ZonedDateTime date) {
49
        return date.getYear() * 1_00_00 + date.getMonthValue() * 1_00 + date.getDayOfMonth();
1✔
50
    }
51

52
    /**
53
     * convert to yyyyMMddHHmmss
54
     */
55

56
    public static long dateTime14(@NotNull LocalDateTime date) {
57
        return date.getYear() * 1_00_00_00_00_00L + date.getMonthValue() * 1_00_00_00_00L + date.getDayOfMonth() * 1_00_00_00L
1✔
58
               + date.getHour() * 1_00_00 + date.getMinute() * 1_00 + date.getSecond();
1✔
59
    }
60

61
    /**
62
     * convert to yyyyMMddHHmmss
63
     */
64
    public static long dateTime14(@NotNull ZonedDateTime date) {
65
        return date.getYear() * 1_00_00_00_00_00L + date.getMonthValue() * 1_00_00_00_00L + date.getDayOfMonth() * 1_00_00_00L
1✔
66
               + date.getHour() * 1_00_00L + date.getMinute() * 1_00L + date.getSecond();
1✔
67
    }
68

69
    /**
70
     * convert to yyyyMMddHHmmssSSS
71
     */
72

73
    public static long dateTime17(@NotNull LocalDateTime date) {
74
        return date.getYear() * 1_00_00_00_00_00_000L + date.getMonthValue() * 1_00_00_00_00_000L + date.getDayOfMonth() * 1_00_00_00_000L
1✔
75
               + date.getHour() * 1_00_00_000 + date.getMinute() * 1_00_000 + date.getSecond() * 1_000
1✔
76
               + (date.getNano() / 1_000_000);
1✔
77
    }
78

79
    /**
80
     * convert to yyyyMMddHHmmssSSS
81
     */
82

83
    public static long dateTime17(@NotNull ZonedDateTime date) {
84
        return date.getYear() * 1_00_00_00_00_00_000L + date.getMonthValue() * 1_00_00_00_00_000L + date.getDayOfMonth() * 1_00_00_00_000L
1✔
85
               + date.getHour() * 1_00_00_000L + date.getMinute() * 1_00_000L + date.getSecond() * 1_000L
1✔
86
               + (date.getNano() / 1_000_000);
1✔
87
    }
88

89
    /**
90
     * convert to HHmmss
91
     */
92
    public static int time6(@NotNull LocalTime date) {
93
        return date.getHour() * 1_00_00 + date.getMinute() * 1_00 + date.getSecond();
1✔
94
    }
95

96
    /**
97
     * convert to HHmmss
98
     */
99
    public static int time6(@NotNull LocalDateTime date) {
100
        return date.getHour() * 1_00_00 + date.getMinute() * 1_00 + date.getSecond();
1✔
101
    }
102

103
    /**
104
     * convert to HHmmss
105
     */
106
    public static int time6(@NotNull ZonedDateTime date) {
107
        return date.getHour() * 1_00_00 + date.getMinute() * 1_00 + date.getSecond();
1✔
108
    }
109

110
    /**
111
     * convert to HHmmssSSS
112
     */
113
    public static int time9(@NotNull LocalTime date) {
114
        return date.getHour() * 1_00_00_000 + date.getMinute() * 1_00_000 + date.getSecond() * 1_000 + (date.getNano() / 1_000_000);
1✔
115
    }
116

117
    /**
118
     * convert to HHmmssSSS
119
     */
120
    public static int time9(@NotNull LocalDateTime date) {
121
        return date.getHour() * 1_00_00_000 + date.getMinute() * 1_00_000 + date.getSecond() * 1_000 + (date.getNano() / 1_000_000);
1✔
122
    }
123

124
    /**
125
     * convert to HHmmssSSS
126
     */
127
    public static int time9(@NotNull ZonedDateTime date) {
128
        return date.getHour() * 1_00_00_000 + date.getMinute() * 1_00_000 + date.getSecond() * 1_000 + (date.getNano() / 1_000_000);
1✔
129
    }
130

131
    /**
132
     * convert any number with date information to a date
133
     */
134
    @NotNull
135
    public static LocalTime parseTime(long num) {
136
        return parseTime(num, 0);
1✔
137
    }
138

139
    /**
140
     * convert any number with date information to a date
141
     */
142
    @NotNull
143
    public static LocalDate parseDate(long num) {
144
        return parseDate(num, 0);
1✔
145
    }
146

147
    /**
148
     * convert any number with date information to a date
149
     */
150
    @NotNull
151
    public static LocalDateTime parseDateTime(long num) {
152
        return parseDateTime(num, 0);
1✔
153
    }
154

155
    /**
156
     * from the offset to convert any number with date information to a date
157
     */
158
    @NotNull
159
    public static LocalTime parseTime(long num, int off) {
160
        return DateParser.parseTime(String.valueOf(num), off);
1✔
161
    }
162

163
    /**
164
     * from the offset to convert any number with date information to a date
165
     */
166
    @NotNull
167
    public static LocalDate parseDate(long num, int off) {
168
        return DateParser.parseDate(String.valueOf(num), off);
1✔
169
    }
170

171
    /**
172
     * from the offset to convert any number with date information to a date
173
     */
174
    @NotNull
175
    public static LocalDateTime parseDateTime(long num, int off) {
176
        return DateParser.parseDateTime(String.valueOf(num), off);
1✔
177
    }
178
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc