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:com.blackberry.logdriver.timestamp.Rfc3164TimestampParser.java
@Override public long parseTimestatmp(String timestamp) throws ParseException { if (timestamp == null) { throw new ParseException("Timestamp is null", 0); }/* www . java2s .co m*/ // Before we parse the date, add the current year to the string. That way, // we get a correct timestamp. If I try to add the year after, we run into // issues with leap years. Calendar currentCalendar = Calendar.getInstance(); int currentYear = currentCalendar.get(Calendar.YEAR); Date date = dateFormat.parse(currentYear + " " + timestamp); Calendar logCalendar = Calendar.getInstance(); logCalendar.setTime(date); // If today is the first of January, and the log is for the 31st of // December, then we probably just used the wrong year. So lets roll the // year back by one in that case. if (logCalendar.get(Calendar.DAY_OF_MONTH) == 31 && logCalendar.get(Calendar.MONTH) == Calendar.DECEMBER && currentCalendar.get(Calendar.DAY_OF_MONTH) == 1 && currentCalendar.get(Calendar.MONTH) == Calendar.JANUARY) { logCalendar.add(Calendar.YEAR, -1); // Contrariwise, a bad clock can give us Jan 1 logs on December 31 } else if (currentCalendar.get(Calendar.DAY_OF_MONTH) == 31 && currentCalendar.get(Calendar.MONTH) == Calendar.DECEMBER && logCalendar.get(Calendar.DAY_OF_MONTH) == 1 && logCalendar.get(Calendar.MONTH) == Calendar.JANUARY) { logCalendar.add(Calendar.YEAR, 1); } return logCalendar.getTimeInMillis(); }
From source file:org.neo4art.importer.wikipedia.parser.util.WikipediaDateTimeInfoboxParserUtils.java
/** * Known pattern:/*from w w w. java2 s . c om*/ * * {{Birth date|1993|2|4|df=yes}} * {{Birth date|1993|2|4|mf=yes}} * {{Birth date|1993|2|4}} * {{Birth date|df=yes|1756|03|04}} * * {{Birth date and age|1993|2|4|df=yes}} * {{Birth date and age|1993|2|4|mf=yes}} * {{Birth date and age|1993|2|4}} * * {{Death date and age|1993|2|24|1941|4|12|df=yes}} * {{Death date and age|1993|2|24|1941|4|df=yes}} * {{Death date and age|1993|2|24|1941|mf=yes}} * {{Death date and age|df=yes|1890|7|29|1853|3|30}} * * 30 March 1853 * * @param dateAsString * @return */ public static Date parseAsDate(String dateAsString) { if (StringUtils.isBlank(dateAsString)) { return null; } final String PATTERNS[] = { "[\\{]{2}[Bb]irth date[\\s]*\\|([\\d]+)\\|([\\d]+)\\|([\\d]+)\\|[\\S]+[\\}]{2}", "[\\{]{2}[Bb]irth date[\\s]*\\|([\\d]+)\\|([\\d]+)\\|([\\d]+)[\\}]{2}", "[\\{]{2}[Bb]irth date[\\s]*\\|[\\D]+\\|([\\d]+)\\|([\\d]+)\\|([\\d]+)[\\}]{2}", "[\\{]{2}[Bb]irth date and age[\\s]*\\|([\\d]+)\\|([\\d]+)\\|([\\d]+)\\|[\\S]*", "[\\{]{2}[Bb]irth date and age[\\s]*\\|([\\d]+)\\|([\\d]+)\\|([\\d]+)[\\}]{2}", "[\\{]{2}[Dd]eath date and age[\\s]*\\|([\\d]+)\\|([\\d]+)\\|([\\d]+)\\|[\\S]*", "[\\{]{2}[Dd]eath date and age[\\s]*\\|[\\D]+\\|([\\d]+)\\|([\\d]+)\\|([\\d]+)\\|[\\S]*" }; for (String patternRegex : PATTERNS) { Pattern patter = Pattern.compile(patternRegex); Matcher matcher = patter.matcher(dateAsString); if (matcher.matches()) { return toDate(matcher.group(1), matcher.group(2), matcher.group(3)); } } try { return new SimpleDateFormat("dd MMM yyyy").parse(dateAsString); } catch (Exception e) { } try { Calendar year = Calendar.getInstance(); year.set(Integer.parseInt(dateAsString), Calendar.JANUARY, 1, 0, 0, 0); year.set(Calendar.MILLISECOND, 0); return year.getTime(); } catch (Exception e) { } logger.trace("Unable to parse " + dateAsString + " as Date."); return null; }
From source file:ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverServiceTest.java
@Before public void before() { service.resourceReleaseComparator = new ResourceReleaseComparator(); Calendar cal = new GregorianCalendar(); cal.set(2001, Calendar.JANUARY, 1); release1 = createRelease(1, new Date(cal.getTimeInMillis())); cal.set(2002, Calendar.JANUARY, 1); release2 = createRelease(2, new Date(cal.getTimeInMillis())); cal.set(2003, Calendar.JANUARY, 1); release3 = createRelease(3, new Date(cal.getTimeInMillis())); cal.set(2004, Calendar.JANUARY, 1); release4 = createRelease(4, new Date(cal.getTimeInMillis())); r1 = ResourceEntityBuilder.createResourceEntity("test1", 1); r1.setRelease(release1);//from w w w. ja va 2 s .co m r2 = ResourceEntityBuilder.createResourceEntity("test2", 2); r2.setRelease(release2); r3 = ResourceEntityBuilder.createResourceEntity("test3", 3); r3.setRelease(release3); r4 = ResourceEntityBuilder.createResourceEntity("test4", 4); r4.setRelease(release4); }
From source file:net.audumla.climate.bom.BOMStatisticalClimateDataObserver.java
public BOMStatisticalClimateDataObserver(ClimateDataSource source) { this.source = source; this.source.setType(ClimateDataSource.ClimateDataSourceType.MONTHLY_STATISTICAL); Calendar c = Calendar.getInstance(); c.setTime(new Date(0)); c.set(Calendar.MONTH, Calendar.JANUARY); for (int i = 0; i < 12; ++i) { WritableClimateData cd = ClimateDataFactory.newWritableClimateData(this, getSource()); cd.setTime(c.getTime());//from w w w .ja v a2s . co m statData.put(c.getTime(), cd); c.add(Calendar.MONTH, 1); } if (source.getId() != null && source.getId().length() > 0) { loadHistoricalData(); } logger.debug("Initialized BOM MONTHLY STATISTICAL Observer[" + source.toString() + "]"); }
From source file:org.kuali.kfs.gl.batch.service.PosterServiceTest.java
/** * * @see org.kuali.kfs.gl.businessobject.OriginEntryTestBase#setUp() *//*from w w w.jav a 2s.c om*/ @Override protected void setUp() throws Exception { super.setUp(); Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.YEAR, TestUtils.getFiscalYearForTesting()); // because of the cutoff time implementation, assume a specific time of day after the cutoff (10:00 am, see RunDateService // for details) c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 50); c.set(Calendar.SECOND, 0); date = c.getTime(); // Set the run date of the job dateTimeService.setCurrentDate(date); posterService = SpringContext.getBean(PosterService.class, "glMockPosterService"); posterService.setDateTimeService(dateTimeService); }
From source file:org.sipfoundry.sipxconfig.rest.VoicemailResourceTest.java
public void testFeed() throws Exception { User user = new User(); user.setUniqueId();/*from ww w.ja va 2 s .com*/ user.setUserName("joeuser"); Authentication token = new TestAuthenticationToken(user, false, false).authenticateToken(); SecurityContextHolder.getContext().setAuthentication(token); Mailbox mailbox = new Mailbox(null, "joeuser"); List<Voicemail> vmails = new ArrayList<Voicemail>(); File vmailDir = new File("/voicemail/store"); for (int i = 0; i < 5; i++) { final int id = i; Voicemail vmail = new Voicemail(vmailDir, "joeuse", "inbox", "0000000" + i) { @Override protected MessageDescriptor readMessageDescriptor(File file) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.set(1970, Calendar.JANUARY, 14 + id, 10, 0, id); MessageDescriptor md = createMock(MessageDescriptor.class); md.getSubject(); expectLastCall().andReturn("Voice Message 0000000" + id); md.getTimestamp(); expectLastCall().andReturn(cal.getTime()).atLeastOnce(); md.getFrom(); expectLastCall().andReturn("George <president@example.org>"); md.getFromBrief(); expectLastCall().andReturn("George"); md.getDurationsecs(); expectLastCall().andReturn(10 + id); replay(md); return md; } }; vmails.add(vmail); } CoreContext coreContext = createMock(CoreContext.class); coreContext.loadUser(user.getId()); expectLastCall().andReturn(user); MailboxManager mailboxManager = createMock(MailboxManager.class); mailboxManager.getMailbox(user.getUserName()); expectLastCall().andReturn(mailbox); mailboxManager.getVoicemail(mailbox, "inbox"); expectLastCall().andReturn(vmails); PrivateUserKeyManager pukm = createMock(PrivateUserKeyManager.class); pukm.getPrivateKeyForUser(user); expectLastCall().andStubReturn("123456"); replay(coreContext, mailboxManager, pukm); VoicemailResource resource = new VoicemailResource(); resource.setMailboxManager(mailboxManager); resource.setCoreContext(coreContext); resource.setPrivateUserKeyManager(pukm); Request request = new Request(); Map<String, Object> attributes = new HashMap(); attributes.put("folder", "inbox"); request.setAttributes(attributes); request.setOriginalRef(new Reference("https://example.com:8034/sipxconfig/rest/my/feed/voicemail/inbox")); request.setRootRef(new Reference("https://example.com:8034/sipxconfig/rest")); resource.init(null, request, null); Representation representation = resource.represent(new Variant(APPLICATION_RSS_XML)); StringWriter writer = new StringWriter(); representation.write(writer); String generated = StringUtils.trim(StringUtils.replace(writer.toString(), "\r\n", "\n")); // FileUtils.writeStringToFile(new File("kuku"), generated); String expected = IOUtils.toString(getClass().getResourceAsStream("voicemail-feed.test.xml")); assertEquals(expected, generated); }
From source file:org.neo4art.colour.manager.VanGoghArtworksColourAnalysisDefaultManager.java
/** * @see org.neo4art.colour.manager.VanGoghArtworksColourAnalysisManager#loadArtworksFromFile(java.lang.String) *///from w w w. j a va 2s .c o m @Override public List<Artwork> loadArtworksFromFile(String fileName) throws IOException { List<Artwork> artworks = null; URL url = getClass().getClassLoader().getResource(fileName); CSVParser csvParser = CSVParser.parse(url, Charset.defaultCharset(), CSVFormat.EXCEL.withIgnoreSurroundingSpaces(true)); List<CSVRecord> cvsRecords = csvParser.getRecords(); if (CollectionUtils.isNotEmpty(cvsRecords) && CollectionUtils.size(cvsRecords) > 1) { artworks = new ArrayList<Artwork>(); for (int i = 1; i < cvsRecords.size(); i++) { CSVRecord csvRecord = cvsRecords.get(i); Artwork artwork = new Artwork(); Calendar completionDate = Calendar.getInstance(); completionDate.set(Calendar.YEAR, Integer.parseInt(csvRecord.get(2))); completionDate.set(Calendar.MONTH, Integer.parseInt(csvRecord.get(3))); artwork.setTitle(csvRecord.get(0)); artwork.setType(csvRecord.get(1)); artwork.setYear(new Date(Integer.parseInt(csvRecord.get(2)), Calendar.JANUARY, 1)); artwork.setCompletionDate(completionDate.getTime()); artwork.setImageFile(csvRecord.get(4)); artwork.setCatalogue("F: " + csvRecord.get(5) + ", JH: " + csvRecord.get(6)); artworks.add(artwork); } } return artworks; }
From source file:com.netflix.genie.core.jpa.services.JpaJobPersistenceImplIntegrationTests.java
/** * Make sure we can delete jobs that were created before a given date. *///from w w w .j av a2 s.c om @Test public void canDeleteJobsCreatedBeforeDateWithMinTransactionAndPageSize() { // Try to delete a single job 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(), 1, 1); Assert.assertThat(deleted, Matchers.is(1L)); Assert.assertThat(this.jobExecutionRepository.count(), Matchers.is(2L)); Assert.assertThat(this.jobRequestRepository.count(), Matchers.is(2L)); Assert.assertThat(this.jobRequestMetadataRepository.count(), Matchers.is(2L)); Assert.assertThat(this.jobRepository.count(), Matchers.is(2L)); 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:org.apache.hadoop.hive.ql.exec.vector.expressions.TestVectorDateExpressions.java
private int[] getAllBoundaries() { List<Integer> boundaries = new ArrayList<Integer>(1); Calendar c = Calendar.getInstance(); c.setTimeInMillis(0); // c.set doesn't reset millis for (int year = 1902; year <= 2038; year++) { c.set(year, Calendar.JANUARY, 1, 0, 0, 0); int exactly = (int) (c.getTimeInMillis() / (24 * 60 * 60 * 1000)); int before = exactly - 1; int after = exactly + 1; boundaries.add(Integer.valueOf(before)); boundaries.add(Integer.valueOf(exactly)); boundaries.add(Integer.valueOf(after)); }/*from w ww .ja v a 2s. co m*/ Integer[] indices = boundaries.toArray(new Integer[1]); return ArrayUtils.toPrimitive(indices); }
From source file:biz.c24.io.spring.integration.samples.fpml.FpmlGenerator.java
private static TradeConfirmed randomizeFpML(TradeConfirmed tradeConfirmed) throws CloneNotSupportedException { ISO8601DateTime creationDate = new ISO8601DateTime(new Date()); ISO8601Date tradeDate = new ISO8601Date(new GregorianCalendar(2011, Calendar.JULY, 5).getTime()); ISO8601Date expiryDate = new ISO8601Date(new GregorianCalendar(2012, Calendar.JANUARY, 5).getTime()); ISO8601Date settlementDate = new ISO8601Date(new GregorianCalendar(2011, Calendar.JULY, 7).getTime()); ISO8601Date valueDate = new ISO8601Date(new GregorianCalendar(2012, Calendar.JANUARY, 9).getTime()); Random random = new Random(); BigDecimal putAmount = new BigDecimal((1 + random.nextInt(999)) * 100000.); BigDecimal callAmount = new BigDecimal((1 + random.nextInt(999)) * 100000.); BigDecimal fxRate = callAmount.divide(putAmount, 8, RoundingMode.HALF_EVEN).setScale(5, BigDecimal.ROUND_HALF_UP); BigDecimal premiumValue = new BigDecimal(0.001).setScale(5, BigDecimal.ROUND_HALF_UP); BigDecimal premiumAmount = callAmount.multiply(premiumValue).setScale(2, BigDecimal.ROUND_HALF_UP); String sendTo = "SendTo" + random.nextInt(999999); String sentBy = "SentBy" + random.nextInt(999999); String msgId = "Msg" + random.nextInt(999999); String conversationId = "Conv" + random.nextInt(999999); String tradeId1 = "ID1:" + random.nextInt(999999); String tradeId2 = "ID2:" + random.nextInt(999999); // Set the header NotificationMessageHeader header = tradeConfirmed.getHeader(); header.getMessageHeadermodel().setCreationTimestamp(creationDate); header.getConversationId().setValue(conversationId); header.getMessageId().setValue(msgId); header.getMessageHeadermodel().getSentBy().setValue(sentBy); header.getMessageHeadermodel().getSendTo()[0].setValue(sendTo); // Set the TradeHeader TradeHeader tradeHeader = tradeConfirmed.getTrade().getTradeHeader(); tradeHeader.getPartyTradeIdentifier()[0].getTradeIdentifierSG1()[0].getTradeId().setValue(tradeId1); tradeHeader.getPartyTradeIdentifier()[1].getTradeIdentifierSG1()[0].getTradeId().setValue(tradeId2); tradeHeader.getTradeDate().setValue(tradeDate); FxOptionLeg fxOptionLeg = (FxOptionLeg) tradeConfirmed.getTrade().getProduct(); fxOptionLeg.getExpiryDateTime().setExpiryDate(expiryDate); FxOptionPremium optionPremium = fxOptionLeg.getFxOptionPremium()[0]; optionPremium.getPremiumAmount().setAmount(premiumAmount); optionPremium.setPremiumSettlementDate(settlementDate); SettlementInstruction settlementInstruction = optionPremium.getSettlementInformation() .getSettlementInstruction(); settlementInstruction.getCorrespondentInformation().getRoutingIdentificationmodel().getRoutingIds() .getRoutingId()[0].setValue(sendTo); settlementInstruction.getBeneficiary().getRoutingIdentificationmodel().getRoutingIds().getRoutingId()[0] .setValue(sentBy);//from w w w. j ava 2s.c o m optionPremium.getPremiumQuote().setPremiumValue(premiumValue); fxOptionLeg.setValueDate(valueDate); fxOptionLeg.getPutCurrencyAmount().getCurrency().setValue("AUD"); fxOptionLeg.getPutCurrencyAmount().setAmount(putAmount); fxOptionLeg.getPutCurrencyAmount().getCurrency().setValue("USD"); fxOptionLeg.getCallCurrencyAmount().setAmount(callAmount); fxOptionLeg.getFxStrikePrice().setRate(fxRate); fxOptionLeg.getQuotedAs().getOptionOnCurrency().setValue("AUD"); fxOptionLeg.getQuotedAs().getFaceOnCurrency().setValue("USD"); fxOptionLeg.getQuotedAs().getQuotedTenor().setPeriod("M"); fxOptionLeg.getQuotedAs().getQuotedTenor().setPeriodMultiplier(new BigInteger("6")); tradeConfirmed.getParty()[0].getPartyId()[0].setValue(sendTo); tradeConfirmed.getParty()[1].getPartyId()[0].setValue(sentBy); return (TradeConfirmed) tradeConfirmed.cloneDeep(); }