List of usage examples for java.util Calendar JANUARY
int JANUARY
To view the source code for java.util Calendar JANUARY.
Click Source Link
From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.CriteriaTest.java
/** * Tests the xpath query statement produced by a Criteria instance. * @throws Exception/*from ww w . jav a2 s . co m*/ */ @Test public void testToXpathExpression() throws Exception { Criteria criteria = toXpathExpressionJavadocExampleCriteria(); Calendar begin = Calendar.getInstance(); begin.set(1999, Calendar.JANUARY, 1); begin.set(Calendar.HOUR_OF_DAY, 0); begin.set(Calendar.MINUTE, 0); begin.set(Calendar.SECOND, 0); begin.set(Calendar.MILLISECOND, 0); Calendar end = Calendar.getInstance(); end.set(2001, Calendar.DECEMBER, 31); end.set(Calendar.HOUR_OF_DAY, 0); end.set(Calendar.MINUTE, 0); end.set(Calendar.SECOND, 0); end.set(Calendar.MILLISECOND, 0); end.add(Calendar.MILLISECOND, -1); end.add(Calendar.DAY_OF_YEAR, 1); String expectedStmt = "//pets//*" + "[((jcr:contains(@title, 'Lucky')) and (@petType='dog')" + " and (@birthDate >=xs:dateTime('" + XPathTextUtils.toXsdDate(begin) + "')" + " and @birthDate <=xs:dateTime('" + XPathTextUtils.toXsdDate(end) + "')))]" + " order by @title descending"; log.debug(expectedStmt); // @birthDate >=xs:dateTime('1999-01-01T00:00:00.000+01:00') // and // @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+01:00') String actualStmt = criteria.toXpathExpression(); Assert.assertEquals(StringUtils.remove(actualStmt, ' '), StringUtils.remove(expectedStmt, ' ')); }
From source file:org.lieuofs.commune.biz.GestionMutationCommuneTest.java
@Test public void testRechercherMutationDepuisDate() { MutationCommuneCritere critere = new MutationCommuneCritere(); Calendar cal = Calendar.getInstance(); cal.set(2006, Calendar.JANUARY, 1); critere.setDateDebut(cal.getTime()); List<IMutationCommune> mutations = gestionnaire.rechercherMutation(critere); List<String> descriptions = new ArrayList<String>(); int i = 0;//w w w . j a va 2 s . c o m for (IMutationCommune mut : mutations) { System.out.println("Mutation " + i); descriptions.add(mut.getDescription()); i++; } assertThat(mutations.size()).isGreaterThan(100); }
From source file:ch.puzzle.itc.mobiliar.business.generator.control.extracted.templates.TemplateProcessorBaseTest.java
protected GenerationOptions createOptions() { DeploymentEntity d = new DeploymentEntity(); d.setRuntime(builder.platform);/*from w w w . j av a2s . c om*/ d.setApplicationsWithVersion(new ArrayList<DeploymentEntity.ApplicationWithVersion>()); ReleaseEntity release = new ReleaseEntity(); Calendar cal = new GregorianCalendar(); release.setId(-1); release.setName("release"); cal.set(2014, Calendar.JANUARY, 1); d.setRelease(release); GenerationContext context = new GenerationContext(this.context, builder.as, d, null, GenerationModus.SIMULATE, dependencyResolverService); context.setNode(builder.buildResource(builder.buildResourceType(EntityBuilderType.NODE1.type), "node")); builder.buildConsumedRelation(context.getApplicationServer(), context.getNode(), ForeignableOwner.AMW); return new GenerationOptions(context); }
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 a va 2 s.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:uk.co.anthonycampbell.java.mp4reader.util.Util.java
/** * Convert the provided big integer time stamp to a date instance. * Time stamps in the MP4 specification resolve to the number of * seconds since 1904./*www .j a v a2 s . c o m*/ * * @param bigInteger - big integer instance to convert. * @return date instance. */ public static Date generateDate(final BigInteger bigInteger) { // Validate if (bigInteger != null) { /* * TODO If once upon a time we have a very LARGE time stamp * this call will only return the lower order 64 bits. */ final Calendar calendar = Calendar.getInstance(); calendar.set(1904, Calendar.JANUARY, 1, 0, 0, 0); calendar.setTimeInMillis(calendar.getTimeInMillis() + (bigInteger.longValue() * 1000)); return calendar.getTime(); } else { throw new IllegalArgumentException( "Unable to generate date, provided argument is invalid! " + "(bigInteger=" + bigInteger + ")"); } }
From source file:org.sakaiproject.util.CalendarUtil.java
void initDates() { Calendar calendarSunday = Calendar.getInstance(); Calendar calendarMonday = Calendar.getInstance(); Calendar calendarTuesday = Calendar.getInstance(); Calendar calendarWednesday = Calendar.getInstance(); Calendar calendarThursday = Calendar.getInstance(); Calendar calendarFriday = Calendar.getInstance(); Calendar calendarSaturday = Calendar.getInstance(); calendarSunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); calendarMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); calendarTuesday.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); calendarWednesday.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY); calendarThursday.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY); calendarFriday.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); calendarSaturday.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); dateSunday = calendarSunday.getTime(); dateMonday = calendarMonday.getTime(); dateTuesday = calendarTuesday.getTime(); dateWednesday = calendarWednesday.getTime(); dateThursday = calendarThursday.getTime(); dateFriday = calendarFriday.getTime(); dateSaturday = calendarSaturday.getTime(); Calendar calendarJanuary = Calendar.getInstance(); Calendar calendarFebruary = Calendar.getInstance(); Calendar calendarMarch = Calendar.getInstance(); Calendar calendarApril = Calendar.getInstance(); Calendar calendarMay = Calendar.getInstance(); Calendar calendarJune = Calendar.getInstance(); Calendar calendarJuly = Calendar.getInstance(); Calendar calendarAugust = Calendar.getInstance(); Calendar calendarSeptember = Calendar.getInstance(); Calendar calendarOctober = Calendar.getInstance(); Calendar calendarNovember = Calendar.getInstance(); Calendar calendarDecember = Calendar.getInstance(); calendarJanuary.set(Calendar.MONTH, Calendar.JANUARY); calendarFebruary.set(Calendar.MONTH, Calendar.FEBRUARY); calendarMarch.set(Calendar.MONTH, Calendar.MARCH); calendarApril.set(Calendar.MONTH, Calendar.APRIL); calendarMay.set(Calendar.MONTH, Calendar.MAY); calendarJune.set(Calendar.MONTH, Calendar.JUNE); calendarJuly.set(Calendar.MONTH, Calendar.JULY); calendarAugust.set(Calendar.MONTH, Calendar.AUGUST); calendarSeptember.set(Calendar.MONTH, Calendar.SEPTEMBER); calendarOctober.set(Calendar.MONTH, Calendar.OCTOBER); calendarNovember.set(Calendar.MONTH, Calendar.NOVEMBER); calendarDecember.set(Calendar.MONTH, Calendar.DECEMBER); dateJanuary = calendarJanuary.getTime(); dateFebruary = calendarFebruary.getTime(); dateMarch = calendarMarch.getTime(); dateApril = calendarApril.getTime(); dateMay = calendarMay.getTime();/* w w w . j ava 2 s. co m*/ dateJune = calendarJune.getTime(); dateJuly = calendarJuly.getTime(); dateAugust = calendarAugust.getTime(); dateSeptember = calendarSeptember.getTime(); dateOctober = calendarOctober.getTime(); dateNovember = calendarNovember.getTime(); dateDecember = calendarDecember.getTime(); }
From source file:org.apache.torque.generated.peer.DateTest.java
/** * Tests the time behaviour. Time fields should have the date set * to 1.1.1970. Note that this does not tell * anything about how the field is saved in the database, which can differ * between databases./*from w w w . ja v a2 s . co m*/ * * @throws Exception if the test fails */ public void testTime() throws Exception { cleanDateTimeTimestampTable(); // insert new DateTest object to db DateTimeTimestampType dateTimeTimestamp = new DateTimeTimestampType(); Date now = new Date(); dateTimeTimestamp.setDateValue(now); dateTimeTimestamp.setTimeValue(now); dateTimeTimestamp.setTimestampValue(now); dateTimeTimestamp.save(); // reload dateTest from db DateTimeTimestampType loaded = DateTimeTimestampTypePeer.retrieveByPK(dateTimeTimestamp.getPrimaryKey()); // calculate expected value Date expected; // if (adapter instanceof DBOracle) // { // expected = new Date(now.getTime() / 1000L * 1000L); // } // else { Calendar calendar = new GregorianCalendar(); calendar.setTime(now); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MILLISECOND, 0); expected = calendar.getTime(); } // verify long loadedTimestampRounded = loaded.getTimeValue().getTime() / 1000L * 1000L; assertEquals(expected, new Date(loadedTimestampRounded)); }
From source file:com.netflix.genie.core.jpa.services.JpaJobPersistenceImplIntegrationTests.java
/** * Make sure we can delete jobs that were created before a given date. *//* w w w . j a va2s. c om*/ @Test public void canDeleteJobsCreatedBeforeDateWithMaxLargerThanPage() { // Try to delete a all jobs from before Jan 1, 2016 final Calendar cal = Calendar.getInstance(JobConstants.UTC); cal.set(2016, Calendar.JANUARY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); final long deleted = this.jobPersistenceService.deleteBatchOfJobsCreatedBeforeDate(cal.getTime(), 10, 1); Assert.assertThat(deleted, Matchers.is(2L)); Assert.assertThat(this.jobExecutionRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRequestRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRequestMetadataRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRepository.count(), Matchers.is(1L)); Assert.assertNotNull(this.jobExecutionRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRequestRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRequestMetadataRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRepository.getOne(JOB_3_ID)); }
From source file:com.jeans.iservlet.controller.impl.AssetsController.java
private Map<String, Object> parseFilters(String filters) { Map<String, Object> ret = new HashMap<String, Object>(); String[] fs = filters.split("&"); Set<String> vendors = new HashSet<String>(); String[] vs = fs[0].split(","); for (String v : vs) { if (!StringUtils.isBlank(v)) { vendors.add(v);//from w w w . jav a2s .c o m } } ret.put("vendor", vendors); Calendar start = Calendar.getInstance(); try { start.set(Calendar.YEAR, Integer.parseInt(fs[1])); start.set(Calendar.MONTH, Calendar.JANUARY); start.set(Calendar.DATE, 1); start.set(Calendar.HOUR_OF_DAY, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.MILLISECOND, 0); ret.put("purchaseTimeStart", start.getTime()); } catch (Exception e) { ret.put("purchaseTimeStart", null); } Calendar end = Calendar.getInstance(); try { end.set(Calendar.YEAR, Integer.parseInt(fs[2])); end.set(Calendar.MONTH, Calendar.DECEMBER); end.set(Calendar.DATE, 31); end.set(Calendar.HOUR_OF_DAY, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 999); ret.put("purchaseTimeEnd", end.getTime()); } catch (Exception e) { ret.put("purchaseTimeEnd", null); } try { ret.put("state", Byte.parseByte(fs[3])); } catch (Exception e) { ret.put("state", (byte) 9); } if (fs.length == 6) { // : warranty, importance try { ret.put("warranty", Byte.parseByte(fs[5])); } catch (Exception e) { ret.put("warranty", (byte) 9); } try { ret.put("importance", Byte.parseByte(fs[6])); } catch (Exception e) { ret.put("importance", (byte) 9); } } else if (fs.length == 5) { // : softwareType try { ret.put("softwareType", Byte.parseByte(fs[4])); } catch (Exception e) { ret.put("softwareType", (byte) 9); } } return ret; }
From source file:py.una.pol.karaku.test.test.dao.clauses.DateClausesTest.java
private Date time(int hour, int minute) { return newTime(1, Calendar.JANUARY, 1970, hour, minute); }