Skip to content

Commit

Permalink
Merge pull request #1 from exxeleron/master
Browse files Browse the repository at this point in the history
Merge from origin
  • Loading branch information
maciejlach authored Jan 18, 2017
2 parents e230767 + 6b15c03 commit 26b6b5e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To get started, please <a href="https://www.clahub.com/agreements/exxeleron/qJava">sign the Contributor License Agreement</a>.
2 changes: 1 addition & 1 deletion src/main/java/com/exxeleron/qjava/QMinute.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static QMinute fromString( final String date ) {
final String[] parts = date.split(":");
final int hours = Integer.parseInt(parts[0]);
final int minutes = Integer.parseInt(parts[1]);
return new QMinute((minutes + 60 * Math.abs(hours)) * (hours > 0 ? 1 : -1));
return new QMinute((minutes + 60 * Math.abs(hours)) * ('-' == date.charAt(0) ? -1 : 1));
} catch ( final Exception e ) {
throw new IllegalArgumentException("Cannot parse QMinute from: " + date, e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/exxeleron/qjava/QSecond.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static QSecond fromString( final String date ) {
final int hours = Integer.parseInt(parts[0]);
final int minutes = Integer.parseInt(parts[1]);
final int seconds = Integer.parseInt(parts[2]);
return new QSecond((seconds + 60 * minutes + 3600 * Math.abs(hours)) * (hours > 0 ? 1 : -1));
return new QSecond((seconds + 60 * minutes + 3600 * Math.abs(hours)) * ('-' == date.charAt(0) ? -1 : 1));
} catch ( final Exception e ) {
throw new IllegalArgumentException("Cannot parse QSecond from: " + date, e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/exxeleron/qjava/QTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static QTime fromString( final String date ) {
final int minutes = Integer.parseInt(parts[1]);
final int seconds = Integer.parseInt(parts[2]);
final int millis = Integer.parseInt(parts[3]);
return new QTime((millis + 1000 * seconds + 60000 * minutes + 3600000 * Math.abs(hours)) * (hours > 0 ? 1 : -1));
return new QTime((millis + 1000 * seconds + 60000 * minutes + 3600000 * Math.abs(hours)) * ('-' == date.charAt(0) ? -1 : 1));
} catch ( final Exception e ) {
throw new IllegalArgumentException("Cannot parse QTime from: " + date, e);
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/exxeleron/qjava/TestDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public void testQMinute() {
public void testQMinuteToString() {
assertEquals("00:00", new QMinute(0).toString());
assertEquals("13:30", new QMinute(810).toString());
assertEquals("-13:30", new QMinute(-810).toString());
assertEquals("23:59", new QMinute(1439).toString());

assertEquals("-13:30", new QMinute(-810).toString());
Expand All @@ -177,6 +178,8 @@ public void testQMinuteToString() {
@Test
public void testQMinuteFromString() {
assertEquals(new QMinute(0), QMinute.fromString("00:00"));
assertEquals(new QMinute(12), QMinute.fromString("00:12"));
assertEquals(new QMinute(-12), QMinute.fromString("-00:12"));
assertEquals(new QMinute(810), QMinute.fromString("13:30"));
assertEquals(new QMinute(1439), QMinute.fromString("23:59"));

Expand Down Expand Up @@ -270,6 +273,7 @@ public void testQSecond() {
public void testQSecondToString() {
assertEquals("00:00:00", new QSecond(0).toString());
assertEquals("13:30:13", new QSecond(48613).toString());
assertEquals("-13:30:13", new QSecond(-48613).toString());
assertEquals("23:59:59", new QSecond(86399).toString());

assertEquals("51:46:39", new QSecond(186399).toString());
Expand All @@ -281,6 +285,8 @@ public void testQSecondToString() {
@Test
public void testQSecondFromString() {
assertEquals(new QSecond(0), QSecond.fromString("00:00:00"));
assertEquals(new QSecond(70), QSecond.fromString("00:01:10"));
assertEquals(new QSecond(-70), QSecond.fromString("-00:01:10"));
assertEquals(new QSecond(48613), QSecond.fromString("13:30:13"));
assertEquals(new QSecond(86399), QSecond.fromString("23:59:59"));

Expand Down Expand Up @@ -321,6 +327,7 @@ public void testQTime() {
@Test
public void testQTimeToString() {
assertEquals("00:00:00.000", new QTime(0).toString());
assertEquals("-13:30:13.000", new QTime(-48613000).toString());
assertEquals("13:30:13.000", new QTime(48613000).toString());
assertEquals("23:59:59.001", new QTime(86399001).toString());

Expand All @@ -334,6 +341,8 @@ public void testQTimeToString() {
public void testQTimeFromString() {
assertEquals(new QTime(48613000), QTime.fromString("13:30:13.000"));
assertEquals(new QTime(0), QTime.fromString("00:00:00.000"));
assertEquals(new QTime(10000), QTime.fromString("00:00:10.000"));
assertEquals(new QTime(-10000), QTime.fromString("-00:00:10.000"));
assertEquals(new QTime(86399000), QTime.fromString("23:59:59.000"));

assertEquals(new QTime(186399001), QTime.fromString("51:46:39.001"));
Expand Down

0 comments on commit 26b6b5e

Please sign in to comment.