Skip to content

Commit 6c7231f

Browse files
committed
Fixed time estimate parsing to follow GitLab standards (#114).
1 parent c4721cc commit 6c7231f

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep
1111
```java
1212
dependencies {
1313
...
14-
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.7.7'
14+
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.7.8'
1515
}
1616
```
1717

@@ -20,7 +20,7 @@ dependencies {
2020
<dependency>
2121
<groupId>org.gitlab4j</groupId>
2222
<artifactId>gitlab4j-api</artifactId>
23-
<version>4.7.7</version>
23+
<version>4.7.8</version>
2424
</dependency>
2525
```
2626

@@ -89,6 +89,18 @@ List<Commit> allCommits = new ArrayList<>(commitPager.getTotalItems());
8989
while (commitPager.hasNext())
9090
allCommits.addAll(commitPager.next());
9191
```
92+
---
93+
## Issue Time Estimates
94+
GitLab issues allow for time tracking. The following time units are currently available:
95+
96+
months (mo)
97+
weeks (w)
98+
days (d)
99+
hours (h)
100+
minutes (m)
101+
102+
Conversion rates are 1mo = 4w, 1w = 5d and 1d = 8h.
103+
92104
---
93105
## Making API Calls
94106
The API has been broken up into sub APIs classes to make it easier to learn and to separate concerns. Following is a list of the sub APIs along with a sample use of each API. See the <a href="http://www.messners.com/gitlab4j-api/javadocs/index.html?org/gitlab4j/api/package-summary.html" target="_top">Javadocs</a> for a complete list of available methods for each sub API.

src/main/java/org/gitlab4j/api/utils/DurationUtils.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
public class DurationUtils {
77

88
private static final String[] TIME_UNITS = { "mo", "w", "d", "h", "m", "s" };
9-
private static final int[] TIME_UNIT_MULTIPLIERS = { 60 * 60 * 24 * 30, 60 * 60 * 24 * 7, 60 * 60 * 24, 60 * 60, 60, 1 };
9+
private static final int[] TIME_UNIT_MULTIPLIERS = {
10+
60 * 60 * 8 * 5 * 4, // 4 weeks = 1 month
11+
60 * 60 * 8 * 5, // 5 days = 1 week
12+
60 * 60 * 8, // 8 hours = 1 day
13+
60 * 60, // 60 minutes = 1 hours
14+
60, // 60 seconds = 1 minute
15+
1
16+
};
1017
private static Pattern durationPattern = Pattern.compile("(\\s*(\\d+)(mo|[wdhms]))");
1118

1219
/**

src/test/java/org/gitlab4j/api/TestDuration.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public class TestDuration {
1212
public void testParse() {
1313

1414
int seconds = DurationUtils.parse("7mo1w1d1h1m1s");
15-
assertEquals(60 * 60 * 24 * 30 * 7 + 60 * 60 * 24 * 7 + 60 * 60 * 24 + 60 * 60 + 60 + 1, seconds);
15+
assertEquals(60 * 60 * 8 * 5 * 4 * 7 + 60 * 60 * 8 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
1616

1717
seconds = DurationUtils.parse("1w1d1h1m1s");
18-
assertEquals(60 * 60 * 24 * 7 + 60 * 60 * 24 + 60 * 60 + 60 + 1, seconds);
18+
assertEquals(60 * 60 * 8 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
1919

2020
seconds = DurationUtils.parse("1d1h1m1s");
21-
assertEquals(60 * 60 * 24 + 60 * 60 + 60 + 1, seconds);
21+
assertEquals(60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
2222

2323
seconds = DurationUtils.parse("60m");
2424
assertEquals(60 * 60, seconds);
@@ -27,6 +27,25 @@ public void testParse() {
2727
assertEquals(60 * 60, seconds);
2828
}
2929

30+
@Test
31+
public void testParseWithSpaces() {
32+
33+
int seconds = DurationUtils.parse("5w 1d 1h 1m 1s");
34+
assertEquals(60 * 60 * 8 * 5 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
35+
36+
seconds = DurationUtils.parse("1w 1d 1h 1m 1s");
37+
assertEquals(60 * 60 * 8 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
38+
39+
seconds = DurationUtils.parse("1d 1h 1m 1s");
40+
assertEquals(60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
41+
42+
seconds = DurationUtils.parse("60m");
43+
assertEquals(60 * 60, seconds);
44+
45+
seconds = DurationUtils.parse("2h");
46+
assertEquals(60 * 60 * 2, seconds);
47+
}
48+
3049
@Test
3150
public void testBadParse() {
3251

@@ -75,13 +94,13 @@ public void testToString() {
7594
duration = DurationUtils.toString(60 * 60 + 60 + 1);
7695
assertEquals("1h1m1s", duration);
7796

78-
duration = DurationUtils.toString(60 * 60 * 24 + 60 * 60 * 2 + 60 * 3 + 4);
97+
duration = DurationUtils.toString(60 * 60 * 8 + 60 * 60 * 2 + 60 * 3 + 4);
7998
assertEquals("1d2h3m4s", duration);
8099

81-
duration = DurationUtils.toString(60 * 60 * 24 * 7 + 60 * 60 * 24 * 2 + 60 * 60 * 3 + 60 * 4 + 5);
100+
duration = DurationUtils.toString(60 * 60 * 8 * 5 + 60 * 60 * 8 * 2 + 60 * 60 * 3 + 60 * 4 + 5);
82101
assertEquals("1w2d3h4m5s", duration);
83102

84-
duration = DurationUtils.toString(60 * 60 * 24 * 30 * 3 + 60 * 60 * 24 * 2 + 60 * 60 * 3 + 60 * 6 + 8);
103+
duration = DurationUtils.toString(60 * 60 * 8 * 5 * 4 * 3 + 60 * 60 * 8 * 2 + 60 * 60 * 3 + 60 * 6 + 8);
85104
assertEquals("3mo2d3h6m8s", duration);
86105
}
87106
}

0 commit comments

Comments
 (0)