public long mark(String label, long time) { TimeEntry entry = new TimeEntry(); entry.label = label; entry.time = time; entries.add(entry); return entry.time; }
public void addEntry(TimeEntry entry) { ContentValues values = new ContentValues(); values.put(TimeEntryContract.TimeEntry.COLUMN_NAME_DATE, entry.getFormattedDate()); values.put(TimeEntryContract.TimeEntry.COLUMN_NAME_HOURS, entry.getHours()); getDb().insert(TimeEntryContract.TimeEntry.TABLE_NAME, null, values); }
public long mark(String label) { TimeEntry entry = new TimeEntry(); entry.label = label; entry.time = System.currentTimeMillis(); entries.add(entry); return entry.time; }
@Test public void updateTimeEntry() { final String DESCRIPTION = "ABC"; timeEntry.setDescription(DESCRIPTION); TimeEntry te = jToggl.updateTimeEntry(timeEntry); Assert.assertNotNull(te); Assert.assertEquals(DESCRIPTION, te.getDescription()); }
private static void generateXMLForTimeEntry() { TimeEntry o = new TimeEntry(); o.setId(13); o.setIssueId(45); o.setActivityId(3); o.setProjectId(55); o.setUserId(66); o.setHours(123f); o.setComment("text here"); o.setSpentOn(new Date()); String xml = RedmineXMLGenerator.toXML(o); logger.debug(xml); }
public void resume() { switch (status) { case PAUSED: long now = now(); global.resume(now); for (TimeEntry entry : splitStack) { entry.resume(now); } status = Status.RUN; break; case RUN: // no-op; break; default: throw new IllegalArgumentException("unknow status: " + status); } }
@AfterClass public static void afterClass() throws Exception { jToggl.destroyTimeEntry(timeEntry.getId()); jToggl.destroyClient(client.getId()); try { jToggl.destroyTask(task.getId()); } catch (Exception e) { // Ignore because Task is only for paying customers } }
public void split(String name) { TimeEntry entry = new TimeEntry(); entry.name = name; if (!splitNameCache.contains(name)) { splitNameCache.add(name); } switch (status) { case PAUSED: entry.reset(); splitStack.add(entry); break; case RUN: splitStack.add(entry); // set time later entry.resume(now()); break; default: throw new IllegalArgumentException("unknow status: " + status); } }
private long[] getSplitsByName(String name, long now) { List<Long> list = times.get(name); TimeEntry inSplitting = null; for (TimeEntry entry : splitStack) { if (entry.name.equals(name)) { inSplitting = entry; } } long[] ret = new long[(list == null ? 0 : list.size()) + (inSplitting == null ? 0 : 1)]; if (list != null) { int i = 0; for (long l : list) { ret[i] = l; i++; } } if (inSplitting != null) { ret[ret.length - 1] = inSplitting.total(now); } return ret; }
public void unsplit() { long now = now(); TimeEntry timeEntry = splitStack.peek(); if (timeEntry != null) { splitStack.pop(); } else { return; } switch (status) { case RUN: timeEntry.pause(now); case PAUSED: List<Long> list = times.get(timeEntry.name); if (list == null) { list = new ArrayList<Long>(); times.put(timeEntry.name, list); } list.add(timeEntry.total(now)); break; default: throw new IllegalArgumentException("unknow status: " + status); } }
private long total(String name, long now, TimeUnit unit) { switch (status) { case PAUSED: case RUN: long d = 0L; if (name == null) { d = global.total(now); } else { long[] entries = getSplitsByName(name, now); for (long entry : entries) { d += entry; } } return unit.convert(d, UNIT); default: throw new IllegalArgumentException("unknow status: " + status); } }
private static TimeEntry createTimeEntry() throws Exception { TimeEntry entry = new TimeEntry(); entry.setDuration(480); entry.setBillable(true); ZoneId tz = TimeZone.getTimeZone("Europe/Moscow").toZoneId(); ZonedDateTime start = ZonedDateTime.of(2011, 10, 15, 8, 0, 0, 0, tz); entry.setStart(start); ZonedDateTime stop = ZonedDateTime.of(2011, 10, 15, 16, 0, 0, 0, tz); entry.setStop(stop); entry.setDescription("From JUnit Test"); entry.setCreated_with("JUnit"); entry = jToggl.createTimeEntry(entry); Assert.assertNotNull(entry); return entry; }
@Test public void getTimeEntriesWithRange2() { List<TimeEntry> entries = jToggl.getTimeEntries(timeEntry.getStart(), timeEntry.getStop()); Assert.assertTrue(!entries.isEmpty()); }
@Test public void startStopTimeEntry() throws Exception { TimeEntry current = jToggl.getCurrentTimeEntry(); Assert.assertNull(current); TimeEntry timeEntry = new TimeEntry(); timeEntry.setWorkspace(workspace); timeEntry.setProject(project); timeEntry.setDescription("ABCD"); timeEntry.setCreated_with("JToggl Unit Test"); TimeEntry te = jToggl.startTimeEntry(timeEntry); try { Assert.assertNotNull(te.getId()); // created Assert.assertTrue(te.getDuration() < 0); // running current = jToggl.getCurrentTimeEntry(); Assert.assertNotNull(current); Assert.assertEquals(current.getId(), te.getId()); Thread.sleep(2000); TimeEntry stoppedTe = jToggl.stopTimeEntry(te); Assert.assertEquals(te.getId(), stoppedTe.getId()); Assert.assertTrue(stoppedTe.toJSONString(), stoppedTe.getDuration() > 1); // stopped current = jToggl.getCurrentTimeEntry(); Assert.assertNull(current); } finally { jToggl.destroyTimeEntry(te.getId()); } }
@Test public void getTimeEntry() { TimeEntry te = jToggl.getTimeEntry(timeEntry.getId()); Assert.assertNotNull(te); }
public void reset() { status = Status.PAUSED; global.reset(); times.clear(); splitStack.clear(); }