Commit 6c7231f1 authored by Greg Messner's avatar Greg Messner
Browse files

Fixed time estimate parsing to follow GitLab standards (#114).

parent c4721cc5
...@@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep ...@@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep
```java ```java
dependencies { dependencies {
... ...
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.7.7' compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.7.8'
} }
``` ```
...@@ -20,7 +20,7 @@ dependencies { ...@@ -20,7 +20,7 @@ dependencies {
<dependency> <dependency>
<groupId>org.gitlab4j</groupId> <groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId> <artifactId>gitlab4j-api</artifactId>
<version>4.7.7</version> <version>4.7.8</version>
</dependency> </dependency>
``` ```
...@@ -89,6 +89,18 @@ List<Commit> allCommits = new ArrayList<>(commitPager.getTotalItems()); ...@@ -89,6 +89,18 @@ List<Commit> allCommits = new ArrayList<>(commitPager.getTotalItems());
while (commitPager.hasNext()) while (commitPager.hasNext())
allCommits.addAll(commitPager.next()); allCommits.addAll(commitPager.next());
``` ```
---
## Issue Time Estimates
GitLab issues allow for time tracking. The following time units are currently available:
months (mo)
weeks (w)
days (d)
hours (h)
minutes (m)
Conversion rates are 1mo = 4w, 1w = 5d and 1d = 8h.
--- ---
## Making API Calls ## Making API Calls
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. 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.
......
...@@ -6,7 +6,14 @@ import java.util.regex.Pattern; ...@@ -6,7 +6,14 @@ import java.util.regex.Pattern;
public class DurationUtils { public class DurationUtils {
private static final String[] TIME_UNITS = { "mo", "w", "d", "h", "m", "s" }; private static final String[] TIME_UNITS = { "mo", "w", "d", "h", "m", "s" };
private static final int[] TIME_UNIT_MULTIPLIERS = { 60 * 60 * 24 * 30, 60 * 60 * 24 * 7, 60 * 60 * 24, 60 * 60, 60, 1 }; private static final int[] TIME_UNIT_MULTIPLIERS = {
60 * 60 * 8 * 5 * 4, // 4 weeks = 1 month
60 * 60 * 8 * 5, // 5 days = 1 week
60 * 60 * 8, // 8 hours = 1 day
60 * 60, // 60 minutes = 1 hours
60, // 60 seconds = 1 minute
1
};
private static Pattern durationPattern = Pattern.compile("(\\s*(\\d+)(mo|[wdhms]))"); private static Pattern durationPattern = Pattern.compile("(\\s*(\\d+)(mo|[wdhms]))");
/** /**
......
...@@ -12,13 +12,13 @@ public class TestDuration { ...@@ -12,13 +12,13 @@ public class TestDuration {
public void testParse() { public void testParse() {
int seconds = DurationUtils.parse("7mo1w1d1h1m1s"); int seconds = DurationUtils.parse("7mo1w1d1h1m1s");
assertEquals(60 * 60 * 24 * 30 * 7 + 60 * 60 * 24 * 7 + 60 * 60 * 24 + 60 * 60 + 60 + 1, seconds); assertEquals(60 * 60 * 8 * 5 * 4 * 7 + 60 * 60 * 8 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("1w1d1h1m1s"); seconds = DurationUtils.parse("1w1d1h1m1s");
assertEquals(60 * 60 * 24 * 7 + 60 * 60 * 24 + 60 * 60 + 60 + 1, seconds); assertEquals(60 * 60 * 8 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("1d1h1m1s"); seconds = DurationUtils.parse("1d1h1m1s");
assertEquals(60 * 60 * 24 + 60 * 60 + 60 + 1, seconds); assertEquals(60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("60m"); seconds = DurationUtils.parse("60m");
assertEquals(60 * 60, seconds); assertEquals(60 * 60, seconds);
...@@ -27,6 +27,25 @@ public class TestDuration { ...@@ -27,6 +27,25 @@ public class TestDuration {
assertEquals(60 * 60, seconds); assertEquals(60 * 60, seconds);
} }
@Test
public void testParseWithSpaces() {
int seconds = DurationUtils.parse("5w 1d 1h 1m 1s");
assertEquals(60 * 60 * 8 * 5 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("1w 1d 1h 1m 1s");
assertEquals(60 * 60 * 8 * 5 + 60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("1d 1h 1m 1s");
assertEquals(60 * 60 * 8 + 60 * 60 + 60 + 1, seconds);
seconds = DurationUtils.parse("60m");
assertEquals(60 * 60, seconds);
seconds = DurationUtils.parse("2h");
assertEquals(60 * 60 * 2, seconds);
}
@Test @Test
public void testBadParse() { public void testBadParse() {
...@@ -75,13 +94,13 @@ public class TestDuration { ...@@ -75,13 +94,13 @@ public class TestDuration {
duration = DurationUtils.toString(60 * 60 + 60 + 1); duration = DurationUtils.toString(60 * 60 + 60 + 1);
assertEquals("1h1m1s", duration); assertEquals("1h1m1s", duration);
duration = DurationUtils.toString(60 * 60 * 24 + 60 * 60 * 2 + 60 * 3 + 4); duration = DurationUtils.toString(60 * 60 * 8 + 60 * 60 * 2 + 60 * 3 + 4);
assertEquals("1d2h3m4s", duration); assertEquals("1d2h3m4s", duration);
duration = DurationUtils.toString(60 * 60 * 24 * 7 + 60 * 60 * 24 * 2 + 60 * 60 * 3 + 60 * 4 + 5); duration = DurationUtils.toString(60 * 60 * 8 * 5 + 60 * 60 * 8 * 2 + 60 * 60 * 3 + 60 * 4 + 5);
assertEquals("1w2d3h4m5s", duration); assertEquals("1w2d3h4m5s", duration);
duration = DurationUtils.toString(60 * 60 * 24 * 30 * 3 + 60 * 60 * 24 * 2 + 60 * 60 * 3 + 60 * 6 + 8); duration = DurationUtils.toString(60 * 60 * 8 * 5 * 4 * 3 + 60 * 60 * 8 * 2 + 60 * 60 * 3 + 60 * 6 + 8);
assertEquals("3mo2d3h6m8s", duration); assertEquals("3mo2d3h6m8s", duration);
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment