fr.quatrevieux.araknemu.util.DofusDate   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 40
ccs 8
cts 11
cp 0.7272
c 0
b 0
f 0
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A DofusDate() 0 3 1
A fromDuration(long) 0 6 1
A month() 0 2 1
A day() 0 2 1
A toMilliseconds() 0 2 1
A year() 0 2 1
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.util;
21
22
import java.util.Calendar;
23
24
/**
25
 * Handle date for Dofus server
26
 */
27
public final class DofusDate {
28
    public static final int YEAR_OFFSET = -1370;
29
30
    private final Calendar calendar;
31
32 1
    public DofusDate() {
33 1
        calendar = Calendar.getInstance();
34 1
        calendar.add(Calendar.YEAR, YEAR_OFFSET);
35 1
    }
36
37
    /**
38
     * Get the date to milliseconds
39
     */
40
    public long toMilliseconds() {
41 1
        return calendar.getTimeInMillis() + calendar.get(Calendar.ZONE_OFFSET);
42
    }
43
44
    public int year() {
45
        return calendar.get(Calendar.YEAR);
46
    }
47
48
    public int month() {
49
        return calendar.get(Calendar.MONTH) + 1;
50
    }
51
52
    public int day() {
53
        return calendar.get(Calendar.DAY_OF_MONTH);
54
    }
55
56
    /**
57
     * Create a new past date from duration in milliseconds
58
     *
59
     * @param duration The duration in milliseconds
60
     */
61
    public static DofusDate fromDuration(long duration) {
62 1
        final DofusDate date = new DofusDate();
63
64 1
        date.calendar.setTimeInMillis(date.calendar.getTimeInMillis() - duration);
65
66 1
        return date;
67
    }
68
}
69