List of usage examples for java.util Calendar WEEK_OF_YEAR
int WEEK_OF_YEAR
To view the source code for java.util Calendar WEEK_OF_YEAR.
Click Source Link
get
and set
indicating the week number within the current year. From source file:org.jfree.data.time.Week.java
/** * Returns the week preceding this one. This method will return * <code>null</code> for some lower limit on the range of weeks (currently * week 1, 1900). For week 1 of any year, the previous week is always week * 53, but week 53 may not contain any days (you should check for this). * * @return The preceding week (possibly <code>null</code>). *///from ww w .j a v a 2s .co m @Override public RegularTimePeriod previous() { Week result; if (this.week != FIRST_WEEK_IN_YEAR) { result = new Week(this.week - 1, this.year); } else { // we need to work out if the previous year has 52 or 53 weeks... if (this.year > 1900) { int yy = this.year - 1; Calendar prevYearCalendar = Calendar.getInstance(); prevYearCalendar.set(yy, Calendar.DECEMBER, 31); result = new Week(prevYearCalendar.getActualMaximum(Calendar.WEEK_OF_YEAR), yy); } else { result = null; } } return result; }
From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java
private LineData getData() { ArrayList<ILineDataSet> dataSets = new ArrayList<>(); final SparseArray<Pair<Date, Double>> sparseArray = JobCheckpointsContract.getHourlyReport(mDataType); if (mDataType == DataType.WEEK) { final SparseArray<SparseArray<Double>> weeksDays = groupValues(sparseArray, 0, Calendar.DAY_OF_WEEK); if (weeksDays.size() > 0) { final Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); final int startValue = calendar.get(Calendar.DAY_OF_WEEK); dataSets.add(getData(0, "", weeksDays.get(weeksDays.keyAt(0)), startValue)); }//from www. ja va2 s . co m } else if (mDataType == DataType.MONTH) { final SparseArray<SparseArray<Double>> weeksInMonth = groupValues(sparseArray, Calendar.WEEK_OF_YEAR, Calendar.DAY_OF_WEEK); for (int i = 0; i < weeksInMonth.size(); i++) { final String label = getString(R.string.chart_week_label, i + 1); dataSets.add(getData(i, label, weeksInMonth.get(weeksInMonth.keyAt(i)), 0)); } } else if (mDataType == DataType.ALL_TIME) { final SparseArray<SparseArray<Double>> years = groupValues(sparseArray, Calendar.YEAR, Calendar.YEAR); if (years.size() > 0) { dataSets.add(getData(0, "", years.get(years.keyAt(0)), 0)); } } return new LineData(dataSets); }
From source file:org.rapidandroid.activity.chart.ChartBroker.java
protected Date getNextValue(DateDisplayTypes displayType, Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);// w ww . ja v a2s .c om switch (displayType) { case Hourly: cal.add(Calendar.HOUR, 1); break; case Daily: cal.add(Calendar.DATE, 1); break; case Weekly: cal.add(Calendar.WEEK_OF_YEAR, 1); break; case Monthly: cal.add(Calendar.MONTH, 1); break; case Yearly: cal.add(Calendar.YEAR, 1); break; default: throw new IllegalArgumentException("Bad display type: " + displayType); } return cal.getTime(); }
From source file:org.openmrs.logic.db.hibernate.HibernateLogicObsDAO.java
public Criterion getCriterion(LogicExpression logicExpression, Date indexDate, Criteria criteria) { Operator operator = logicExpression.getOperator(); Operand rightOperand = logicExpression.getRightOperand(); Operand leftOperand = null;/*from w ww. j av a 2 s . c om*/ if (logicExpression instanceof LogicExpressionBinary) { leftOperand = ((LogicExpressionBinary) logicExpression).getLeftOperand(); } List<Criterion> criterion = new ArrayList<Criterion>(); //the root token can be a concept name for the obs datasource String rootToken = logicExpression.getRootToken(); Concept concept = getConceptForToken(rootToken); if (concept != null) { criterion.add(Restrictions.eq("concept", concept)); } else { if (rootToken != null && (rootToken.equalsIgnoreCase(COMPONENT_ENCOUNTER_ID) || rootToken.equalsIgnoreCase(COMPONENT_OBS_DATETIME))) { //this is a component not a concept so it is fine } else { throw new LogicException("Concept: " + rootToken + " does not exist"); } } if (operator == Operator.BEFORE) { criterion.add(Restrictions.lt("obsDatetime", rightOperand)); } else if (operator == Operator.AFTER) { criterion.add(Restrictions.gt("obsDatetime", rightOperand)); } else if (operator == Operator.AND || operator == Operator.OR) { Criterion leftCriteria = null; Criterion rightCriteria = null; if (leftOperand instanceof LogicExpression) { leftCriteria = this.getCriterion((LogicExpression) leftOperand, indexDate, criteria); } if (rightOperand instanceof LogicExpression) { rightCriteria = this.getCriterion((LogicExpression) rightOperand, indexDate, criteria); } if (leftCriteria != null && rightCriteria != null) { if (operator == Operator.AND) { criterion.add(Restrictions.and(leftCriteria, rightCriteria)); } if (operator == Operator.OR) { criterion.add(Restrictions.or(leftCriteria, rightCriteria)); } } } else if (operator == Operator.NOT) { Criterion rightCriteria = null; if (rightOperand instanceof LogicExpression) { rightCriteria = this.getCriterion((LogicExpression) rightOperand, indexDate, criteria); } if (rightCriteria != null) { criterion.add(Restrictions.not(rightCriteria)); } } else if (operator == Operator.CONTAINS) { // used with PROBLEM ADDED concept, to retrieve the "ANSWERED // BY" concept, stashed inside the concept's valueCoded member // variable. for example: // new LogicCriteria("PROBLEM ADDED").contains("HIV INFECTED"); if (rightOperand instanceof OperandNumeric) { concept = Context.getConceptService().getConcept(((OperandNumeric) rightOperand).asInteger()); criterion.add(Restrictions.eq("valueCoded", concept)); } else if (rightOperand instanceof OperandText) { concept = Context.getConceptService().getConcept((String) ((OperandText) rightOperand).asString()); criterion.add(Restrictions.eq("valueCoded", concept)); } else if (rightOperand instanceof OperandConcept) { criterion.add(Restrictions.eq("valueCoded", ((OperandConcept) rightOperand).asConcept())); } else log.error("Invalid operand value for CONTAINS operation"); } else if (operator == Operator.IN) { log.error("Invalid operand value for IN operation"); } else if (operator == Operator.EQUALS) { if (rightOperand instanceof OperandNumeric) { if (rootToken.equalsIgnoreCase(COMPONENT_ENCOUNTER_ID)) { EncounterService encounterService = Context.getEncounterService(); Encounter encounter = encounterService .getEncounter(((OperandNumeric) rightOperand).asInteger()); criterion.add(Restrictions.eq("encounter", encounter)); } else criterion.add(Restrictions.eq("valueNumeric", ((OperandNumeric) rightOperand).asDouble())); } else if (rightOperand instanceof OperandText) criterion.add(Restrictions.eq("valueText", ((OperandText) rightOperand).asString())); else if (rightOperand instanceof OperandDate) if (leftOperand instanceof OperandText && ((OperandText) leftOperand).asString().equals(COMPONENT_OBS_DATETIME)) { criterion.add(Restrictions.eq(COMPONENT_OBS_DATETIME, rightOperand)); } else { criterion.add(Restrictions.eq("valueDatetime", rightOperand)); } else if (rightOperand instanceof OperandConcept) criterion.add(Restrictions.eq("valueCoded", ((OperandConcept) rightOperand).asConcept())); else log.error("Invalid operand value for EQUALS operation"); } else if (operator == Operator.LTE) { if (rightOperand instanceof OperandNumeric) criterion.add(Restrictions.le("valueNumeric", ((OperandNumeric) rightOperand).asDouble())); else if (rightOperand instanceof OperandDate) if (leftOperand instanceof OperandText && ((OperandText) leftOperand).asString().equals(COMPONENT_OBS_DATETIME)) { criterion.add(Restrictions.le(COMPONENT_OBS_DATETIME, rightOperand)); } else { criterion.add(Restrictions.le("valueDatetime", rightOperand)); } else log.error("Invalid operand value for LESS THAN EQUAL operation"); } else if (operator == Operator.GTE) { if (rightOperand instanceof OperandNumeric) criterion.add(Restrictions.ge("valueNumeric", ((OperandNumeric) rightOperand).asDouble())); else if (rightOperand instanceof OperandDate) if (leftOperand instanceof OperandText && ((OperandText) leftOperand).asString().equals(COMPONENT_OBS_DATETIME)) { criterion.add(Restrictions.ge(COMPONENT_OBS_DATETIME, rightOperand)); } else { criterion.add(Restrictions.ge("valueDatetime", rightOperand)); } else log.error("Invalid operand value for GREATER THAN EQUAL operation"); } else if (operator == Operator.LT) { if (rightOperand instanceof OperandNumeric) criterion.add(Restrictions.lt("valueNumeric", ((OperandNumeric) rightOperand).asDouble())); else if (rightOperand instanceof OperandDate) if (leftOperand instanceof OperandText && ((OperandText) leftOperand).asString().equals(COMPONENT_OBS_DATETIME)) { criterion.add(Restrictions.lt(COMPONENT_OBS_DATETIME, rightOperand)); } else { criterion.add(Restrictions.lt("valueDatetime", rightOperand)); } else log.error("Invalid operand value for LESS THAN operation"); } else if (operator == Operator.GT) { if (rightOperand instanceof OperandNumeric) criterion.add(Restrictions.gt("valueNumeric", ((OperandNumeric) rightOperand).asDouble())); else if (rightOperand instanceof OperandDate) if (leftOperand instanceof OperandText && ((OperandText) leftOperand).asString().equals(COMPONENT_OBS_DATETIME)) { criterion.add(Restrictions.gt(COMPONENT_OBS_DATETIME, rightOperand)); } else { criterion.add(Restrictions.gt("valueDatetime", rightOperand)); } else log.error("Invalid operand value for GREATER THAN operation"); } else if (operator == Operator.EXISTS) { // EXISTS can be handled on the higher level (above // LogicService, even) by coercing the Result into a Boolean for // each patient } else if (operator == Operator.ASOF && rightOperand instanceof OperandDate) { indexDate = (Date) rightOperand; criterion.add(Restrictions.le("obsDatetime", indexDate)); } else if (operator == Operator.WITHIN && rightOperand instanceof Duration) { Duration duration = (Duration) rightOperand; Calendar within = Calendar.getInstance(); within.setTime(indexDate); if (duration.getUnits() == Duration.Units.YEARS) { within.add(Calendar.YEAR, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.MONTHS) { within.add(Calendar.MONTH, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.WEEKS) { within.add(Calendar.WEEK_OF_YEAR, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.DAYS) { within.add(Calendar.DAY_OF_YEAR, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.HOURS) { within.add(Calendar.HOUR_OF_DAY, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.MINUTES) { within.add(Calendar.MINUTE, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.SECONDS) { within.add(Calendar.SECOND, duration.getDuration().intValue()); } if (indexDate.compareTo(within.getTime()) > 0) { criterion.add(Restrictions.between("obsDatetime", within.getTime(), indexDate)); } else { criterion.add(Restrictions.between("obsDatetime", indexDate, within.getTime())); } } Criterion c = null; for (Criterion crit : criterion) { if (c == null) { c = crit; } else { c = Restrictions.and(c, crit); } } return c; }
From source file:TimeSpan.java
/** * Returns {@code true} if the end date occurs after the start date during * the period of time represented by this time span. * //from w w w .j a v a 2s.c o m * @param mutableStartDate a <i>mutable<i> {@code Calendar} object that will * be changed to the ending time of this time range as a side effect * of this method */ private boolean isInRange(Calendar mutableStartDate, Calendar endDate) { // ensure that the ending date does not occur before the time span would // have started if (endDate.before(mutableStartDate)) return false; // update the start date to be the date at the end of the time span Calendar tsEnd = mutableStartDate; tsEnd.add(Calendar.YEAR, years); tsEnd.add(Calendar.MONTH, months); tsEnd.add(Calendar.WEEK_OF_YEAR, weeks); tsEnd.add(Calendar.DAY_OF_YEAR, days); tsEnd.add(Calendar.HOUR, hours); return endDate.before(tsEnd); }
From source file:me.crime.database.Crime.java
/** * * @return */ public Vertex toTemporalPoint() { return new Vertex(getTime(), getStartDate().get(Calendar.WEEK_OF_YEAR)); }
From source file:org.openmrs.logic.db.hibernate.HibernateLogicEncounterDAO.java
/** * Convenience method to get the list of hibernate queries for this expression * //from w w w. j av a 2 s .c o m * @param logicExpression * @param indexDate * @param criteria Criteria object so that certain expressions can add aliases, etc * @return Criterion to be added to the Criteria */ public Criterion getCriterion(LogicExpression logicExpression, Date indexDate, Criteria criteria) { Operator operator = logicExpression.getOperator(); Object rightOperand = logicExpression.getRightOperand(); Object leftOperand = null; if (logicExpression instanceof LogicExpressionBinary) { leftOperand = ((LogicExpressionBinary) logicExpression).getLeftOperand(); } List<Criterion> criterion = new ArrayList<Criterion>(); //if the leftOperand is a String and does not match any components, //see if it is a concept name and restrict accordingly //a null operator implies a concept restriction if (leftOperand instanceof LogicExpression) { // no restrictions if there is no operator // TODO restrict on provider != null for encounterProvider token? } String token = logicExpression.getRootToken(); if (operator == null) { // no restrictions if there is no operator // TODO restrict on provider != null for encounterProvider token? } else if (operator == Operator.BEFORE || operator == Operator.LT) { if (ENCOUNTER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandDate) { criterion.add(Restrictions.lt("encounterDatetime", rightOperand)); } else { throw new LogicException("'before' is not a valid operator on " + token + " and " + rightOperand); } } else if (operator == Operator.AFTER || operator == Operator.GT) { if (ENCOUNTER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandDate) { criterion.add(Restrictions.gt("encounterDatetime", rightOperand)); } else { throw new LogicException("'after' is not a valid operator on " + token + " and " + rightOperand); } } else if (operator == Operator.AND || operator == Operator.OR) { if (ENCOUNTER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandDate) { Criterion leftCriteria = null; Criterion rightCriteria = null; if (leftOperand instanceof LogicExpression) { leftCriteria = this.getCriterion((LogicExpression) leftOperand, indexDate, criteria); } if (rightOperand instanceof LogicExpression) { rightCriteria = this.getCriterion((LogicExpression) rightOperand, indexDate, criteria); } if (leftCriteria != null && rightCriteria != null) { if (operator == Operator.AND) { criterion.add(Restrictions.and(leftCriteria, rightCriteria)); } if (operator == Operator.OR) { criterion.add(Restrictions.or(leftCriteria, rightCriteria)); } } } else { throw new LogicException("'and/or' are not valid operators on " + token + " and " + rightOperand); } } else if (operator == Operator.NOT) { Criterion rightCriteria = null; if (rightOperand instanceof LogicExpression) { rightCriteria = this.getCriterion((LogicExpression) rightOperand, indexDate, criteria); } if (rightCriteria != null) { criterion.add(Restrictions.not(rightCriteria)); } } else if (operator == Operator.CONTAINS) { if (ENCOUNTER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandText) { criteria.createAlias("encounterType", "encounterType"); criterion.add(Expression.eq("encounterType.name", ((OperandText) rightOperand).asString())); } else if (LOCATION_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandText) { criteria.createAlias("location", "location"); criterion.add(Restrictions.eq("location.name", ((OperandText) rightOperand).asString())); } else if (PROVIDER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandNumeric) { criteria.createAlias("provider", "provider"); criterion.add(Restrictions.eq("provider.personId", ((OperandNumeric) rightOperand).asInteger())); } else { throw new LogicException("'contains' is not a valid operator on " + token + " and " + rightOperand); } } else if (operator == Operator.IN) { if (ENCOUNTER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandCollection) { criteria.createAlias("encounterType", "encounterType"); criterion.add( Expression.in("encounterType.name", ((OperandCollection) rightOperand).asCollection())); } else if (LOCATION_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandCollection) { criteria.createAlias("location", "location"); criterion.add(Restrictions.in("location.name", ((OperandCollection) rightOperand).asCollection())); } else if (PROVIDER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandCollection) { criteria.createAlias("provider", "provider"); criterion.add( Restrictions.in("provider.systemId", ((OperandCollection) rightOperand).asCollection())); } else { throw new LogicException("'in' is not a valid operator on " + token + " and " + rightOperand); } } else if (operator == Operator.EQUALS) { if (ENCOUNTER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandDate) { criterion.add(Restrictions.eq("encounterDatetime", rightOperand)); } else if (ENCOUNTER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandText) { criteria.createAlias("encounterType", "encounterType"); criterion.add(Restrictions.eq("encounterType.name", ((OperandText) rightOperand).asString())); } else if (LOCATION_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandText) { criteria.createAlias("location", "location"); criterion.add(Restrictions.eq("location.name", ((OperandText) rightOperand).asString())); } else if (PROVIDER_KEY.equalsIgnoreCase(token) && rightOperand instanceof OperandText) { criteria.createAlias("provider", "provider"); criterion.add(Restrictions.eq("provider.systemId", ((OperandText) rightOperand).asString())); } else { throw new LogicException("'equals' is not a valid operator on " + token + " and " + rightOperand); } } else if (operator == Operator.LTE) { if (rightOperand instanceof OperandDate) criterion.add(Restrictions.le("encounterDatetime", rightOperand)); else throw new LogicException( "'less than or equals' is not a valid operator on " + token + " and " + rightOperand); } else if (operator == Operator.GTE) { if (rightOperand instanceof OperandDate) criterion.add(Restrictions.ge("encounterDatetime", rightOperand)); else throw new LogicException( "'greater than or equals' is not a valid operator on " + token + " and " + rightOperand); } else if (operator == Operator.LT) { if (rightOperand instanceof OperandDate) criterion.add(Restrictions.lt("encounterDatetime", rightOperand)); else throw new LogicException( "'less than' is not a valid operator on " + token + " and " + rightOperand); } else if (operator == Operator.GT) { if (rightOperand instanceof OperandDate) criterion.add(Restrictions.gt("encounterDatetime", rightOperand)); else throw new LogicException( "'greater than' is not a valid operator on " + token + " and " + rightOperand); } else if (operator == Operator.EXISTS) { // EXISTS can be handled on the higher level (above // LogicService, even) by coercing the Result into a Boolean for // each patient } else if (operator == Operator.ASOF && rightOperand instanceof Date) { indexDate = (Date) rightOperand; criterion.add(Restrictions.le("encounterDatetime", indexDate)); } else if (operator == Operator.WITHIN) { if (rightOperand instanceof Duration) { Duration duration = (Duration) rightOperand; Calendar within = Calendar.getInstance(); within.setTime(indexDate); if (duration.getUnits() == Duration.Units.YEARS) { within.add(Calendar.YEAR, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.MONTHS) { within.add(Calendar.MONTH, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.WEEKS) { within.add(Calendar.WEEK_OF_YEAR, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.DAYS) { within.add(Calendar.DAY_OF_YEAR, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.HOURS) { within.add(Calendar.HOUR_OF_DAY, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.MINUTES) { within.add(Calendar.MINUTE, duration.getDuration().intValue()); } else if (duration.getUnits() == Duration.Units.SECONDS) { within.add(Calendar.SECOND, duration.getDuration().intValue()); } if (indexDate.compareTo(within.getTime()) > 0) { criterion.add(Restrictions.between("encounterDatetime", within.getTime(), indexDate)); } else { criterion.add(Restrictions.between("encounterDatetime", indexDate, within.getTime())); } } else { throw new LogicException("'within' is not a valid operator on " + token + " and " + rightOperand); } } Criterion c = null; for (Criterion crit : criterion) { if (c == null) { c = crit; } else { c = Restrictions.and(c, crit); } } return c; }
From source file:org.jfree.data.time.Week.java
/** * Returns the week following this one. This method will return * <code>null</code> for some upper limit on the range of weeks (currently * week 53, 9999). For week 52 of any year, the following week is always * week 53, but week 53 may not contain any days (you should check for * this)./*w w w . j a v a 2s .c o m*/ * * @return The following week (possibly <code>null</code>). */ @Override public RegularTimePeriod next() { Week result; if (this.week < 52) { result = new Week(this.week + 1, this.year); } else { Calendar calendar = Calendar.getInstance(); calendar.set(this.year, Calendar.DECEMBER, 31); int actualMaxWeek = calendar.getActualMaximum(Calendar.WEEK_OF_YEAR); if (this.week < actualMaxWeek) { result = new Week(this.week + 1, this.year); } else { if (this.year < 9999) { result = new Week(FIRST_WEEK_IN_YEAR, this.year + 1); } else { result = null; } } } return result; }
From source file:com.redhat.rhn.frontend.action.monitoring.notification.BaseFilterEditAction.java
private List makeDurationTypes() { ArrayList result = new ArrayList(); result.add(lv("filter-form.jspf.minutes", new Long(Calendar.MINUTE).toString())); result.add(lv("filter-form.jspf.hours", new Long(Calendar.HOUR_OF_DAY).toString())); result.add(lv("filter-form.jspf.days", new Long(Calendar.DAY_OF_YEAR).toString())); result.add(lv("filter-form.jspf.weeks", new Long(Calendar.WEEK_OF_YEAR).toString())); result.add(lv("filter-form.jspf.years", new Long(Calendar.YEAR).toString())); localize(result);// w w w . java2 s . c o m return result; }
From source file:org.apache.lens.cube.parse.DateUtil.java
public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) { int dayDiff = 0; Date tmpFrom = from;//from ww w.j a v a2 s . c o m while (tmpFrom.before(to)) { tmpFrom = DateUtils.addDays(tmpFrom, 1); dayDiff++; } if (dayDiff < 7) { return new CoveringInfo(0, false); } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromWeek = cal.get(Calendar.WEEK_OF_YEAR); int fromDay = cal.get(Calendar.DAY_OF_WEEK); int fromYear = cal.get(YEAR); cal.clear(); cal.set(YEAR, fromYear); cal.set(Calendar.WEEK_OF_YEAR, fromWeek); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); int maxDayInWeek = cal.getActualMaximum(Calendar.DAY_OF_WEEK); Date fromWeekStartDate = cal.getTime(); boolean coverable = dayDiff % 7 == 0; if (fromWeekStartDate.before(from)) { // Count from the start of next week dayDiff -= (maxDayInWeek - (fromDay - Calendar.SUNDAY)); coverable = false; } return new CoveringInfo(dayDiff / 7, coverable); }