Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #134 from llorllale/133
Browse files Browse the repository at this point in the history
(#133) TimeTrackEntry.date does not consider difference between user and server timezones
  • Loading branch information
llorllale committed Jan 10, 2018
2 parents 576cc50 + ca4768f commit c165d67
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.time.Duration;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Optional;
import java.util.stream.Stream;

Expand Down Expand Up @@ -174,7 +173,7 @@ public Xml asXml() {
.append("<date>")
.append(String.valueOf(
this.date.atStartOfDay()
.atZone(ZoneId.systemDefault())
.atZone(YouTrack.ZONE_ID)
.toInstant()
.toEpochMilli()
)
Expand Down
Expand Up @@ -19,7 +19,6 @@
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Optional;

/**
Expand Down Expand Up @@ -55,7 +54,7 @@ public LocalDate date() {
Long.parseLong(
this.xml.textOf("date").get()
)
).atZone(ZoneId.systemDefault())
).atZone(YouTrack.ZONE_ID)
.toLocalDate();
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/llorllale/youtrack/api/YouTrack.java
Expand Up @@ -16,13 +16,22 @@

package org.llorllale.youtrack.api;

import java.time.ZoneId;

/**
* Entry point for the YouTrack API.
*
* @author George Aristy (george.aristy@gmail.com)
* @since 0.4.0
*/
public interface YouTrack {
/**
* All date/time fields in YouTrack's API are expressed relative to this ZoneId.
*
* @since 1.0.0
*/
ZoneId ZONE_ID = ZoneId.of("GMT+0");

/**
* Access to the {@link Project projects} API.
*
Expand Down
Expand Up @@ -17,8 +17,10 @@
package org.llorllale.youtrack.api;

import java.time.Duration;
import java.time.LocalDate;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
import org.llorllale.youtrack.api.Issues.IssueSpec;
Expand All @@ -34,7 +36,6 @@
public class DefaultIssueTimeTrackingIT {
private static IntegrationTestsConfig config;
private static Session session;
private static Issue issue;

@BeforeClass
public static void setup() throws Exception {
Expand All @@ -44,25 +45,46 @@ public static void setup() throws Exception {
config.youtrackUrl(),
config.youtrackUserToken()
).login();

issue = new DefaultYouTrack(session)
.projects()
.stream()
.findFirst()
.get()
.issues()
.create(new IssueSpec(DefaultIssueTimeTrackingIT.class.getSimpleName(), "Description"));
}

@Test
public void createAndCountAll() throws Exception {
assertThat(
new DefaultIssueTimeTracking(session, issue)
new DefaultIssueTimeTracking(session, this.issue("createAndCountAll"))
.create(new EntrySpec(Duration.ofMinutes(45)))
.create(new EntrySpec(Duration.ofHours(1)))
.stream()
.count(),
is(2L)
);
}
}

/**
* Creates an entry with date and duration, and reads it back.
*
* @throws Exception
* @see <a href="https://github.com/llorllale/youtrack-api/issues/133">#133</a>
* @since 1.0.0
*/
@Test
public void createWithDateAndDuration() throws Exception {
final LocalDate date = LocalDate.now();
final Duration duration = Duration.ofMinutes(234);
assertTrue(
new DefaultIssueTimeTracking(session, this.issue("createWithDateAndDuration"))
.create(new EntrySpec(date, duration))
.stream()
.anyMatch(e -> date.equals(e.date()) && duration.equals(e.duration()))
);
}

private Issue issue(String description) throws Exception {
return new DefaultYouTrack(session)
.projects()
.stream()
.findFirst()
.get()
.issues()
.create(new IssueSpec(DefaultIssueTimeTrackingIT.class.getSimpleName(), description));
}
}
Expand Up @@ -58,7 +58,7 @@ public void date() {
assertThat(
new EntrySpec(LocalDate.now(), Duration.ZERO).asXml().textOf("/workItem/date"),
is(Optional.of(String.valueOf(
LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
LocalDate.now().atStartOfDay().atZone(YouTrack.ZONE_ID).toInstant().toEpochMilli()
)))
);
}
Expand Down
Expand Up @@ -50,13 +50,16 @@ public void testIssue() {
);
}

/**
* @see <a href="https://github.com/llorllale/youtrack-api/issues/133">#133</a>
*/
@Test
public void testDate() {
assertThat(
new XmlTimeTrackEntry(issue(), xml).date(),
is(
Instant.ofEpochMilli(1480204800000L)
.atZone(ZoneId.systemDefault())
.atZone(YouTrack.ZONE_ID)
.toLocalDate()
)
);
Expand Down

0 comments on commit c165d67

Please sign in to comment.