List of usage examples for java.util Calendar HOUR
int HOUR
To view the source code for java.util Calendar HOUR.
Click Source Link
get
and set
indicating the hour of the morning or afternoon. From source file:org.duracloud.mill.manifest.cleaner.ManifestCleanerDriver.java
/** * @param time/*from ww w . ja v a2 s. com*/ * @return * @throws ParseException */ private Date parseExpirationDate(String time) throws ParseException { Calendar c = Calendar.getInstance(); String pattern = "([0-9]+)([smhd])"; if (!time.matches(pattern)) { throw new ParseException(time + " is not a valid time value."); } int amount = Integer.parseInt(time.replaceAll(pattern, "$1")); String units = time.replaceAll(pattern, "$2"); int field = Calendar.SECOND; if (units.equals("m")) { field = Calendar.MINUTE; } else if (units.equals("h")) { field = Calendar.HOUR; } else if (units.equals("d")) { field = Calendar.DATE; } else { // should never happen. throw new RuntimeException("unit " + units + " not recognized."); } c.add(field, -1 * amount); return c.getTime(); }
From source file:org.vietspider.server.handler.cms.metas.IndexSearchHandler.java
public String handle(final HttpRequest request, final HttpResponse response, final HttpContext context, String... params) throws Exception { String pattern = params[1];//from ww w . ja va 2 s . c o m int idx = pattern.indexOf('='); if (idx < 0 || idx >= pattern.length() - 1) { throw new IndexOutOfBoundsException("Incorrect parammeter"); } String search = URLDecoder.decode(pattern.substring(idx + 1), "UTF-8"); pattern = search; MetaList metas = new MetaList(); metas.setAction("SEARCH"); metas.setCurrentPage(Integer.parseInt(params[0])); String[][] parameters = ParameterParser.getParameters(params[1]); /*SearchQuery query = null; if(parameters.length > 0) { query = new SearchQuery(parameters[0][1]); // for(int i = 1; i < parameters.length; i++) { // if("region".equalsIgnoreCase(parameters[i][0])) { // query.setRegion(parameters[i][1]); // } // } } else { throw new IndexOutOfBoundsException("Incorrect parammeter"); }*/ ArticleSearchQuery query = new ArticleSearchQuery(); for (int i = 0; i < parameters.length; i++) { if (parameters[i][0].charAt(0) == '?') { parameters[i][0] = parameters[i][0].substring(1); } // System.out.println(parameters[i][0] + " : "+ parameters[i][1]); if (parameters[i][0].equals("text")) { query.setPattern(parameters[i][1]); } else if (parameters[i][0].equals("source")) { query.setSource(parameters[i][1]); } else if (parameters[i][0].equals("dtstart")) { parameters[i][1] = parameters[i][1].replace('.', '/'); try { SimpleDateFormat dateFormat = CalendarUtils.getDateFormat(); Date date = dateFormat.parse(parameters[i][1]); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); query.setIndexFrom(calendar.getTimeInMillis()); } catch (Exception e) { LogService.getInstance().setMessage(e, e.toString()); } } else if (parameters[i][0].equals("dtend")) { parameters[i][1] = parameters[i][1].replace('.', '/'); try { SimpleDateFormat dateFormat = CalendarUtils.getDateFormat(); Date date = dateFormat.parse(parameters[i][1]); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1); query.setIndexTo(calendar.getTimeInMillis()); } catch (Exception e) { LogService.getInstance().setMessage(e, e.toString()); } } } if (Application.LICENSE != Install.PERSONAL) { // ArticleSearchQuery query = new ArticleSearchQuery(parameters[0][1]); query.setHighlightStart("<b style=\"color: black; background-color: rgb(255, 255, 102);\">"); query.setHighlightEnd("</b>"); ArticleIndexStorage.getInstance().search(metas, query); } // System.out.println("thay co " + metas.getData().size()); // System.out.println(parameters[0][1]); // File tempFolder = UtilFile.getFolder("content/temp/search/"); // ContentSearcher2 searcher = new ContentSearcher2(ContentSearcher2.SIMPLE, tempFolder); // HighlightBuilder highlighter = new HighlightBuilder(query.getPattern().toLowerCase()); // highlighter.setHighlightTag("<b style=\"color: black; background-color: rgb(255, 255, 102);\">", "</b>"); // query.setParser(new QueryParser()); // DefaultArticleHandler articleHandler2 = new DefaultArticleHandler(highlighter); // searcher.search(metas, query, articleHandler2); // ContentSearcher searcher = new ContentSearcher(); // searcher.search(metas, pattern); WebRM resources = new WebRM(); StringBuilder builder = new StringBuilder(resources.getLabel("search")); metas.setTitle(builder.toString()); metas.setUrl(params[1]); return write(request, response, context, metas, params); }
From source file:helper.lang.DateHelperTest.java
@Test public void testGetRangeDaysBeforeTodayUtc() { int days = 1; Calendar nowUtc = DateHelper.nowUtc(); CalendarRange range = DateHelper.getRangeFullDaysBefore(nowUtc, days); Calendar start = range.getStart(); Calendar end = range.getEnd(); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(start)); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(end)); // end date is midnight of date passed in assertEquals(nowUtc.get(Calendar.YEAR), end.get(Calendar.YEAR)); assertEquals(nowUtc.get(Calendar.MONTH), end.get(Calendar.MONTH)); assertEquals(nowUtc.get(Calendar.DATE), end.get(Calendar.DATE)); assertEquals(0, end.get(Calendar.HOUR)); assertEquals(0, end.get(Calendar.MINUTE)); assertEquals(0, end.get(Calendar.SECOND)); assertEquals(0, end.get(Calendar.MILLISECOND)); assertEquals(0, end.get(Calendar.HOUR_OF_DAY)); assertEquals(DateHelper.UTC_TIME_ZONE, end.getTimeZone()); // start date is 11:59:59 or 'days' time nowUtc.add(Calendar.DATE, -(days + 2)); assertEquals(nowUtc.get(Calendar.YEAR), start.get(Calendar.YEAR)); assertEquals(nowUtc.get(Calendar.MONTH), start.get(Calendar.MONTH)); assertEquals(nowUtc.get(Calendar.DATE), start.get(Calendar.DATE)); assertEquals(11, start.get(Calendar.HOUR)); assertEquals(23, start.get(Calendar.HOUR_OF_DAY)); assertEquals(59, start.get(Calendar.MINUTE)); assertEquals(59, start.get(Calendar.SECOND)); assertEquals(999, start.get(Calendar.MILLISECOND)); assertEquals(DateHelper.UTC_TIME_ZONE, start.getTimeZone()); }
From source file:com.netflix.simianarmy.basic.sniper.BasicSniperMonkey.java
/** * Instantiates a new basic sniper monkey. * @param ctx//from w ww. ja va 2 s.c o m * the ctx */ public BasicSniperMonkey(SniperMonkey.Context ctx) { super(ctx); this.cfg = ctx.configuration(); this.monkeyCalendar = ctx.calendar(); Calendar open = monkeyCalendar.now(); Calendar close = monkeyCalendar.now(); open.set(Calendar.HOUR, monkeyCalendar.openHour()); close.set(Calendar.HOUR, monkeyCalendar.closeHour()); TimeUnit freqUnit = ctx.scheduler().frequencyUnit(); long units = freqUnit.convert(close.getTimeInMillis() - open.getTimeInMillis(), TimeUnit.MILLISECONDS); runsPerDay = units / ctx.scheduler().frequency(); privateKey = this.cfg.getStr("simianarmy.sniper.privateKey"); user = this.cfg.getStr("simianarmy.sniper.user"); process = this.cfg.getStr("simianarmy.sniper.process"); }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.NSFCoverPageBaseGenerator.java
/** * //from ww w . j a v a 2 s .com * This method Converts the String that is passed to it into a calendar * object. The argument will be set as the Year in the Calendar Object. * * @param year - * The String value to be converted to Calendar Object * @return calendar value corresponding to the year(String) passed. */ public Calendar getYearAsCalendar(String year) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.DATE, 0); calendar.set(Calendar.MONTH, 0); try { calendar.set(Calendar.YEAR, Integer.parseInt(year)); } catch (NumberFormatException ex) { calendar.set(Calendar.YEAR, 0); } return calendar; }
From source file:helper.util.DateHelper.java
/** * Take a local time calendar and represent it as a UTC day * (truncate to day, retain yy/mm/dd from original date) **//*from www.ja v a 2 s .c om*/ public static Calendar asUtcDay(Calendar localTimeCalendar) { Calendar utcDate = Calendar.getInstance(DateUtils.UTC_TIME_ZONE); utcDate.clear(); utcDate.set(localTimeCalendar.get(Calendar.YEAR), localTimeCalendar.get(Calendar.MONTH), localTimeCalendar.get(Calendar.DATE), 0, 0, 0); utcDate.set(Calendar.AM_PM, Calendar.AM); utcDate.set(Calendar.MILLISECOND, 0); utcDate.set(Calendar.HOUR, 0); return utcDate; }
From source file:com.antsdb.saltedfish.sql.vdm.FuncDateFormat.java
private String format(String format, Timestamp time) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < format.length(); i++) { char ch = format.charAt(i); if (ch != '%') { buf.append(ch);//from w w w.j av a 2 s. c o m continue; } if (i >= (format.length() - 1)) { buf.append(ch); continue; } char specifier = format.charAt(++i); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time.getTime()); if (specifier == 'a') { throw new NotImplementedException(); } else if (specifier == 'b') { throw new NotImplementedException(); } else if (specifier == 'c') { buf.append(calendar.get(Calendar.MONTH + 1)); } else if (specifier == 'd') { int day = calendar.get(Calendar.DAY_OF_MONTH); if (day < 10) { buf.append('0'); } buf.append(day); } else if (specifier == 'D') { throw new NotImplementedException(); } else if (specifier == 'e') { buf.append(calendar.get(Calendar.DAY_OF_MONTH)); } else if (specifier == 'f') { buf.append(calendar.get(Calendar.MILLISECOND * 1000)); } else if (specifier == 'H') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'h') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'i') { buf.append(calendar.get(Calendar.MINUTE)); } else if (specifier == 'I') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'j') { buf.append(calendar.get(Calendar.DAY_OF_YEAR)); } else if (specifier == 'k') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'l') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'm') { int month = calendar.get(Calendar.MONTH) + 1; if (month < 10) { buf.append('0'); } buf.append(calendar.get(Calendar.MONTH) + 1); } else if (specifier == 'M') { buf.append(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())); } else if (specifier == 'p') { int hour = calendar.get(Calendar.HOUR); buf.append(hour < 12 ? "AM" : "PM"); } else if (specifier == 'r') { int hour = calendar.get(Calendar.HOUR); hour = hour % 13; if (hour < 10) { buf.append('0'); } buf.append(hour); buf.append(':'); int minute = calendar.get(Calendar.MINUTE); if (minute < 10) { buf.append('0'); } buf.append(minute); buf.append(':'); int second = calendar.get(Calendar.SECOND); if (second < 10) { buf.append('0'); } buf.append(second); buf.append(hour < 12 ? " AM" : " PM"); } else if (specifier == 's') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'S') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'T') { throw new NotImplementedException(); } else if (specifier == 'u') { buf.append(calendar.get(Calendar.WEEK_OF_YEAR)); } else if (specifier == 'U') { throw new NotImplementedException(); } else if (specifier == 'v') { throw new NotImplementedException(); } else if (specifier == 'V') { throw new NotImplementedException(); } else if (specifier == 'w') { throw new NotImplementedException(); } else if (specifier == 'W') { throw new NotImplementedException(); } else if (specifier == 'x') { throw new NotImplementedException(); } else if (specifier == 'X') { throw new NotImplementedException(); } else if (specifier == 'y') { buf.append(calendar.get(Calendar.YEAR) % 100); } else if (specifier == 'Y') { buf.append(calendar.get(Calendar.YEAR)); } else if (specifier == '%') { buf.append('%'); } else { buf.append(specifier); } } return buf.toString(); }
From source file:net.firejack.platform.processor.statistics.StatisticsProcessor.java
@Scheduled(cron = "0 0/5 * * * *") public void schedulerStatisticsHandler() { if (templates != null) { for (HibernateTemplate template : templates) { SessionFactory sessionFactory = template.getSessionFactory(); Statistics statistics = sessionFactory.getStatistics(); if (statistics.isStatisticsEnabled()) { LogTransaction logTransaction = new LogTransaction(); logTransaction.setPackageLookup(OpenFlameSecurityConstants.getPackageLookup()); logTransaction.setTransactions(statistics.getSuccessfulTransactionCount()); logTransaction.setEntitiesLoaded(statistics.getEntityLoadCount()); logTransaction.setEntitiesInserted(statistics.getEntityInsertCount()); logTransaction.setEntitiesUpdated(statistics.getEntityUpdateCount()); logTransaction.setEntitiesDeleted(statistics.getEntityDeleteCount()); logTransaction.setEntitiesFetched(statistics.getEntityFetchCount()); logTransaction.setCollectionsLoaded(statistics.getCollectionLoadCount()); logTransaction.setCollectionsRecreated(statistics.getCollectionRecreateCount()); logTransaction.setCollectionsUpdated(statistics.getCollectionUpdateCount()); logTransaction.setCollectionsRemoved(statistics.getCollectionRemoveCount()); logTransaction.setCollectionsFetched(statistics.getCollectionFetchCount()); logTransaction.setMaxQueryTime(statistics.getQueryExecutionMaxTime()); Date hourlyDate = new Date(); logTransaction.setHourPeriod(DateUtils.truncate(hourlyDate, Calendar.HOUR).getTime()); logTransaction.setDayPeriod(DateUtils.truncate(hourlyDate, Calendar.DAY_OF_MONTH).getTime()); logTransaction.setWeekPeriod(DateUtils.truncateDateToWeek(hourlyDate).getTime()); logTransaction.setMonthPeriod(DateUtils.truncate(hourlyDate, Calendar.MONTH).getTime()); OPFEngine.StatisticsService.saveLogTransaction(logTransaction); statistics.clear();//from w w w . j a v a2s .c o m } else { logger.warn("Hibernate Statistics is disabled."); } } } }
From source file:it.govpay.web.rs.dars.base.StatisticaDarsHandler.java
protected Date calcolaAvanzamento(Date data, int avanzamento, TipoIntervallo tipoIntervallo) throws ConsoleException { if (avanzamento != 0) { Calendar calendar = Calendar.getInstance(); calendar.setTime(data);/*w ww . j a v a 2 s .com*/ switch (tipoIntervallo) { case MENSILE: calendar.add(Calendar.MONTH, avanzamento); break; case GIORNALIERO: calendar.add(Calendar.DATE, avanzamento); break; case ORARIO: calendar.add(Calendar.HOUR, avanzamento); break; } return calendar.getTime(); } return data; }
From source file:CalendarUtilsTest.java
/** * Tests various values with the round method *///from w w w .j ava 2 s . com public void testRound() throws Exception { assertEquals("round year-1 failed", new Date("2002 January 1"), CalendarUtils.round(date1, Calendar.YEAR)); assertEquals("round year-2 failed", new Date("2002 January 1"), CalendarUtils.round(date2, Calendar.YEAR)); assertEquals("round month-1 failed", new Date("2002 February 1"), CalendarUtils.round(date1, Calendar.MONTH)); assertEquals("round month-2 failed", new Date("2001 December 1"), CalendarUtils.round(date2, Calendar.MONTH)); assertEquals("round semimonth-1 failed", new Date("2002 February 16"), CalendarUtils.round(date1, CalendarUtils.SEMI_MONTH)); assertEquals("round semimonth-2 failed", new Date("2001 November 16"), CalendarUtils.round(date2, CalendarUtils.SEMI_MONTH)); assertEquals("round date-1 failed", new Date("2002 February 13"), CalendarUtils.round(date1, Calendar.DATE)); assertEquals("round date-2 failed", new Date("2001 November 18"), CalendarUtils.round(date2, Calendar.DATE)); assertEquals("round hour-1 failed", parser.parse("February 12, 2002 13:00:00.000"), CalendarUtils.round(date1, Calendar.HOUR)); assertEquals("round hour-2 failed", parser.parse("November 18, 2001 1:00:00.000"), CalendarUtils.round(date2, Calendar.HOUR)); assertEquals("round minute-1 failed", parser.parse("February 12, 2002 12:35:00.000"), CalendarUtils.round(date1, Calendar.MINUTE)); assertEquals("round minute-2 failed", parser.parse("November 18, 2001 1:23:00.000"), CalendarUtils.round(date2, Calendar.MINUTE)); assertEquals("round second-1 failed", parser.parse("February 12, 2002 12:34:57.000"), CalendarUtils.round(date1, Calendar.SECOND)); assertEquals("round second-2 failed", parser.parse("November 18, 2001 1:23:11.000"), CalendarUtils.round(date2, Calendar.SECOND)); }