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:no.met.jtimeseries.MeteogramWrapper.java
/** * Get the nearest full hour where UTC hour % snapTo == 0 * @param date Date to adapt//from w w w. j ava2s.c om * @param snapTo Hour to snap to * @return */ private static Date adapt(Date date, int snapTo) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTime(date); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); int offset = (snapTo - (cal.get(Calendar.HOUR) % snapTo)); cal.add(Calendar.HOUR, offset); return cal.getTime(); }
From source file:edu.ku.kuali.kra.negotiations.rules.NegotiationActivityRuleImpl.java
/** * Call this to validate individual activities. * * @param activity/*from w w w . ja v a2 s . c o m*/ * @param negotiation * @return */ public boolean validateNegotiationActivity(NegotiationActivity activity, Negotiation negotiation) { boolean result = true; activity.refreshReferenceObject("activityType"); if (activity.getActivityType() == null) { result = false; getErrorReporter().reportError("activityTypeId", KeyConstants.ERROR_REQUIRED, "Activity Type (Activity Type)"); } activity.refreshReferenceObject("location"); if (activity.getLocation() == null) { result = false; getErrorReporter().reportError("locationId", KeyConstants.ERROR_REQUIRED, "Location (Location)"); } if (activity.getStartDate() == null) { result = false; getErrorReporter().reportError(START_DATE_PROPERTY, KeyConstants.ERROR_REQUIRED, "Activity Start Date (Activity Start Date)"); } if (StringUtils.isBlank(activity.getDescription())) { result = false; getErrorReporter().reportError("description", KeyConstants.ERROR_REQUIRED, "Activity Description (Activity Description)"); } if (activity.getStartDate() != null && negotiation.getNegotiationStartDate() != null && activity.getStartDate().compareTo(negotiation.getNegotiationStartDate()) < 0) { result = false; getErrorReporter().reportError(START_DATE_PROPERTY, KeyConstants.NEGOTIATION_ACTIVITY_START_BEFORE_NEGOTIATION); } // BUKC-0156: Negotiation - sufficient message when Activity Startis before the Negotiation End Date (Neg. QA Issue 19) if (activity.getStartDate() != null && negotiation.getNegotiationEndDate() != null && activity.getStartDate().compareTo(negotiation.getNegotiationEndDate()) > 0) { result = false; getErrorReporter().reportError(START_DATE_PROPERTY, BUConstants.NEGOTIATION_ACTIVITY_START_AFTER_NEGOTIATION_END); } if (activity.getStartDate() != null && activity.getEndDate() != null && activity.getStartDate().compareTo(activity.getEndDate()) > 0) { result = false; getErrorReporter().reportError(END_DATE_PROPERTY, KeyConstants.NEGOTIATION_ACTIVITY_START_BEFORE_END); } if (activity.getEndDate() != null && negotiation.getNegotiationEndDate() != null && activity.getEndDate().compareTo(negotiation.getNegotiationEndDate()) > 0) { result = false; getErrorReporter().reportError(END_DATE_PROPERTY, KeyConstants.NEGOTIATION_ACTIVITY_END_AFTER_NEGOTIATION); } if (activity.getFollowupDate() != null) { // get today but without any time fields so compare is done strictly on the date. Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); if (activity.getFollowupDate().compareTo(today.getTime()) < 0) { getErrorReporter().reportWarning(FOLLOW_UP_DATE_PROPERTY, KeyConstants.NEGOTIATION_ACTIVITY_START_BEFORE_NEGOTIATION); } } // BUKC-0162: Negotiation - Add validation to prevent user from putting status to "Complete" if activites are still open (Neg. Enhancements // #6) if (activity.getEndDate() == null && negotiation.getNegotiationStatus() != null && getNegotiationService() .getCompletedStatusCodes().contains(negotiation.getNegotiationStatus().getCode())) { result = false; getErrorReporter().reportError(END_DATE_PROPERTY, BUConstants.ACTIVITY_END_DATE_REQUIRED_WHEN_STATUS_COMPLETE, negotiation.getNegotiationStatus().getDescription()); } return result; }
From source file:com.appeligo.search.messenger.Messenger.java
/** * /*from ww w . j ava 2 s . c o m*/ * @param messages */ public int send(com.appeligo.search.entity.Message... messages) { int sent = 0; if (messages == null) { return 0; } for (com.appeligo.search.entity.Message message : messages) { User user = message.getUser(); if (user != null) { boolean changed = false; boolean abort = false; if ((!user.isEnabled()) || (!user.isRegistrationComplete()) || (message.isSms() && (!user.isSmsValid()))) { abort = true; if (message.getExpires() == null) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, 24); message.setExpires(new Timestamp(cal.getTimeInMillis())); changed = true; } } if (message.isSms() && user.isSmsValid() && (!user.isSmsOKNow())) { Calendar now = Calendar.getInstance(user.getTimeZone()); now.set(Calendar.MILLISECOND, 0); now.set(Calendar.SECOND, 0); Calendar nextWindow = Calendar.getInstance(user.getTimeZone()); nextWindow.setTime(user.getEarliestSmsTime()); nextWindow.set(Calendar.MILLISECOND, 0); nextWindow.set(Calendar.SECOND, 0); nextWindow.add(Calendar.MINUTE, 1); // compensate for zeroing out millis, seconds nextWindow.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE)); int nowMinutes = (now.get(Calendar.HOUR) * 60) + now.get(Calendar.MINUTE); int nextMinutes = (nextWindow.get(Calendar.HOUR) * 60) + nextWindow.get(Calendar.MINUTE); if (nowMinutes > nextMinutes) { nextWindow.add(Calendar.HOUR, 24); } message.setDeferUntil(new Timestamp(nextWindow.getTimeInMillis())); changed = true; abort = true; } if (changed) { message.save(); } if (abort) { continue; } } String to = message.getTo(); String from = message.getFrom(); String subject = message.getSubject(); String body = message.getBody(); String contentType = message.getMimeType(); try { Properties props = new Properties(); //Specify the desired SMTP server props.put("mail.smtp.host", mailHost); props.put("mail.smtp.port", Integer.toString(port)); // create a new Session object Session session = null; if (password != null) { props.put("mail.smtp.auth", "true"); session = Session.getInstance(props, new SMTPAuthenticator(smtpUser, password)); } else { session = Session.getInstance(props, null); } session.setDebug(debug); // create a new MimeMessage object (using the Session created above) Message mimeMessage = new MimeMessage(session); mimeMessage.setFrom(new InternetAddress(from)); mimeMessage.setRecipients(Message.RecipientType.TO, new InternetAddress[] { new InternetAddress(to) }); mimeMessage.setSubject(subject); mimeMessage.setContent(body.toString(), contentType); if (mailHost.trim().equals("")) { log.info("No Mail Host. Would have sent:"); log.info("From: " + from); log.info("To: " + to); log.info("Subject: " + subject); log.info(mimeMessage.getContent()); } else { Transport.send(mimeMessage); sent++; } message.setSent(new Date()); } catch (Throwable t) { message.failedAttempt(); if (message.getAttempts() >= maxAttempts) { message.setExpires(new Timestamp(System.currentTimeMillis())); } log.error(t.getMessage(), t); } } return sent; }
From source file:com.otterca.common.crypto.acceptance.X509CertificateBuilderAcceptanceTest.java
/** * Default constructor.//w ww . j ava2 s. c o m * * @throws Exception */ protected X509CertificateBuilderAcceptanceTest() throws GeneralSecurityException, InvalidNameException, URISyntaxException, UnknownHostException, IOException { certUtil = new X509CertificateUtilImpl(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // create key pairs. this is for testing so we use 512-bit keys for // speed. KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); keyPairGen.initialize(512); keyPair = keyPairGen.generateKeyPair(); issuerKeyPair = keyPairGen.generateKeyPair(); grandfatherKeyPair = keyPairGen.generateKeyPair(); notBefore = Calendar.getInstance(); notBefore.set(Calendar.MINUTE, 0); notBefore.set(Calendar.SECOND, 0); notBefore.set(Calendar.MILLISECOND, 0); notAfter = Calendar.getInstance(); notAfter.setTime(notBefore.getTime()); notAfter.add(Calendar.YEAR, 1); expectedGeneralNameUri1 = new com.otterca.common.crypto.GeneralName.URI("http://example.com"); expectedGeneralNameUri2 = new com.otterca.common.crypto.GeneralName.URI("ldap://example.net"); expectedGeneralNameDir = new com.otterca.common.crypto.GeneralName.Directory("C=US,ST=AK,C=Anchorage"); expectedGeneralNameEmail = new com.otterca.common.crypto.GeneralName.Email("bob@example.com"); expectedGeneralNameDns = new com.otterca.common.crypto.GeneralName.DNS("example.com"); expectedGeneralNameIpAddress = new com.otterca.common.crypto.GeneralName.IpAddress("127.0.0.1"); }
From source file:hubert.team.paragraphs.AdvertsOverviewModel.java
public Calendar getMaxDate() { final String dateParameter = MgnlContext.getParameter("date"); if (StringUtils.isNotEmpty(dateParameter)) { Date date;/* ww w.ja v a2s .c o m*/ try { date = new SimpleDateFormat("yyyy.MM.dd").parse(dateParameter); } catch (ParseException e) { throw new IllegalArgumentException("Can't parse date " + dateParameter); } maxDate.setTimeInMillis(date.getTime()); } else { String selector = MgnlContext.getAggregationState().getSelector(); if (StringUtils.isNotEmpty(selector)) { manipulateBySelector(maxDate, selector); } this.maxDate.set(Calendar.DATE, maxDate.getActualMaximum(Calendar.DATE)); } this.maxDate.set(Calendar.HOUR_OF_DAY, minDate.getActualMaximum(Calendar.HOUR_OF_DAY)); this.maxDate.set(Calendar.MINUTE, minDate.getActualMaximum(Calendar.MINUTE)); this.maxDate.set(Calendar.SECOND, minDate.getActualMaximum(Calendar.SECOND)); this.maxDate.set(Calendar.MILLISECOND, minDate.getActualMaximum(Calendar.MILLISECOND)); return maxDate; }
From source file:org.jfree.data.time.Millisecond.java
/** * Creates a millisecond./*from w w w. j a va 2s. c o m*/ * * @param time the date-time ({@code null} not permitted). * @param zone the time zone ({@code null} not permitted). * @param locale the locale ({@code null} not permitted). * * @since 1.0.13 */ public Millisecond(Date time, TimeZone zone, Locale locale) { Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); this.millisecond = calendar.get(Calendar.MILLISECOND); this.second = (byte) calendar.get(Calendar.SECOND); this.minute = (byte) calendar.get(Calendar.MINUTE); this.hour = (byte) calendar.get(Calendar.HOUR_OF_DAY); this.day = new Day(time, zone, locale); peg(calendar); }
From source file:com.controlj.addon.weather.wbug.service.WeatherBugDataUtils.java
/** * Extracts a timestamp from a XML element. * // w w w . ja va 2 s . c om * @param elem * the element from which the timestamp must be extracted. * @param path * the XPath to be used to locate the value. * @return the extracted timestamp. */ public static Timestamp getTimestamp(Element elem, String path) { Element timestampElem = (Element) elem.selectSingleNode(path); final String tz = WeatherBugDataUtils.getString(timestampElem, "aws:time-zone/@abbrv") != null ? WeatherBugDataUtils.getString(timestampElem, "aws:time-zone/@abbrv") : "CST"; final GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(tz)); cal.set(Calendar.YEAR, WeatherBugDataUtils.getInt(timestampElem, "aws:year/@number", -1)); cal.set(Calendar.MONTH, WeatherBugDataUtils.getInt(timestampElem, "aws:month/@number", -1) - 1); //zero based in GregorianCal cal.set(Calendar.DAY_OF_MONTH, WeatherBugDataUtils.getInt(timestampElem, "aws:day/@number", -1)); cal.set(Calendar.HOUR_OF_DAY, WeatherBugDataUtils.getInt(timestampElem, "aws:hour/@hour-24", -1)); cal.set(Calendar.MINUTE, WeatherBugDataUtils.getInt(timestampElem, "aws:minute/@number", 0)); cal.set(Calendar.SECOND, WeatherBugDataUtils.getInt(timestampElem, "aws:second/@number", 0)); cal.set(Calendar.MILLISECOND, 0); return new Timestamp(cal.getTimeInMillis()); }
From source file:com.atlassian.plugins.studio.storage.examples.it.TestSuite.java
@ToolkitTest protected void constantScopeSaveDeleteForDate() throws Exception { String name = getClass().getName() + "-saveDeleteCycle"; StorageFacade facade = storageService.constantNameStorage(name); facade.remove("date"); stateTrue("First boolean access should be null", facade.getDate("date") == null); Calendar c = Calendar.getInstance(); c.set(2010, 1, 2, 3, 4, 5);/*from w w w .j a va2 s .c o m*/ c.set(Calendar.MILLISECOND, 0); facade.setDate("date", c.getTime()); stateTrue("date key should exist now", facade.exists("date")); Calendar c2 = Calendar.getInstance(); c2.setTime(facade.getDate("date")); stateTrue("[date]=" + c.getTime() + ", actual=" + c2.getTime(), c2.getTime().equals(c.getTime())); stateTrue("delete date should work", facade.remove("date")); not("date key should NOT exist now", facade.exists("date")); }
From source file:com.linuxbox.enkive.statistics.removal.RemovalJob.java
/** * generates a date cooresponding to the amount of time each type of * statistic should be kept. For instance, if monthKeepTime is set to 3 then * 3 months will be subtracted from the current date and that date will be * returned/* w w w .j av a2s.c o m*/ * * @param time * - the identifier corresponding to the amount of time to deduct */ private void setDate(int time) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); switch (time) { case REMOVAL_MONTH_ID:// month cal.add(Calendar.MONTH, -monthKeepTime); break; case REMOVAL_WEEK_ID:// week cal.add(Calendar.WEEK_OF_YEAR, -weekKeepTime); break; case REMOVAL_DAY_ID:// day cal.add(Calendar.DATE, -dayKeepTime); break; case REMOVAL_HOUR_ID:// hour cal.add(Calendar.HOUR, -hourKeepTime); break; case REMOVAL_RAW_ID:// raw cal.add(Calendar.HOUR, -rawKeepTime); } dateFilter = cal.getTime(); }
From source file:de.hybris.platform.test.HJMPTest.java
@Test public void testWriteReadValues() { LOG.debug(">>> testWriteReadValues()"); final Float floatValue = new Float(1234.5678f); /* conv-LOG */LOG.debug(">>> Float (" + floatValue + ") <<<"); remote.setFloat(floatValue);//from ww w.j a v a 2 s . c o m assertEquals(floatValue, remote.getFloat()); final Double doubleValue = new Double(2234.5678d); /* conv-LOG */LOG.debug(">>> Double (" + doubleValue + ") <<<"); remote.setDouble(doubleValue); assertEquals(doubleValue, remote.getDouble()); final Character characterValue = Character.valueOf('g'); /* conv-LOG */LOG.debug(">>> Character (" + characterValue + ") <<<"); remote.setCharacter(characterValue); assertEquals(characterValue, remote.getCharacter()); final Integer integerValue = Integer.valueOf(3357); /* conv-LOG */LOG.debug(">>> Integer (" + integerValue + ") <<<"); remote.setInteger(integerValue); assertEquals(integerValue, remote.getInteger()); final Long longValue = Long.valueOf(4357L); /* conv-LOG */LOG.debug(">>> Long (" + longValue + ") <<<"); remote.setLong(longValue); assertEquals(longValue, remote.getLong()); final Calendar now = Utilities.getDefaultCalendar(); now.set(Calendar.MILLISECOND, 0); /* conv-LOG */LOG.debug(">>> Date (" + now + ", ms=" + now.getTime() + ")<<<"); remote.setDate(now.getTime()); final java.util.Date got = remote.getDate(); /* conv-LOG */LOG.debug(">>> found (" + got.getTime() + ")<<<"); assertEquals(now.getTime(), got); // try to get 123,4567 as big decimal final BigDecimal bigDecimalValue = BigDecimal.valueOf(1234567, 4); /* conv-LOG */LOG.debug(">>> BigDecimal (" + bigDecimalValue + ")<<<"); remote.setBigDecimal(bigDecimalValue); assertTrue(remote.getBigDecimal().compareTo(bigDecimalValue) == 0); final java.sql.Timestamp timestamp = new java.sql.Timestamp(now.getTime().getTime()); /* conv-LOG */LOG.debug(">>> Timestamp (" + timestamp + ", ms=" + timestamp.getTime() + ")<<<"); remote.setDate(timestamp); final java.util.Date got2 = remote.getDate(); /* conv-LOG */LOG.debug(">>> found (" + got2.getTime() + ")<<<"); assertEquals(now.getTime(), got2); final String str = "Alles wird gut!"; /* conv-LOG */LOG.debug(">>> String (" + str + ")<<<"); remote.setString(str); assertEquals(str, remote.getString()); final String longstr = "Alles wird lange gut!"; /* conv-LOG */LOG.debug(">>> Long String (" + longstr + ")<<<"); remote.setLongString(longstr); assertEquals(longstr, remote.getLongString()); //put 50000 chars into it String longstr2 = ""; for (int i2 = 0; i2 < 5000; i2++) { longstr2 += "01234567890"; } remote.setLongString(longstr2); assertEquals(longstr2, remote.getLongString()); /* * remote.setString( "" ); assertEquals( "" , remote.getString() ); remote.setString( null ); assertNull( * remote.getString() ); remote.setLongString( "" ); assertEquals( "" , remote.getLongString() ); * remote.setLongString( null ); assertNull( remote.getLongString() ); */ final Boolean booleanValue = Boolean.TRUE; /* conv-LOG */LOG.debug(">>> Boolean (" + booleanValue + ")<<<"); remote.setBoolean(booleanValue); assertEquals(booleanValue, remote.getBoolean()); final float floatValue2 = 5234.5678f; /* conv-LOG */LOG.debug(">>> float (" + floatValue2 + ") <<<"); remote.setPrimitiveFloat(floatValue2); assertTrue(">>> float (" + floatValue2 + ") <<<", floatValue2 == remote.getPrimitiveFloat()); final double doubleValue2 = 6234.5678d; /* conv-LOG */LOG.debug(">>> double (" + doubleValue2 + ") <<<"); remote.setPrimitiveDouble(doubleValue2); assertTrue(">>> double (" + doubleValue2 + ") <<<", doubleValue2 == remote.getPrimitiveDouble()); final int integerValue2 = 7357; /* conv-LOG */LOG.debug(">>> int (" + integerValue2 + ") <<<"); remote.setPrimitiveInteger(integerValue2); assertTrue(integerValue2 == remote.getPrimitiveInteger()); final long longValue2 = 8357L; /* conv-LOG */LOG.debug(">>> long (" + longValue2 + ") <<<"); remote.setPrimitiveLong(longValue2); assertTrue(">>> long (" + longValue2 + ") <<<", longValue2 == remote.getPrimitiveLong()); final byte byteValue = 123; /* conv-LOG */LOG.debug(">>> byte (" + byteValue + ") <<<"); remote.setPrimitiveByte(byteValue); assertTrue(">>> byte (" + byteValue + ") <<<", byteValue == remote.getPrimitiveByte()); final boolean booleanValue2 = true; /* conv-LOG */LOG.debug(">>> boolean (" + booleanValue2 + ") <<<"); remote.setPrimitiveBoolean(booleanValue2); assertTrue(">>> boolean (" + booleanValue2 + ") <<<", booleanValue2 == remote.getPrimitiveBoolean()); final char characterValue2 = 'g'; /* conv-LOG */LOG.debug(">>> char (" + characterValue2 + ") <<<"); remote.setPrimitiveChar(characterValue2); assertTrue(">>> char (" + characterValue2 + ") <<<", characterValue2 == remote.getPrimitiveChar()); final ArrayList list = new ArrayList(); LOG.debug(">>> Serializable with standard classes (" + list + ") <<<"); remote.setSerializable(list); assertEquals(list, remote.getSerializable()); if (!Config.isOracleUsed()) { try { final HashMap bigtest = new HashMap(); LOG.debug(">>> Serializable with standard classes (big thing) <<<"); final byte[] byteArray = new byte[100000]; bigtest.put("test", byteArray); remote.setSerializable(bigtest); final Map longtestret = (Map) remote.getSerializable(); assertTrue(longtestret.size() == 1); final byte[] byteArray2 = (byte[]) longtestret.get("test"); assertTrue(byteArray2.length == 100000); } catch (final Exception e) { throw new JaloSystemException(e, "Unable to write big serializable object, db: " + Config.getDatabase() + ".", 0); } } /* conv-LOG */LOG.debug(">>> Serializable (null) <<<"); remote.setSerializable(null); assertNull(remote.getSerializable()); // try // { // final Dummy dummy = new Dummy(); // /*conv-LOG*/ LOG.debug(">>> Serializable with custom classes ("+dummy+") <<<"); // remote.setSerializable( dummy ); // final Serializable x = remote.getSerializable(); // assertTrue( dummy.equals( x ) || x == null ); // if( x == null ) // /*conv-LOG*/ LOG.debug(">>> ok, we're still unable of writing non-serverside classes to database : read NULL "); // } // catch( Exception e ) // { // /*conv-LOG*/ LOG.debug(">>> ok, we're still unable of writing non-serverside classes to database : " + e ); // } // // search // try { /* conv-LOG */LOG.debug(">>> Search ( " + str + ", " + integerValue2 + " ) <<<"); home.finderTest(str, integerValue2); } catch (final Exception e) { e.printStackTrace(); fail("TestItem not found!"); } // // 'null' tests // /* conv-LOG */LOG.debug(">>> String (null) <<<"); remote.setString(null); assertNull(remote.getString()); /* conv-LOG */LOG.debug(">>> Character (null) <<<"); remote.setCharacter(null); assertNull(remote.getCharacter()); /* conv-LOG */LOG.debug(">>> Integer (null) <<<"); remote.setInteger(null); assertNull(remote.getInteger()); /* conv-LOG */LOG.debug(">>> Date (null) <<<"); remote.setDate(null); assertNull(remote.getDate()); /* conv-LOG */LOG.debug(">>> Double (null) <<<"); remote.setDouble(null); assertNull(remote.getDouble()); /* conv-LOG */LOG.debug(">>> Float (null) <<<"); remote.setFloat(null); assertNull(remote.getFloat()); }