List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:no.dusken.aranea.web.control.IssueController.java
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws PageNotFoundException { // this content does not change that often, allow two hours cache response.setHeader("Cache-Control", "max-age=72000"); Map<String, Object> map = new HashMap<String, Object>(); map.put("baseImageDir", "/images"); // LinkedHashMap maintains order... Map<Integer, Collection> issueMap = new LinkedHashMap<Integer, Collection>(); int year = 0; List<Issue> issues;/* w w w . j av a2 s.c o m*/ if (request.getParameter("year") != null) { try { year = ServletRequestUtils.getIntParameter(request, "year"); issues = issueService.getIssuesPublished(year); if (issues == null || issues.size() == 0) { //Throwing exception so this can be threated as a 404 error on a higher level throw new PageNotFoundException("Issue in year " + year); } issueMap.put(year, issues); } catch (ServletRequestBindingException e) { log.info("Unable to get section name from request", e); } } else { // defaulting to all years year = (new GregorianCalendar()).get(GregorianCalendar.YEAR); issues = issueService.getIssuesPublished(year); issueMap.put(year, issues); // get all previous years do { year = year - 1; issues = issueService.getIssuesPublished(year); if (issues != null && issues.size() > 0) { issueMap.put(year, issues); } } while (issues != null && issues.size() > 0); } map.put("issueMap", issueMap); map.put("year", year); return new ModelAndView("no/dusken/aranea/base/web/pdf/view", map); }
From source file:com.tdclighthouse.prototype.utils.Configuration.java
public Date getTime(String key, Date defaultValue) { Date result = defaultValue;/*from w ww . ja va 2s .c om*/ String stringDate = properties.getProperty(key); try { if (StringUtils.isNotBlank(stringDate)) { Calendar calendar = new GregorianCalendar(); calendar.setTime(new SimpleDateFormat(TIME_FORMAT_STRING).parse(stringDate)); Calendar now = new GregorianCalendar(); calendar.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); if (calendar.before(now)) { calendar.add(Calendar.DAY_OF_MONTH, 1); } result = calendar.getTime(); } } catch (ParseException e) { LOG.error( "the given value \"{}\" of the key \"{}\" is not of the format \"{}\" so we default back to the default value", stringDate, key, TIME_FORMAT_STRING); } return result; }
From source file:de.laures.cewolf.taglib.ChartImageDefinition.java
/** * Constructor for ChartImage//from w ww . jav a2s. c o m */ public ChartImageDefinition(ChartHolder ch, int width, int height, int type, String mimeType, int timeout) { if (width <= 0) { throw new IllegalArgumentException("ChartImage with height or width <= 0 is illegal"); } this.chartHolder = ch; this.width = width; this.height = height; this.type = type; this.mimeType = mimeType; Calendar cal = new GregorianCalendar(); cal.add(Calendar.SECOND, timeout); this.timeoutTime = cal.getTime(); }
From source file:net.rrm.ehour.report.criteria.UserSelectedCriteria.java
public UserSelectedCriteria() { resetCustomerSelection();//www. java 2 s . c o m resetProjectSelection(); resetUserDepartmentSelection(); resetUserSelection(); infiniteStartDate = false; infiniteEndDate = false; reportRange = DateUtil.getDateRangeForMonth(new GregorianCalendar()); }
From source file:edu.umm.radonc.ca_dash.controllers.HistogramController.java
public HistogramController() { histogram = new BarChartModel(); percentile = 50.0;// w ww . j a v a 2s . c o m dstats = new SynchronizedDescriptiveStatistics(); endDate = new Date(); interval = ""; binInterval = -1; includeWeekends = false; GregorianCalendar gc = new GregorianCalendar(); ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); Map<String, Object> sessionMap = externalContext.getSessionMap(); if (sessionMap.containsKey("endDate")) { endDate = (Date) sessionMap.get("endDate"); } else { endDate = new Date(); sessionMap.put("endDate", endDate); } if (sessionMap.containsKey("startDate")) { startDate = (Date) sessionMap.get("startDate"); } else { gc.setTime(endDate); gc.add(Calendar.MONTH, -1); startDate = gc.getTime(); sessionMap.put("startDate", startDate); this.interval = "1m"; } selectedFilters = "all-tx"; selectedFacility = new Long(-1); patientsFlag = true; scheduledFlag = false; relativeModeFlag = false; }
From source file:com.jpeterson.littles3.bo.S3Authenticator.java
/** * Authenticate the request using the prescribed Amazon S3 authentication * mechanisms./* ww w.ja va2 s .c o m*/ * * @param req * The original HTTP request. * @param s3Request * The S3 specific information for authenticating the request. * @return The authenticated <code>CanonicalUser</code> making the request. * @throws RequestTimeTooSkewedException * Thrown if the request timestamp is outside of the allotted * timeframe. */ public CanonicalUser authenticate(HttpServletRequest req, S3ObjectRequest s3Request) throws AuthenticatorException { // check to see if anonymous request String authorization = req.getHeader(HEADER_AUTHORIZATION); if (authorization == null) { return new CanonicalUser(CanonicalUser.ID_ANONYMOUS); } // attempting to be authenticated request if (false) { // check timestamp of request Date timestamp = s3Request.getTimestamp(); if (timestamp == null) { throw new RequestTimeTooSkewedException("No timestamp provided"); } GregorianCalendar calendar = new GregorianCalendar(); Date now = calendar.getTime(); calendar.add(Calendar.MINUTE, 15); Date maximumDate = calendar.getTime(); calendar.add(Calendar.MINUTE, -30); Date minimumDate = calendar.getTime(); if (timestamp.before(minimumDate)) { throw new RequestTimeTooSkewedException( "Timestamp [" + timestamp + "] too old. System time: " + now); } if (timestamp.after(maximumDate)) { throw new RequestTimeTooSkewedException( "Timestamp [" + timestamp + "] too new. System time: " + now); } } // authenticate request String[] fields = authorization.split(" "); if (fields.length != 2) { throw new InvalidSecurityException("Unsupported authorization format"); } if (!fields[0].equals(AUTHORIZATION_TYPE)) { throw new InvalidSecurityException("Unsupported authorization type: " + fields[0]); } String[] keys = fields[1].split(":"); if (keys.length != 2) { throw new InvalidSecurityException("Invalid AWSAccesskeyId:Signature"); } String accessKeyId = keys[0]; String signature = keys[1]; String secretAccessKey = userDirectory.getAwsSecretAccessKey(accessKeyId); String calculatedSignature; try { SecretKey key = new SecretKeySpec(secretAccessKey.getBytes(), "HmacSHA1"); Mac m = Mac.getInstance("HmacSHA1"); m.init(key); m.update(s3Request.getStringToSign().getBytes()); byte[] mac = m.doFinal(); calculatedSignature = new String(Base64.encodeBase64(mac)); } catch (NoSuchAlgorithmException e) { throw new InvalidSecurityException(e); } catch (InvalidKeyException e) { throw new InvalidSecurityException(e); } System.out.println("-----------------"); System.out.println("signature: " + signature); System.out.println("calculatedSignature: " + calculatedSignature); System.out.println("-----------------"); if (calculatedSignature.equals(signature)) { // authenticated! return userDirectory.getCanonicalUser(secretAccessKey); } else { throw new SignatureDoesNotMatchException("Provided signature doesn't match calculated value"); } }
From source file:edu.utah.further.core.util.jaxb.JaxbConversionUtil.java
/** * @param s//from w ww . ja va2 s .com * @param dateFormat * @return */ public static XMLGregorianCalendar parseDateGregorian(final String s, final SimpleDateFormat dateFormat) { try { final Date date = dateFormat.parse(s); final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return DATATYPE_FACTORY.newXMLGregorianCalendar(calendar); } catch (final ParseException e) { throw new ApplicationException("Bad date field " + s, e); } }
From source file:org.openhie.openempi.util.DateConverterTest.java
public void testConvertStringToTimestamp() throws Exception { Date today = new Date(); Calendar todayCalendar = new GregorianCalendar(); todayCalendar.setTime(today);/*from w w w .ja v a2 s. c o m*/ String datePart = DateUtil.convertDateToString(today); Timestamp time = (Timestamp) converter.convert(Timestamp.class, datePart + " 01:02:03.4"); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(time.getTime()); assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR)); assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH)); assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH)); }