List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:org.eclipse.dirigible.repository.local.FileSystemRepository.java
@Override public void cleanupOldVersions() throws IOException { String versionsRoot = getVersionsPath(); synchronized (this.getClass()) { GregorianCalendar last = new GregorianCalendar(); last.add(Calendar.WEEK_OF_YEAR, -1); thresholdDate = last.getTime(); cleanOlderFiles(new File(versionsRoot)); }/*from w w w . jav a 2s. co m*/ }
From source file:org.alfresco.provision.AWSService.java
public Metrics getMetrics(String instanceId, List<String> measureNames) { GetMetricStatisticsRequest getMetricRequest = new GetMetricStatisticsRequest(); getMetricRequest.setNamespace("AWS/EC2"); getMetricRequest.setPeriod(60);/*from w w w . j av a 2 s . c om*/ List<String> stats = new LinkedList<>(); stats.add("Average"); getMetricRequest.setStatistics(stats); getMetricRequest.setNamespace("AWS/EC2"); Dimension dimension = new Dimension(); dimension.withName("InstanceId").withValue(instanceId); getMetricRequest.setDimensions(Arrays.asList(dimension)); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.add(GregorianCalendar.SECOND, -1 * calendar.get(GregorianCalendar.SECOND)); getMetricRequest.setEndTime(calendar.getTime()); calendar.add(GregorianCalendar.MINUTE, -10); getMetricRequest.setStartTime(calendar.getTime()); Map<Long, Metrics> measureSets = new HashMap<>(); for (String measureName : measureNames) { getMetricRequest.setMetricName(measureName); GetMetricStatisticsResult metricStatistics = cloudWatchClient.getMetricStatistics(getMetricRequest); List<Datapoint> datapoints = metricStatistics.getDatapoints(); for (Datapoint point : datapoints) { Calendar cal = new GregorianCalendar(); cal.setTime(point.getTimestamp()); Metrics measureSet = measureSets.get(cal.getTimeInMillis()); if (measureSet == null) { measureSet = new Metrics(); measureSet.timestamp = cal; measureSets.put(cal.getTimeInMillis(), measureSet); } measureSet.setMetric(measureName, point.getAverage()); } } List<Metrics> sortedMeasureSets = new ArrayList<>(measureSets.values()); if (sortedMeasureSets.size() == 0) { return null; } else { Collections.sort(sortedMeasureSets); return sortedMeasureSets.get(sortedMeasureSets.size() - 1); } }
From source file:org.sufficientlysecure.keychain.keyimport.HkpKeyServer.java
@Override public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, InsufficientQuery { ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>(); if (query.length() < 3) { throw new InsufficientQuery(); }//from w ww .j a v a2 s . c om String encodedQuery; try { encodedQuery = URLEncoder.encode(query, "utf8"); } catch (UnsupportedEncodingException e) { return null; } String request = "/pks/lookup?op=index&options=mr&search=" + encodedQuery; String data; try { data = query(request); } catch (HttpError e) { if (e.getCode() == 404) { return results; } else { if (e.getData().toLowerCase(Locale.US).contains("no keys found")) { return results; } else if (e.getData().toLowerCase(Locale.US).contains("too many")) { throw new TooManyResponses(); } else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) { throw new InsufficientQuery(); } } throw new QueryException("querying server(s) for '" + mHost + "' failed"); } final Matcher matcher = PUB_KEY_LINE.matcher(data); while (matcher.find()) { final ImportKeysListEntry entry = new ImportKeysListEntry(); entry.setBitStrength(Integer.parseInt(matcher.group(3))); final int algorithmId = Integer.decode(matcher.group(2)); entry.setAlgorithm(PgpKeyHelper.getAlgorithmInfo(algorithmId)); // group 1 contains the full fingerprint (v4) or the long key id if available // see http://bit.ly/1d4bxbk and http://bit.ly/1gD1wwr String fingerprintOrKeyId = matcher.group(1); if (fingerprintOrKeyId.length() > 16) { entry.setFingerprintHex(fingerprintOrKeyId.toLowerCase(Locale.US)); entry.setKeyIdHex("0x" + fingerprintOrKeyId.substring(fingerprintOrKeyId.length() - 16, fingerprintOrKeyId.length())); } else { // set key id only entry.setKeyIdHex("0x" + fingerprintOrKeyId); } final long creationDate = Long.parseLong(matcher.group(4)); final GregorianCalendar tmpGreg = new GregorianCalendar(TimeZone.getTimeZone("UTC")); tmpGreg.setTimeInMillis(creationDate * 1000); entry.setDate(tmpGreg.getTime()); entry.setRevoked(matcher.group(6).contains("r")); ArrayList<String> userIds = new ArrayList<String>(); final String uidLines = matcher.group(7); final Matcher uidMatcher = UID_LINE.matcher(uidLines); while (uidMatcher.find()) { String tmp = uidMatcher.group(1).trim(); if (tmp.contains("%")) { try { // converts Strings like "Universit%C3%A4t" to a proper encoding form "Universitt". tmp = (URLDecoder.decode(tmp, "UTF8")); } catch (UnsupportedEncodingException ignored) { // will never happen, because "UTF8" is supported } } userIds.add(tmp); } entry.setUserIds(userIds); entry.setPrimaryUserId(userIds.get(0)); results.add(entry); } return results; }
From source file:org.thialfihar.android.apg.keyimport.HkpKeyserver.java
@Override public ArrayList<ImportKeysListEntry> search(String query) throws QueryFailedException, QueryNeedsRepairException { ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>(); if (query.length() < 3) { throw new QueryTooShortException(); }/*from w ww.j a va 2 s .c o m*/ String encodedQuery; try { encodedQuery = URLEncoder.encode(query, "utf8"); } catch (UnsupportedEncodingException e) { return null; } String request = "/pks/lookup?op=index&options=mr&search=" + encodedQuery; String data; try { data = query(request); } catch (HttpError e) { if (e.getCode() == 404) { return results; } else { if (e.getData().toLowerCase(Locale.US).contains("no keys found")) { return results; } else if (e.getData().toLowerCase(Locale.US).contains("too many")) { throw new TooManyResponsesException(); } else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) { throw new QueryTooShortException(); } } throw new QueryFailedException("querying server(s) for '" + mHost + "' failed"); } final Matcher matcher = PUB_KEY_LINE.matcher(data); while (matcher.find()) { final ImportKeysListEntry entry = new ImportKeysListEntry(); entry.setQuery(query); entry.setBitStrength(Integer.parseInt(matcher.group(3))); final int algorithmId = Integer.decode(matcher.group(2)); entry.setAlgorithm(PgpKeyHelper.getAlgorithmInfo(algorithmId)); // group 1 contains the full fingerprint (v4) or the long key id if available // see http://bit.ly/1d4bxbk and http://bit.ly/1gD1wwr String fingerprintOrKeyId = matcher.group(1); if (fingerprintOrKeyId.length() > 16) { entry.setFingerprintHex(fingerprintOrKeyId.toLowerCase(Locale.US)); entry.setKeyIdHex("0x" + fingerprintOrKeyId.substring(fingerprintOrKeyId.length() - 16, fingerprintOrKeyId.length())); } else { // set key id only entry.setKeyIdHex("0x" + fingerprintOrKeyId); } final long creationDate = Long.parseLong(matcher.group(4)); final GregorianCalendar tmpGreg = new GregorianCalendar(TimeZone.getTimeZone("UTC")); tmpGreg.setTimeInMillis(creationDate * 1000); entry.setDate(tmpGreg.getTime()); entry.setRevoked(matcher.group(6).contains("r")); ArrayList<String> userIds = new ArrayList<String>(); final String uidLines = matcher.group(7); final Matcher uidMatcher = UID_LINE.matcher(uidLines); while (uidMatcher.find()) { String tmp = uidMatcher.group(1).trim(); if (tmp.contains("%")) { try { // converts Strings like "Universit%C3%A4t" to a proper encoding form "Universitt". tmp = (URLDecoder.decode(tmp, "UTF8")); } catch (UnsupportedEncodingException ignored) { // will never happen, because "UTF8" is supported } } userIds.add(tmp); } entry.setUserIds(userIds); entry.setPrimaryUserId(userIds.get(0)); results.add(entry); } return results; }
From source file:com.alkacon.opencms.calendar.CmsSerialDateWidget.java
/** * Returns the given timestamp as String formatted in a localized pattern.<p> * //from ww w .ja v a 2 s. c o m * @param locale the locale for the time format * @param messages the messages that contain the time format definitions * @param timestamp the time to format * @param showDate flag to show the date in the formatted String * @param showTime flag to show the time in the formatted String * * @return the given timestamp as String formatted in a localized pattern */ public static String getCalendarLocalizedTime(Locale locale, CmsMessages messages, long timestamp, boolean showDate, boolean showTime) { // get the current date & time TimeZone zone = TimeZone.getDefault(); GregorianCalendar cal = new GregorianCalendar(zone, locale); cal.setTimeInMillis(timestamp); String datePattern = ""; if (showDate) { datePattern = messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0); if (showTime) { datePattern += " "; } } if (showTime) { datePattern += messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0); } // format it nicely according to the localized pattern DateFormat df = new SimpleDateFormat(CmsCalendarWidget.getCalendarJavaDateFormat(datePattern)); return df.format(cal.getTime()); }
From source file:edu.umm.radonc.ca_dash.controllers.HistogramController.java
public void onSelectTimePeriod() { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate);/*from w w w. j a va 2 s . c o m*/ switch (interval) { case "1wk": gc.add(Calendar.DATE, 7); endDate = gc.getTime(); break; case "1m": gc.add(Calendar.MONTH, 1); endDate = gc.getTime(); break; case "3m": gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "6m": gc.add(Calendar.MONTH, 6); endDate = gc.getTime(); break; case "1y": gc.add(Calendar.YEAR, 1); endDate = gc.getTime(); break; case "2y": gc.add(Calendar.YEAR, 2); endDate = gc.getTime(); break; case "3y": gc.add(Calendar.YEAR, 3); endDate = gc.getTime(); break; case "Q1": gc.setTime(FiscalDate.getQuarter(1)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "Q2": gc.setTime(FiscalDate.getQuarter(2)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "Q3": gc.setTime(FiscalDate.getQuarter(3)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "Q4": gc.setTime(FiscalDate.getQuarter(4)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; } }
From source file:org.thialfihar.android.apg.pgp.HkpKeyServer.java
@Override public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, InsufficientQuery { ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>(); if (query.length() < 3) { throw new InsufficientQuery(); }// w ww . j a va 2 s. c om String encodedQuery; try { encodedQuery = URLEncoder.encode(query, "utf8"); } catch (UnsupportedEncodingException e) { return null; } String request = "/pks/lookup?op=index&options=mr&search=" + encodedQuery; String data; try { data = query(request); } catch (HttpError e) { if (e.getCode() == 404) { return results; } else { if (e.getData().toLowerCase(Locale.US).contains("no keys found")) { return results; } else if (e.getData().toLowerCase(Locale.US).contains("too many")) { throw new TooManyResponses(); } else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) { throw new InsufficientQuery(); } } throw new QueryException("querying server(s) for '" + mHost + "' failed"); } final Matcher matcher = PUB_KEY_LINE.matcher(data); while (matcher.find()) { final ImportKeysListEntry entry = new ImportKeysListEntry(); entry.setBitStrength(Integer.parseInt(matcher.group(3))); final int algorithmId = Integer.decode(matcher.group(2)); entry.setAlgorithm(ImportKeysListEntry.getAlgorithmFromId(algorithmId)); // group 1 contains the full fingerprint (v4) or the long key id if available // see http://bit.ly/1d4bxbk and http://bit.ly/1gD1wwr String fingerprintOrKeyId = matcher.group(1); if (fingerprintOrKeyId.length() > 16) { entry.setFingerPrintHex(fingerprintOrKeyId.toLowerCase(Locale.US)); entry.setKeyIdHex("0x" + fingerprintOrKeyId.substring(fingerprintOrKeyId.length() - 16, fingerprintOrKeyId.length())); } else { // set key id only entry.setKeyIdHex("0x" + fingerprintOrKeyId); } final long creationDate = Long.parseLong(matcher.group(4)); final GregorianCalendar tmpGreg = new GregorianCalendar(TimeZone.getTimeZone("UTC")); tmpGreg.setTimeInMillis(creationDate * 1000); entry.setDate(tmpGreg.getTime()); entry.setRevoked(matcher.group(6).contains("r")); ArrayList<String> userIds = new ArrayList<String>(); final String uidLines = matcher.group(7); final Matcher uidMatcher = UID_LINE.matcher(uidLines); while (uidMatcher.find()) { String tmp = uidMatcher.group(1).trim(); if (tmp.contains("%")) { try { // converts Strings like "Universit%C3%A4t" to a proper encoding form "Universitt". tmp = (URLDecoder.decode(tmp, "UTF8")); } catch (UnsupportedEncodingException ignored) { // will never happen, because "UTF8" is supported } } userIds.add(tmp); } entry.setUserIds(userIds); results.add(entry); } return results; }
From source file:edu.umm.radonc.ca_dash.model.ActivityFacade.java
public TreeMap<Date, SynchronizedDescriptiveStatistics> getWeeklyTrailingSummaryStats(Date start, Date end, Long hospitalser, boolean imrtOnly, boolean includeWeekends) { TreeMap<Date, SynchronizedDescriptiveStatistics> retval = new TreeMap(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(end);/*from ww w . j a va 2 s. co m*/ Date d; SynchronizedDescriptiveStatistics stats; while (gc.getTime().compareTo(start) > 0) { d = gc.getTime(); gc.add(Calendar.DATE, -7); if (hospitalser <= 0) { stats = getDailyStats(gc.getTime(), d, imrtOnly, includeWeekends); } else { stats = getDailyStats(gc.getTime(), d, hospitalser, imrtOnly, includeWeekends); } retval.put(gc.getTime(), stats); } return retval; }
From source file:org.novoj.utils.datePattern.DatePatternConverter.java
/** * Method returns date object with normalized date: * - when pattern doesn't contain year pattern -> current year is used * - when pattern doesn't contain month pattern * date represents current year -> current month is used * else -> january is used * - when pattern doesn't contain day pattern * date represents current year and month -> current day is used * else -> first day of month is used *//*from ww w . j a v a 2 s .co m*/ private static Date normalizeDate(Calendar nowCld, Date date, Locale locale, String pattern) { GregorianCalendar dateCld = new GregorianCalendar(); dateCld.setTime(date); //set current date if (pattern.toLowerCase(locale).indexOf('y') == -1) { dateCld.set(Calendar.YEAR, nowCld.get(Calendar.YEAR)); } if (pattern.indexOf('M') == -1) { if (nowCld.get(Calendar.YEAR) == dateCld.get(Calendar.YEAR)) { dateCld.set(Calendar.MONTH, nowCld.get(Calendar.MONTH)); } else { dateCld.set(Calendar.MONTH, 0); } } if (pattern.toLowerCase(locale).indexOf('d') == -1) { if (nowCld.get(Calendar.YEAR) != dateCld.get(Calendar.YEAR) || nowCld.get(Calendar.MONTH) != dateCld.get(Calendar.MONTH)) { dateCld.set(Calendar.DAY_OF_MONTH, 1); } else { dateCld.set(Calendar.DAY_OF_MONTH, nowCld.get(Calendar.DAY_OF_MONTH)); } } return dateCld.getTime(); }
From source file:org.nuclos.common2.DateUtils.java
public static Date calc(String calculation) { calculation = calculation.toUpperCase(); GregorianCalendar result = new GregorianCalendar(); result.setTime(today());/*from ww w . j av a2 s . c o m*/ StringBuffer operand = new StringBuffer(); CalcFunction cf = null; for (int i = 0; i < calculation.length(); i++) { char c = calculation.charAt(i); switch (c) { case '+': case '-': case '.': if (cf != null) { calc(result, cf, getCalcPair(operand.toString())); operand = new StringBuffer(); } break; } switch (c) { case '+': cf = CalcFunction.ADD; break; case '-': cf = CalcFunction.SUBTRACT; break; case '.': cf = CalcFunction.SET; break; default: operand.append(c); } } if (operand.length() > 0 && cf != null) { calc(result, cf, getCalcPair(operand.toString())); } return result.getTime(); }