Skip to content

Commit

Permalink
Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
aozarov committed Feb 11, 2015
1 parent 0ae2558 commit 56b6455
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/datastore/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Calendar toCalendar() {
}

public static DateTime now() {
return new DateTime(System.nanoTime() / 1000L);
return copyFrom(new Date());
}

public static DateTime copyFrom(Date date) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.google.gcloud.datastore;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertNotEquals;import static org.junit.Assert.assertTrue;import org.junit.Test;import java.util.Calendar;public class DateTimeTest { @Test public void testTimestampMicroseconds() throws Exception { Calendar cal = Calendar.getInstance(); DateTime date = DateTime.copyFrom(cal); assertEquals(cal.getTimeInMillis() * 1000, date.timestampMicroseconds()); } @Test public void testTimestampMillis() throws Exception { Calendar cal = Calendar.getInstance(); DateTime date = DateTime.copyFrom(cal); assertEquals(cal.getTimeInMillis(), date.timestampMillis()); } @Test public void testToDate() throws Exception { Calendar cal = Calendar.getInstance(); DateTime date = DateTime.copyFrom(cal); assertEquals(cal.getTime(), date.toDate()); } @Test public void testToCalendar() throws Exception { Calendar cal = Calendar.getInstance(); DateTime date = DateTime.copyFrom(cal); assertEquals(cal, date.toCalendar()); } @Test public void testNow() throws Exception { Calendar cal1 = Calendar.getInstance(); DateTime now = DateTime.now(); Calendar cal2 = Calendar.getInstance(); assertTrue(now.timestampMillis() >= cal1.getTimeInMillis()); assertTrue(now.timestampMillis() <= cal2.getTimeInMillis()); } @Test public void testCopyFrom() throws Exception { Calendar cal = Calendar.getInstance(); DateTime date1 = DateTime.copyFrom(cal); DateTime date2 = DateTime.copyFrom(cal.getTime()); cal.add(Calendar.DATE, 1); DateTime date3 = DateTime.copyFrom(cal.getTime()); assertEquals(date1, date2); assertNotEquals(date1, date3); }}
Expand Down

0 comments on commit 56b6455

Please sign in to comment.