List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. 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 ava 2 s . 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: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 w w . j av a2 s .c o m*/ 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:de.micromata.genome.util.types.DateUtils.java
/** * Ensure workday./*from www. ja v a 2s. c o m*/ * * @param cal the cal */ protected static void ensureWorkday(Calendar cal) { int dow = cal.get(Calendar.DAY_OF_WEEK); while (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) { cal.add(Calendar.DAY_OF_YEAR, 1); dow = cal.get(Calendar.DAY_OF_WEEK); } }
From source file:osh.busdriver.MieleGatewayBusDriver.java
static private StartTimeDetails createStartTimeDetails(final UUID devUUID, long timestamp, MieleDeviceHomeBusData dev) {/* w w w.j a va 2 s. co m*/ StartTimeDetails startDetails = new StartTimeDetails(devUUID, timestamp); startDetails.setStartTime(-1); if (dev.getDeviceDetails() != null) { MieleDuration mieleStartTime = dev.getDeviceDetails().getStartTime(); if (mieleStartTime != null) { int starttime = mieleStartTime.duration(); if (starttime >= 0) { Calendar calNow = Calendar.getInstance(); Calendar calStartTime = (Calendar) calNow.clone(); calStartTime.set(Calendar.MINUTE, starttime % 60); calStartTime.set(Calendar.HOUR_OF_DAY, starttime / 60); if (calStartTime.before(calNow)) { calStartTime.add(Calendar.DAY_OF_YEAR, 1); } startDetails.setStartTime(calStartTime.getTimeInMillis() / 1000L); } } } return startDetails; }
From source file:com.hangum.tadpole.manager.core.dialogs.users.FindUserAndDBRoleDialog.java
/** * initialize UI */ private void initUI() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, 365 * 10); }
From source file:org.openmrs.logic.db.hibernate.HibernateLogicEncounterDAO.java
/** * Convenience method to get the list of hibernate queries for this expression * //from ww w .j a va 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:nz.co.senanque.rules.OperationsImpl.java
@InternalFunction() public Date addDays(Date date, Number days) { if (date == null || days == null) { return null; }/*from w ww. jav a 2 s .c o m*/ Calendar calendar = getCalendar(date); calendar.add(Calendar.DAY_OF_YEAR, days.intValue()); Date ret = calendar.getTime(); return ret; }
From source file:com.algomedica.service.LicenseManagerServiceImpl.java
/** * @param oldExpiryDate//ww w .j ava2 s .c om * @param lsExipryDays * @return * @throws ParseException */ private Date calculateExpiryDate(Date oldExpiryDate, long lsExipryDays) throws ParseException { Calendar c = Calendar.getInstance(); // starts with today's date and c.setTime(oldExpiryDate); c.add(Calendar.DAY_OF_YEAR, Integer.valueOf(String.valueOf(lsExipryDays))); DateFormat outputFormatter = new SimpleDateFormat("MM/dd/yyyy"); Date date = c.getTime(); date = outputFormatter.parse(outputFormatter.format(date.getTime())); return date; }
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 ww . ja va 2 s . c o m return result; }
From source file:nz.co.senanque.rules.OperationsImpl.java
@InternalFunction() public Date subtractDays(Date date, Number days) { if (date == null || days == null) { return null; }//from w w w .j a v a2 s .c o m Calendar calendar = getCalendar(date); calendar.add(Calendar.DAY_OF_YEAR, days.intValue() * -1); Date ret = calendar.getTime(); return ret; }