List of usage examples for org.joda.time DateTime getYear
public int getYear()
From source file:influent.server.rest.ChartResource.java
License:MIT License
@Post("json") public Map<String, ChartData> getChartData(String jsonData) { try {/* w w w.j a v a 2s. c o m*/ JSONProperties request = new JSONProperties(jsonData); final String focusContextId = request.getString("focuscontextid", null); final String sessionId = request.getString("sessionId", null); if (!GuidValidator.validateGuidString(sessionId)) { throw new ResourceException(Status.CLIENT_ERROR_EXPECTATION_FAILED, "sessionId is not a valid UUID"); } DateTime startDate = null; try { startDate = DateTimeParser.parse(request.getString("startDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "ChartResource: An illegal argument was passed into the 'startDate' parameter."); } DateTime endDate = null; try { endDate = DateTimeParser.parse(request.getString("endDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "ChartResource: An illegal argument was passed into the 'endDate' parameter."); } List<String> focusIds = new LinkedList<String>(); Iterable<String> focusIter = request.getStrings("focusId"); for (String entityId : focusIter) { List<String> entities = new ArrayList<String>(); InfluentId id = InfluentId.fromInfluentId(entityId); // Point account owners and summaries to their owner account if (id.getIdClass() == InfluentId.ACCOUNT_OWNER || id.getIdClass() == InfluentId.CLUSTER_SUMMARY) { entities.add(InfluentId.fromNativeId(InfluentId.ACCOUNT, id.getIdType(), id.getNativeId()) .toString()); } else if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { // group cluster for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entities.add(sId); } } } else { entities.add(entityId); } } else { entities.add(entityId); } for (String fid : entities) { if (!focusIds.contains(fid)) { focusIds.add(fid); } } } final Double focusMaxDebitCredit = request.getDouble("focusMaxDebitCredit", null); final Integer width = request.getInteger("width", 140); final Integer height = request.getInteger("height", 60); List<Properties> entityArray = Lists.newArrayList(request.getPropertiesSets("entities")); Map<String, ChartData> infoList = new HashMap<String, ChartData>(entityArray.size()); final Integer numBuckets = request.getInteger("numBuckets", 15); /// TODO : make this date range sanity check better if (startDate.getYear() < 1900 || startDate.getYear() > 9999) { MutableDateTime msdt = new MutableDateTime(startDate); msdt.setYear(2007); startDate = msdt.toDateTime(); logger.warn("Invalid start date passed from UI, setting to default"); } if (endDate.getYear() < 1900 || endDate.getYear() > 9999) { MutableDateTime medt = new MutableDateTime(endDate); medt.setYear(2013); endDate = medt.toDateTime(); logger.warn("Invalid end date passed from UI, setting to default"); } FL_DateRange dateRange = DateRangeBuilder.getDateRange(startDate, endDate); // compute an individual chart for each entity received for (Properties entityRequest : entityArray) { final String entityId = entityRequest.getString("dataId", null); final String entityContextId = entityRequest.getString("contextId", null); List<String> entityIds = new ArrayList<String>(); InfluentId id = InfluentId.fromInfluentId(entityId); if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entityIds.add(sId); } } } else { entityIds.add(entityId); } } else { entityIds.add(entityId); } ChartHash hash = new ChartHash(entityIds, startDate, endDate, focusIds, focusMaxDebitCredit, numBuckets, width, height, entityContextId, focusContextId, sessionId, contextCache); ChartData chartData = chartBuilder.computeChart(dateRange, entityIds, focusIds, entityContextId, focusContextId, sessionId, numBuckets, hash); infoList.put(entityId, //memberIds.get(0), chartData); } return infoList; } catch (AvroRemoteException e) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Data access error.", e); } catch (JSONException je) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "JSON parse error.", je); } }
From source file:influent.server.utilities.ConstrainedDateRange.java
License:MIT License
/** * Constructs a date range that is constrained to begin and end on instances of the specified * interval, and that is guaranteed to include the range specified. * /*from www .ja v a 2 s . c om*/ * @param start * @param interval * @param numBins */ public ConstrainedDateRange(DateTime start, FL_DateInterval interval, long numBins) { super(start.getMillis(), interval, numBins); DateTime constrained = start; // constrain to start of interval. switch (interval) { case SECONDS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), start.getHourOfDay(), start.getMinuteOfHour(), start.getSecondOfMinute(), DateTimeZone.UTC); break; case HOURS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), start.getHourOfDay(), 0, DateTimeZone.UTC); break; case DAYS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), 0, 0, DateTimeZone.UTC); break; case WEEKS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), 0, 0, DateTimeZone.UTC); final int days = start.getDayOfWeek() % 7; final long rewindMillis = days * DateTimeConstants.MILLIS_PER_DAY; constrained = new DateTime(constrained.getMillis() - rewindMillis, constrained.getZone()); break; case MONTHS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), 1, 0, 0, DateTimeZone.UTC); break; case QUARTERS: constrained = new DateTime(start.getYear(), 1 + 3 * ((start.getMonthOfYear() - 1) / 3), 1, 0, 0, DateTimeZone.UTC); break; case YEARS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), 1, 0, 0, DateTimeZone.UTC); break; } // add an extra partial interval at the end when not large enough. if (!start.equals(constrained)) { //System.out.println(start + " -> " + constrained); setStartDate(constrained.getMillis()); setNumBins(numBins + 1); } }
From source file:influent.server.utilities.DateTimeParser.java
License:MIT License
/** * @see http://joda-time.sourceforge.net/apidocs/org/joda/time/DateTime.html#parse(java.lang.String) *///w w w . j a va 2 s. c om public static DateTime parse(String str) { if (str == null || str.isEmpty()) return null; // if we can, just pick out the date because we need to ignore any time zone information. if (str.length() >= 10) { try { int yyyy = Integer.parseInt(str.substring(0, 4)); int mm = Integer.parseInt(str.substring(5, 7)); int dd = Integer.parseInt(str.substring(8, 10)); // extra sanity check switch (str.charAt(4)) { case '-': case '/': return new DateTime(yyyy, mm, dd, 0, 0, 0, DateTimeZone.UTC); } } catch (Exception e) { } } final DateTime d = ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(str); return new DateTime(d.getYear(), d.getMonthOfYear(), d.getDayOfMonth(), 0, 0, 0, DateTimeZone.UTC); }
From source file:io.coala.xml.XmlUtil.java
License:Apache License
/** * @param date/*from w ww .j a va2s. c o m*/ * @return a JAXP {@link XMLGregorianCalendar} */ public static XMLGregorianCalendar toDateTime(final DateTime date) { final XMLGregorianCalendar result = getDatatypeFactory().newXMLGregorianCalendar(); result.setYear(date.getYear()); result.setMonth(date.getMonthOfYear()); result.setDay(date.getDayOfMonth()); result.setTime(date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(), date.getMillisOfSecond()); result.setTimezone(date.getZone().toTimeZone().getRawOffset() / 1000 / 60); // result.setTimezone(DatatypeConstants.FIELD_UNDEFINED); return result; }
From source file:io.warp10.script.functions.TSELEMENTS.java
License:Apache License
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object obj = stack.peek();//from w ww . j ava 2 s.c o m String tz = null; if (obj instanceof String) { tz = (String) obj; stack.pop(); } else if (!(obj instanceof Long)) { throw new WarpScriptException(getName() + " operates on a timestamp or a timestamp + timezone."); } DateTimeZone dtz = this.tzones.get(tz); if (null == dtz) { dtz = DateTimeZone.forID(null == tz ? "UTC" : tz); this.tzones.put(tz, dtz); } obj = stack.pop(); if (!(obj instanceof Long)) { throw new WarpScriptException(getName() + " operates on a timestamp or a timestamp + timezone."); } long ts = (long) obj; // Convert ts to milliseconds long tsms = ts / Constants.TIME_UNITS_PER_MS; DateTime dt = new DateTime(tsms, dtz); // Extract components into an array List<Long> elements = new ArrayList<Long>(); elements.add((long) dt.getYear()); elements.add((long) dt.getMonthOfYear()); elements.add((long) dt.getDayOfMonth()); elements.add((long) dt.getHourOfDay()); elements.add((long) dt.getMinuteOfHour()); elements.add((long) dt.getSecondOfMinute()); elements.add(ts % Constants.TIME_UNITS_PER_S); elements.add((long) dt.getDayOfYear()); elements.add((long) dt.getDayOfWeek()); elements.add((long) dt.getWeekOfWeekyear()); stack.push(elements); return stack; }
From source file:io.warp10.script.HyperLogLogPlus.java
License:Apache License
public void setInitTime(long instant) { this.initTime = instant; ///*from w ww. j av a2 s . c om*/ // Compute expiry time, we compute the timestamp of the first day of the month following the current one // DateTime dt = new DateTime(this.initTime, DateTimeZone.UTC); this.expiry = new DateTime(dt.getYear(), dt.getMonthOfYear(), 1, 0, 0, DateTimeZone.UTC).plusMonths(1) .getMillis(); }
From source file:io.warp10.script.mapper.MapperYear.java
License:Apache License
@Override public Object apply(Object[] args) throws WarpScriptException { long tick = (long) args[0]; long[] locations = (long[]) args[4]; long[] elevations = (long[]) args[5]; long location = locations[0]; long elevation = elevations[0]; DateTime dt = new DateTime(tick / Constants.TIME_UNITS_PER_MS, this.dtz); return new Object[] { tick, location, elevation, dt.getYear() }; }
From source file:isjexecact.br.com.inso.utils.Funcoes.java
/** * Retorna o ano de uma data.//from w w w.ja va 2 s .co m * @param data Data a ser processada. * @return Ano da data. */ public static int getYear(Date data) { if (data == null) { return 0; } // Glauber 11/09/2014 - Estou trocando pelo componente joda-time para me livrar da dor de cabea de utiilzar as classes nativa do Java. DateTime dateTime = new DateTime(data); return dateTime.getYear(); // Calendar calendario = new GregorianCalendar(); // calendario.setTime(data); // return calendario.get(Calendar.YEAR) ; }
From source file:it.fabaris.wfp.widget.DateTimeWidget.java
License:Open Source License
/** * set the answer to the answer Widget//from w ww . j a v a 2 s . com * getting in it from the FormEntryPrompt * otherwise create time widget with * the current time */ private void setAnswer() { if (mPrompt.getAnswerValue() != null) { DateTime ldt = new DateTime(((Date) ((DateTimeData) mPrompt.getAnswerValue()).getValue()).getTime()); //mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); //LA DATA DI SINCRONIZZAZIONE ERA SETTATA CON UN MESE INDIETRO mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth(), mDateListener); mTimePicker.setCurrentHour(ldt.getHourOfDay()); mTimePicker.setCurrentMinute(ldt.getMinuteOfHour()); } else { // create time widget with current time as of right now clearAnswer(); } }
From source file:it.fabaris.wfp.widget.DateWidget.java
License:Open Source License
/** * if there is an answer in the FormEntryPrompt * put it in the answer Widget, clean/*from w ww .j a va2 s .c o m*/ * the widget value otherwise */ private void setAnswer() { if (mPrompt.getAnswerValue() != null) { DateTime ldt = new DateTime(((Date) ((DateData) mPrompt.getAnswerValue()).getValue()).getTime()); mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); //mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); } else { // create date widget with current time as of right now clearAnswer(); } }