List of usage examples for java.util Calendar MILLISECOND
int MILLISECOND
To view the source code for java.util Calendar MILLISECOND.
Click Source Link
get
and set
indicating the millisecond within the second. From source file:it.infn.ct.security.utilities.LDAPCleaner.java
private void stopUsers() { _log.info("Disable users who do not confirm the account extension"); Session session = factory.openSession(); session.beginTransaction();//from w w w . j ava 2 s.co m Calendar cal = GregorianCalendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Calendar calEnd = GregorianCalendar.getInstance(); calEnd.setTime(cal.getTime()); calEnd.add(Calendar.DAY_OF_YEAR, 1); Session ses = factory.openSession(); List lstUserUpdates = ses.createCriteria(UserConfirmUpdate.class) .add(Restrictions.between("timelimit", cal.getTime(), calEnd.getTime())) .add(Restrictions.eq("updated", Boolean.FALSE)).list(); for (UserConfirmUpdate ucu : (List<UserConfirmUpdate>) lstUserUpdates) { UserRequest ur = LDAPUtils.getUser(ucu.getUsername()); LDAPUtils.disableUser(ucu.getUsername()); sendUserRemainder(ur, 0); } ses.close(); session.getTransaction().commit(); session.close(); }
From source file:de.kurashigegollub.dev.gcatest.Utils.java
public static DateTime getDateTime2Weeks(DateTime dtFrom) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(dtFrom.getValue()); c.add(Calendar.WEEK_OF_YEAR, 2); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59);/*w ww . jav a 2s . co m*/ c.set(Calendar.SECOND, 59); c.set(Calendar.MILLISECOND, 999); return new DateTime(c.getTime(), TimeZone.getDefault()); }
From source file:org.flowable.rest.service.api.runtime.TaskCollectionResourceTest.java
/** * Test getting a collection of tasks. GET runtime/tasks */// w ww. j ava2 s. c o m @Deployment public void testGetTasks() throws Exception { try { Calendar adhocTaskCreate = Calendar.getInstance(); adhocTaskCreate.set(Calendar.MILLISECOND, 0); Calendar processTaskCreate = Calendar.getInstance(); processTaskCreate.add(Calendar.HOUR, 2); processTaskCreate.set(Calendar.MILLISECOND, 0); Calendar inBetweenTaskCreation = Calendar.getInstance(); inBetweenTaskCreation.add(Calendar.HOUR, 1); processEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime()); Task adhocTask = taskService.newTask(); adhocTask.setAssignee("gonzo"); adhocTask.setOwner("owner"); adhocTask.setDelegationState(DelegationState.PENDING); adhocTask.setDescription("Description one"); adhocTask.setName("Name one"); adhocTask.setDueDate(adhocTaskCreate.getTime()); adhocTask.setPriority(100); adhocTask.setCategory("some-category"); taskService.saveTask(adhocTask); taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT); processEngineConfiguration.getClock().setCurrentTime(processTaskCreate.getTime()); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey"); Task processTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()) .singleResult(); processTask.setParentTaskId(adhocTask.getId()); processTask.setPriority(50); processTask.setDueDate(processTaskCreate.getTime()); taskService.saveTask(processTask); runtimeService.setVariable(processInstance.getId(), "variable", "globaltest"); taskService.setVariableLocal(processTask.getId(), "localVariable", "localtest"); // Check filter-less to fetch all tasks String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION); assertResultsPresentInDataResponse(url, adhocTask.getId(), processTask.getId()); // Name filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?name=" + encode("Name one"); assertResultsPresentInDataResponse(url, adhocTask.getId()); // Name like filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?nameLike=" + encode("%one"); assertResultsPresentInDataResponse(url, adhocTask.getId()); // Description filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?description=" + encode("Description one"); assertResultsPresentInDataResponse(url, adhocTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?description=" + encode("Description two"); assertEmptyResultsPresentInDataResponse(url); // Description like filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?descriptionLike=" + encode("%one"); assertResultsPresentInDataResponse(url, adhocTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?descriptionLike=" + encode("%two"); assertEmptyResultsPresentInDataResponse(url); // Priority filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?priority=100"; assertResultsPresentInDataResponse(url, adhocTask.getId()); // Mininmum Priority filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?minimumPriority=70"; assertResultsPresentInDataResponse(url, adhocTask.getId()); // Maximum Priority filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?maximumPriority=70"; assertResultsPresentInDataResponse(url, processTask.getId()); // Owner filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?owner=owner"; assertResultsPresentInDataResponse(url, adhocTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?owner=kermit"; assertEmptyResultsPresentInDataResponse(url); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?ownerLike=" + encode("%ner"); assertResultsPresentInDataResponse(url, adhocTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?ownerLike=" + encode("kerm%"); assertEmptyResultsPresentInDataResponse(url); // Assignee filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assignee=gonzo"; assertResultsPresentInDataResponse(url, adhocTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assignee=kermit"; assertEmptyResultsPresentInDataResponse(url); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assigneeLike=" + encode("gon%"); assertResultsPresentInDataResponse(url, adhocTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assigneeLike=" + encode("kerm%"); assertEmptyResultsPresentInDataResponse(url); // Unassigned filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?unassigned=true"; assertResultsPresentInDataResponse(url, processTask.getId()); // Delegation state filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?delegationState=pending"; assertResultsPresentInDataResponse(url, adhocTask.getId()); // Candidate user filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?candidateUser=kermit"; assertResultsPresentInDataResponse(url, processTask.getId()); // Candidate group filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?candidateGroup=sales"; assertResultsPresentInDataResponse(url, processTask.getId()); // Involved user filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?involvedUser=misspiggy"; assertResultsPresentInDataResponse(url, adhocTask.getId()); // Process instance filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processInstanceId=" + processInstance.getId(); assertResultsPresentInDataResponse(url, processTask.getId()); // Execution filtering Execution taskExecution = runtimeService.createExecutionQuery().activityId("processTask") .singleResult(); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?executionId=" + taskExecution.getId(); assertResultsPresentInDataResponse(url, processTask.getId()); // Process instance businesskey filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processInstanceBusinessKey=myBusinessKey"; assertResultsPresentInDataResponse(url, processTask.getId()); // CreatedOn filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdOn=" + getISODateString(adhocTaskCreate.getTime()); assertResultsPresentInDataResponse(url, adhocTask.getId()); // CreatedAfter filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdAfter=" + getISODateString(inBetweenTaskCreation.getTime()); assertResultsPresentInDataResponse(url, processTask.getId()); // CreatedBefore filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdBefore=" + getISODateString(inBetweenTaskCreation.getTime()); assertResultsPresentInDataResponse(url, adhocTask.getId()); // Subtask exclusion url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?excludeSubTasks=true"; assertResultsPresentInDataResponse(url, adhocTask.getId()); // Task definition key filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?taskDefinitionKey=processTask"; assertResultsPresentInDataResponse(url, processTask.getId()); // Task definition key like filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?taskDefinitionKeyLike=" + encode("process%"); assertResultsPresentInDataResponse(url, processTask.getId()); // Duedate filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueDate=" + getISODateString(adhocTaskCreate.getTime()); assertResultsPresentInDataResponse(url, adhocTask.getId()); // Due after filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueAfter=" + getISODateString(inBetweenTaskCreation.getTime()); assertResultsPresentInDataResponse(url, processTask.getId()); // Due before filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueBefore=" + getISODateString(inBetweenTaskCreation.getTime()); assertResultsPresentInDataResponse(url, adhocTask.getId()); // Without tenantId filtering before tenant set url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url, adhocTask.getId(), processTask.getId()); // Process definition url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processDefinitionKey=" + processInstance.getProcessDefinitionKey(); assertResultsPresentInDataResponse(url, processTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId(); assertResultsPresentInDataResponse(url, processTask.getId()); // Set tenant on deployment managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant")); // Without tenantId filtering after tenant set, only adhoc task // should remain url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url, adhocTask.getId()); // Tenant id filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?tenantId=myTenant"; assertResultsPresentInDataResponse(url, processTask.getId()); // Tenant id like filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?tenantIdLike=" + encode("%enant"); assertResultsPresentInDataResponse(url, processTask.getId()); // Category filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?category=" + encode("some-category"); assertResultsPresentInDataResponse(url, adhocTask.getId()); // Suspend process-instance to have a suspended task runtimeService.suspendProcessInstanceById(processInstance.getId()); // Suspended filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?active=false"; assertResultsPresentInDataResponse(url, processTask.getId()); // Active filtering url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?active=true"; assertResultsPresentInDataResponse(url, adhocTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?includeTaskLocalVariables=true"; CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); // Check status and size JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); Assert.assertEquals(2, dataNode.size()); Map<String, JsonNode> taskNodeMap = new HashMap<>(); for (JsonNode taskNode : dataNode) { taskNodeMap.put(taskNode.get("id").asText(), taskNode); } Assert.assertTrue(taskNodeMap.containsKey(processTask.getId())); JsonNode processTaskNode = taskNodeMap.get(processTask.getId()); JsonNode variablesNode = processTaskNode.get("variables"); assertEquals(1, variablesNode.size()); JsonNode variableNode = variablesNode.get(0); assertEquals("localVariable", variableNode.get("name").asText()); assertEquals("local", variableNode.get("scope").asText()); assertEquals("localtest", variableNode.get("value").asText()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?includeTaskLocalVariables=true&includeProcessVariables=true"; response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); // Check status and size dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); Assert.assertEquals(2, dataNode.size()); taskNodeMap = new HashMap<>(); for (JsonNode taskNode : dataNode) { taskNodeMap.put(taskNode.get("id").asText(), taskNode); } Assert.assertTrue(taskNodeMap.containsKey(processTask.getId())); processTaskNode = taskNodeMap.get(processTask.getId()); variablesNode = processTaskNode.get("variables"); assertEquals(2, variablesNode.size()); Map<String, JsonNode> variableMap = new HashMap<>(); for (JsonNode variableResponseNode : variablesNode) { variableMap.put(variableResponseNode.get("name").asText(), variableResponseNode); } variableNode = variableMap.get("localVariable"); assertEquals("localVariable", variableNode.get("name").asText()); assertEquals("local", variableNode.get("scope").asText()); assertEquals("localtest", variableNode.get("value").asText()); variableNode = variableMap.get("variable"); assertEquals("variable", variableNode.get("name").asText()); assertEquals("global", variableNode.get("scope").asText()); assertEquals("globaltest", variableNode.get("value").asText()); } finally { // Clean adhoc-tasks even if test fails List<Task> tasks = taskService.createTaskQuery().list(); for (Task task : tasks) { if (task.getExecutionId() == null) { taskService.deleteTask(task.getId(), true); } } } }
From source file:org.openmrs.module.appointmentscheduling.web.controller.AppointmentFormController.java
@ModelAttribute("availableTimes") public List<TimeSlot> getAvailableTimes(ModelMap model, HttpServletRequest request, Appointment appointment, @RequestParam(value = "fromDate", required = false) Date fromDate, @RequestParam(value = "toDate", required = false) Date toDate, @RequestParam(value = "providerSelect", required = false) Provider provider, @RequestParam(value = "locationId", required = false) Location location, @RequestParam(value = "includeFull", required = false) String includeFull, @RequestParam(value = "flow", required = false) String flow) { AppointmentType appointmentType = appointment.getAppointmentType(); if (appointmentType == null || (fromDate != null && toDate != null && !fromDate.before(toDate))) return null; //If its a walk-in flow change the start date to current time and end date to the end of today (23:59:59.999) if (flow != null) { fromDate = Calendar.getInstance().getTime(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); toDate = cal.getTime();//from www . j ava 2 s . c o m } try { List<TimeSlot> availableTimeSlots = null; //No need to include full slots if (includeFull == null || !Context.hasPrivilege(AppointmentUtils.PRIV_SQUEEZE_APPOINTMENTS)) { availableTimeSlots = Context.getService(AppointmentService.class) .getTimeSlotsByConstraints(appointmentType, fromDate, toDate, provider, location); TimeSlot currentSelectedSlot = appointment.getTimeSlot(); //The appointment time slot should be selected from the latest list if (currentSelectedSlot != null && !availableTimeSlots.contains(currentSelectedSlot)) appointment.setTimeSlot(null); } //Include full and indicate which are full using the model attribute fullSlots else { availableTimeSlots = Context.getService(AppointmentService.class) .getTimeSlotsByConstraintsIncludingFull(appointmentType, fromDate, toDate, provider, location); List<TimeSlot> fullTimeSlots = new LinkedList<TimeSlot>(); Map<Integer, Integer> overdueTimes = new HashMap<Integer, Integer>(); Integer typeDuration = appointmentType.getDuration(); Iterator<TimeSlot> iterator = availableTimeSlots.iterator(); while (iterator.hasNext()) { TimeSlot slot = iterator.next(); Integer timeLeft = Context.getService(AppointmentService.class).getTimeLeftInTimeSlot(slot); if (timeLeft < typeDuration) { fullTimeSlots.add(slot); overdueTimes.put(slot.getId(), timeLeft); iterator.remove(); } } model.put("fullSlots", fullTimeSlots); model.put("overdueTimes", overdueTimes); } return availableTimeSlots; } catch (Exception ex) { return null; } }
From source file:com.linuxbox.enkive.statistics.gathering.past.PastGatherer.java
public void consolidatePastMonths() { Calendar c = Calendar.getInstance(); c.setTime(statDate);//from w ww. j a va2 s. c o m c.set(Calendar.MILLISECOND, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.DAY_OF_MONTH, 1); setEndDate(CONSOLIDATION_MONTH); if (c.getTimeInMillis() > endDate.getTime()) { client.storeData(consolidatePast(CONSOLIDATION_MONTH, c)); } }
From source file:net.solarnetwork.node.backup.test.FileSystemBackupServiceTest.java
@Test public void backupMultiple() throws IOException { final ClassPathResource testResource1 = new ClassPathResource("test-context.xml", AbstractNodeTransactionalTest.class); final ClassPathResource testResource2 = new ClassPathResource("test-file.txt", FileSystemBackupServiceTest.class); final BackupService bs = service; final List<BackupResource> resources = new ArrayList<BackupResource>(1); final Calendar now = new GregorianCalendar(); now.set(Calendar.MILLISECOND, 0); resources.add(new ResourceBackupResource(testResource1, "test.xml")); resources.add(new ResourceBackupResource(testResource2, "test.txt")); Backup result = bs.performBackup(resources); assertNotNull(result);/*from w w w. ja v a 2s .co m*/ assertNotNull(result.getDate()); assertTrue(!now.after(result.getDate())); assertNotNull(result.getKey()); assertTrue(result.isComplete()); // now let's verify we can get that file back out of the backup Collection<Backup> backups = bs.getAvailableBackups(); assertNotNull(backups); assertEquals(1, backups.size()); Backup b = backups.iterator().next(); assertEquals(result.getKey(), b.getKey()); assertEquals(result.getDate().getTime(), b.getDate().getTime()); int count = 0; final BackupResourceIterable backupResources = bs.getBackupResources(b); try { for (BackupResource r : bs.getBackupResources(b)) { if (count == 0) { assertEquals("test.xml", r.getBackupPath()); Assert.assertArrayEquals(FileCopyUtils.copyToByteArray(testResource1.getInputStream()), FileCopyUtils.copyToByteArray(r.getInputStream())); } else if (count == 1) { assertEquals("test.txt", r.getBackupPath()); Assert.assertArrayEquals(FileCopyUtils.copyToByteArray(testResource2.getInputStream()), FileCopyUtils.copyToByteArray(r.getInputStream())); } count++; } } finally { backupResources.close(); } assertEquals("Should have 2 backup resources", 2, count); }
From source file:py.una.pol.karaku.test.test.dao.interceptors.TimeInterceptorTest.java
/** * Test date.// ww w.j a v a 2 s . c o m */ @Test public void testDate() { Date d = new Date(); Date d2 = new Date(d.getTime()); TimeTest tt = new TimeTest(d, d, d); this.interceptorHandler.intercept(Operation.CREATE, tt); Calendar c = Calendar.getInstance(); c.setTime(tt.getDate()); Calendar c2 = Calendar.getInstance(); c2.setTime(d2); assertThat(c.get(Calendar.YEAR), is(c2.get(Calendar.YEAR))); assertThat(c.get(Calendar.MONTH), is(c2.get(Calendar.MONTH))); assertThat(c.get(Calendar.DAY_OF_MONTH), is(c2.get(Calendar.DAY_OF_MONTH))); assertThat(c.get(Calendar.HOUR_OF_DAY), is(0)); assertThat(c.get(Calendar.MINUTE), is(0)); assertThat(c.get(Calendar.SECOND), is(0)); assertThat(c.get(Calendar.MILLISECOND), is(0)); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.workspacecache.WorkspaceInfo.java
public WorkspaceInfo(final InternalServerInfo serverInfo, final Workspace workspace) { Check.notNull(serverInfo, "serverInfo"); //$NON-NLS-1$ Check.notNull(workspace, "workspace"); //$NON-NLS-1$ this.serverInfo = serverInfo; this.comment = workspace.getComment(); this.computer = workspace.getComputer(); this.isLocalWorkspace = (workspace.getLocation() == WorkspaceLocation.LOCAL); this.name = workspace.getName(); this.ownerName = workspace.getOwnerName(); this.ownerDisplayName = workspace.getOwnerDisplayName(); this.securityToken = workspace.getSecurityToken(); this.mappedPaths = WorkingFolder.extractMappedPaths(workspace.getFolders()); this.options = workspace.getOptions(); this.ownerAliases = workspace.getOwnerAliases() != null ? workspace.getOwnerAliases().clone() : new String[0]; this.state = LocalWorkspaceState.NEW; lastSavedCheckinTimeStamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$ lastSavedCheckinTimeStamp.set(1, Calendar.JANUARY, 1, 0, 0, 0); lastSavedCheckinTimeStamp.set(Calendar.MILLISECOND, 0); Check.isTrue(this.name.equals(this.ownerName) == false, MessageFormat .format("Something went wrong since name and owner are the same: {0}", this.toString())); //$NON-NLS-1$ }
From source file:Currently.java
/** * Parses one of the ISO 8601 that it produces. Note, it will not * parse the full range of ISO timestamps. * * @param stamp is the textual timestamp representation. * @return a time or <code>null</code>, if unparsable. *//* w w w. j av a2s. co m*/ public static Date parse(String stamp) { // initialize the compiled expressions once if (c_pattern == null) { c_pattern = new Pattern[c_expression.length]; for (int i = 0; i < c_expression.length; ++i) { c_pattern[i] = Pattern.compile(c_expression[i]); } } // match against pattern for (int i = 0; i < c_expression.length; ++i) { Matcher m = c_pattern[i].matcher(stamp); if (m.matches()) { Calendar c = Calendar.getInstance(); TimeZone z = TimeZone.getDefault(); if (m.group(9) != null && m.group(9).length() > 0) { boolean utc = (Character.toUpperCase(m.group(9).charAt(0)) == 'Z'); if (utc) { z = TimeZone.getTimeZone("GMT+0"); } else { z = TimeZone.getTimeZone("GMT" + m.group(9)); } } c.setTimeZone(z); c.set(Calendar.YEAR, Integer.parseInt(m.group(1))); c.set(Calendar.MONTH, Integer.parseInt(m.group(2)) + (Calendar.JANUARY - 1)); c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(m.group(3))); if (m.group(4).length() > 0) { c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(5))); c.set(Calendar.MINUTE, Integer.parseInt(m.group(6))); if (m.group(7) != null && m.group(7).length() > 0) { c.set(Calendar.SECOND, Integer.parseInt(m.group(7))); } if (m.group(8) != null && m.group(8).length() > 1) { String millis = m.group(8).substring(1); while (millis.length() < 3) { millis += "0"; } millis = millis.substring(0, 3); c.set(Calendar.MILLISECOND, Integer.parseInt(millis)); } } return c.getTime(); } } // not found return null; }
From source file:com.rogoman.easyauth.InMemoryUsedCodesManager.java
/** * Cleans up the data structures of old entries. *//* w w w . ja v a 2 s.co m*/ private void queueCleanup() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MILLISECOND, -this.cleanupAge); Date timeToClean = cal.getTime(); try { syncLock.lock(); while (!codeQueue.isEmpty() && codeQueue.peek().getUseDate().before(timeToClean)) { UsedCode usedCode = codeQueue.remove(); codeSet.remove(usedCode); } } finally { syncLock.unlock(); } }