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.springmodules.validation.util.date.DefaultDateParser.java
public DefaultDateParser() { super();// w ww .j a v a 2s.c o m register("^\\d{8}$", "yyyyMMdd"); register("^\\d{4}\\-\\d{2}\\-\\d{2}$", "yyyy-MM-dd"); register("^\\d{4}\\-\\d{2}\\-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}$", "yyyy-MM-dd HH:mm:ss"); register("^\\d{8}\\s+\\d{6}$", "yyyyMMdd HHmmss"); register("^\\d{8}\\s+\\d{2}:\\d{2}:\\d{2}$", "yyyyMMdd HH:mm:ss"); register("^\\d{4}\\-\\d{2}\\-\\d{2}\\s+\\d{6}$", "yyyy-MM-dd HHmmss"); register("^T$", new DateModifier() { public void modify(Calendar calendar, String value) { } }); register("^T\\+(\\d+)S$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MILLISECOND, Integer.parseInt(value)); } }); register("^T\\-(\\d+)S$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MILLISECOND, Integer.parseInt(value) * -1); } }); register("^T>s$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.SECOND, 1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) + 1 * -1); } }); register("^T<s$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); } }); register("^T\\+(\\d+)s$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.SECOND, Integer.parseInt(value)); } }); register("^T\\-(\\d+)s$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.SECOND, Integer.parseInt(value) * -1); } }); register("^T>m$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MINUTE, 1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) + 1 * -1); } }); register("^T<m$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); } }); register("^T\\+(\\d+)m$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MINUTE, Integer.parseInt(value)); } }); register("^T\\-(\\d+)m$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MINUTE, Integer.parseInt(value) * -1); } }); register("^T>H$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.HOUR_OF_DAY, 1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) + 1 * -1); } }); register("^T<H$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); } }); register("^T\\+(\\d+)H$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.HOUR_OF_DAY, Integer.parseInt(value)); } }); register("^T\\-(\\d+)H$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.HOUR_OF_DAY, Integer.parseInt(value) * -1); } }); register("^T>d$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.DAY_OF_YEAR, 1); calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) + 1 * -1); } }); register("^T<d$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); } }); register("^T\\+(\\d+)d$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(value)); } }); register("^T\\-(\\d+)d$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(value) * -1); } }); register("^T>w$", new DateModifier() { public void modify(Calendar calendar, String value) { int thisWeek = calendar.get(Calendar.WEEK_OF_YEAR); calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); while (thisWeek == calendar.get(Calendar.WEEK_OF_YEAR)) { calendar.add(Calendar.DAY_OF_YEAR, 1); } calendar.add(Calendar.MILLISECOND, -1); } }); register("^T<w$", new DateModifier() { public void modify(Calendar calendar, String value) { int thisWeek = calendar.get(Calendar.WEEK_OF_YEAR); calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); while (thisWeek == calendar.get(Calendar.WEEK_OF_YEAR)) { calendar.add(Calendar.DAY_OF_YEAR, -1); } calendar.add(Calendar.DAY_OF_YEAR, 1); } }); register("^T\\+(\\d+)w$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.WEEK_OF_YEAR, Integer.parseInt(value)); } }); register("^T\\-(\\d+)w$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.WEEK_OF_YEAR, Integer.parseInt(value) * -1); } }); register("^T>M$", new DateModifier() { public void modify(Calendar calendar, String value) { int thisMonth = calendar.get(Calendar.MONTH); calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); while (thisMonth == calendar.get(Calendar.MONTH)) { calendar.add(Calendar.DAY_OF_YEAR, 1); } calendar.add(Calendar.MILLISECOND, -1); } }); register("^T<M$", new DateModifier() { public void modify(Calendar calendar, String value) { int thisMonth = calendar.get(Calendar.MONTH); calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); while (thisMonth == calendar.get(Calendar.MONTH)) { calendar.add(Calendar.DAY_OF_YEAR, -1); } calendar.add(Calendar.DAY_OF_YEAR, 1); } }); register("^T\\+(\\d+)M$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MONTH, Integer.parseInt(value)); } }); register("^T\\-(\\d+)M$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.MONTH, Integer.parseInt(value) * -1); } }); register("^T>y$", new DateModifier() { public void modify(Calendar calendar, String value) { int thisYear = calendar.get(Calendar.YEAR); calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); while (thisYear == calendar.get(Calendar.YEAR)) { calendar.add(Calendar.DAY_OF_YEAR, 1); } calendar.add(Calendar.MILLISECOND, -1); } }); register("^T<y$", new DateModifier() { public void modify(Calendar calendar, String value) { int thisYear = calendar.get(Calendar.YEAR); calendar.add(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) * -1); calendar.add(Calendar.MINUTE, calendar.get(Calendar.MINUTE) * -1); calendar.add(Calendar.SECOND, calendar.get(Calendar.SECOND) * -1); calendar.add(Calendar.MILLISECOND, calendar.get(Calendar.MILLISECOND) * -1); while (thisYear == calendar.get(Calendar.YEAR)) { calendar.add(Calendar.DAY_OF_YEAR, -1); } calendar.add(Calendar.DAY_OF_YEAR, 1); } }); register("^T\\+(\\d+)y$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.YEAR, Integer.parseInt(value)); } }); register("^T\\-(\\d+)y$", new DateModifier() { public void modify(Calendar calendar, String value) { calendar.add(Calendar.YEAR, Integer.parseInt(value) * -1); } }); }
From source file:com.application.utils.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *//* w ww .ja va2 s . co m*/ protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<Rule>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerWebAction.java
/** * Handle the date change.//from w ww .jav a 2s . c o m * * @throws ParseException * When can't parse date. */ public void dateSwitcherAction() throws ParseException { String[] dayBackValue = getHttpRequest().getParameterValues("dayBack"); String[] dayNextValue = getHttpRequest().getParameterValues("dayNext"); String[] weekBackValue = getHttpRequest().getParameterValues("weekBack"); String[] weekNextValue = getHttpRequest().getParameterValues("weekNext"); String[] monthBackValue = getHttpRequest().getParameterValues("monthBack"); String[] monthNextVaule = getHttpRequest().getParameterValues("monthNext"); Calendar tempCal = Calendar.getInstance(); date = DateTimeConverterUtil.stringToDate(dateFormated); tempCal.setTime(date); if (dayNextValue != null) { tempCal.add(Calendar.DAY_OF_YEAR, 1); date = tempCal.getTime(); dateFormated = DateTimeConverterUtil.dateToString(date); } else if (dayBackValue != null) { tempCal.add(Calendar.DAY_OF_YEAR, -1); date = tempCal.getTime(); dateFormated = DateTimeConverterUtil.dateToString(date); } else if (monthNextVaule != null) { tempCal.add(Calendar.MONTH, 1); date = tempCal.getTime(); dateFormated = DateTimeConverterUtil.dateToString(date); } else if (monthBackValue != null) { tempCal.add(Calendar.MONTH, -1); date = tempCal.getTime(); dateFormated = DateTimeConverterUtil.dateToString(date); } else if (weekNextValue != null) { tempCal.add(Calendar.WEEK_OF_YEAR, 1); date = tempCal.getTime(); dateFormated = DateTimeConverterUtil.dateToString(date); } else if (weekBackValue != null) { tempCal.add(Calendar.WEEK_OF_YEAR, -1); date = tempCal.getTime(); dateFormated = DateTimeConverterUtil.dateToString(date); } else { parseDateParam(); } }
From source file:com.mobileman.projecth.business.impl.PatientMedicationServiceImpl.java
/** * {@inheritDoc}// w ww.java 2s . com * @see com.mobileman.projecth.business.PatientMedicationService#addConsumedMedication(java.lang.Long, java.lang.Long, java.lang.Long, double, com.mobileman.projecth.domain.util.medication.MedicationFrequency, java.util.Date, java.util.Date, java.lang.String) */ @Override public void addConsumedMedication(Long patientId, Long diseaseId, Long medicationId, double standarUnitsTaken, MedicationFrequency frequency, Date startDate, Date endDate, String comment) throws IllegalArgumentException { if (log.isDebugEnabled()) { log.debug("addConsumedMedication(" + patientId + ", " + diseaseId + ", " + medicationId + ", " + standarUnitsTaken + ", " + frequency + ", " + startDate + ", " + endDate + ") - start"); //$NON-NLS-1$ } if (patientId == null) { throw new IllegalArgumentException("patientId must not be null"); } if (diseaseId == null) { throw new IllegalArgumentException("diseaseId must not be null"); } if (medicationId == null) { throw new IllegalArgumentException("medicationId must not be null"); } if (standarUnitsTaken <= 0.0d) { throw new IllegalArgumentException("standarUnitsTaken must not be zero or negative value"); } if (frequency == null) { throw new IllegalArgumentException("frequency must not be null"); } if (endDate == null) { endDate = startDate; } Patient patient = patientDao.findById(patientId); patient.setLastUpdate(new Date()); Medication medication = medicationDao.findById(medicationId); Disease disease = diseaseDao.findById(diseaseId); Date date = startDate; Calendar calendar = new GregorianCalendar(); calendar.setTime(startDate); Date timestamp = new Date(); while (date.before(endDate) || date.equals(endDate)) { PatientMedication patientMedication = new PatientMedication(); patientMedication.setTimestamp(timestamp); patientMedication.setPatient(patient); patientMedication.setMedication(medication); patientMedication.setComment(comment); patientMedication.setConsumptionDate(date); patientMedication.setDisease(disease); patientMedication.setAmount(new BigDecimal(standarUnitsTaken)); patientMedicationDao.save(patientMedication); if (frequency.equals(MedicationFrequency.ONE_TIME)) { break; } switch (frequency) { case DAILY: calendar.add(Calendar.DAY_OF_YEAR, 1); break; case WEEKLY: calendar.add(Calendar.WEEK_OF_YEAR, 1); break; case BI_WEEKLY: calendar.add(Calendar.WEEK_OF_YEAR, 2); break; default: break; } date = calendar.getTime(); } if (log.isDebugEnabled()) { log.debug("addConsumedMedication(Long, Long, Long, double) - returns"); //$NON-NLS-1$ } }
From source file:org.nuclos.common2.DateUtils.java
private static void calc(GregorianCalendar result, CalcFunction cf, CalcPair cp) { switch (cf) { case ADD:/*ww w .j av a2s.com*/ result.add(cp.x, cp.y); break; case SUBTRACT: result.add(cp.x, cp.y * (-1)); break; case SET: switch (cp.x) { case Calendar.YEAR: result.set(Calendar.DAY_OF_YEAR, cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_YEAR) : result.getActualMaximum(Calendar.DAY_OF_YEAR)); break; case Calendar.MONTH: result.set(Calendar.DAY_OF_MONTH, cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_MONTH) : result.getActualMaximum(Calendar.DAY_OF_MONTH)); break; case Calendar.WEEK_OF_YEAR: result.set(Calendar.DAY_OF_WEEK, cp.y == Integer.MIN_VALUE ? Calendar.MONDAY : Calendar.SUNDAY); break; } break; } }
From source file:com.bjorsond.android.timeline.utilities.Utilities.java
public static Date adjustDate(Zoom zoom, Date zoomDate, int moveDirection) { Calendar cal = Calendar.getInstance(); cal.setTime(zoomDate);//from w ww.ja v a 2 s.c o m System.out.println("Before adjusting " + zoom + " " + getMonthNumberOfDate(zoomDate) + " " + moveDirection); switch (zoom.getType()) { case HOUR_MODE: cal.add(Calendar.HOUR_OF_DAY, moveDirection); System.out.println("Adjusting " + zoom + " " + cal.getTime() + " " + moveDirection); return cal.getTime(); case DAY_MODE: cal.add(Calendar.DATE, moveDirection); return cal.getTime(); case WEEK_MODE: cal.add(Calendar.WEEK_OF_YEAR, moveDirection); return cal.getTime(); case MONTH_MODE: cal.add(Calendar.MONTH, moveDirection); System.out.println("After adjusting " + zoom + " " + getMonthNumberOfDate(cal.getTime())); return cal.getTime(); default: return null; } }
From source file:com.projity.script.object.TimeIntervals.java
public static TimeWindow generateWindow(long start, int scale, int sign) { int timeType, timeType2 = 0, number2; int timeIncrement = 1, timeIncrement2 = 1; switch (scale) { case TimeIntervals.DAY: timeType = Calendar.DAY_OF_MONTH; timeType2 = Calendar.WEEK_OF_YEAR; break;/*w w w. j a v a 2 s. c om*/ case TimeIntervals.WEEK: timeType = Calendar.WEEK_OF_YEAR; timeType2 = Calendar.MONTH; break; case TimeIntervals.MONTH: timeType = Calendar.MONTH; timeType2 = Calendar.MONTH; timeIncrement2 = 3; break; case TimeIntervals.QUARTER: timeType = Calendar.MONTH; timeType2 = Calendar.YEAR; timeIncrement = 3; break; case TimeIntervals.YEAR: timeType = Calendar.YEAR; timeType2 = Calendar.YEAR; break; default: return null; } Calendar c = Calendar.getInstance(DateUtils.UTC_TIME_ZONE, Locale.US);//DateTime.calendarInstance(); c.setTimeInMillis(start); //adapt start floorCal(scale, c); long s1 = c.getTimeInMillis(); floorCal(scale + 1, c); long s2 = c.getTimeInMillis(); c.setTimeInMillis(s1); long s; while ((s = c.getTimeInMillis()) >= s2) { //can occur with week, month scale s1 = s; c.add(timeType, -timeIncrement); } //set approximative end c.setTimeInMillis(s1); c.add(timeType, sign * timeIncrement * WINDOW_INTERVALS); TimeWindow win = new TimeWindow(); if (sign > 0) win.setS(s1); else win.setE(s1); if (sign > 0) win.setE(c.getTimeInMillis()); else win.setS(c.getTimeInMillis()); return win; }
From source file:org.codice.ddf.commands.catalog.DuplicateCommands.java
protected long getFilterStartTime(long now) { long startTime = 0; if (lastHours > 0) { startTime = now - TimeUnit.HOURS.toMillis(lastHours); } else if (lastDays > 0) { startTime = now - TimeUnit.DAYS.toMillis(lastDays); } else if (lastWeeks > 0) { Calendar weeks = GregorianCalendar.getInstance(); weeks.setTimeInMillis(now);/*from ww w .java2s . com*/ weeks.add(Calendar.WEEK_OF_YEAR, -1 * lastWeeks); startTime = weeks.getTimeInMillis(); } else if (lastMonths > 0) { Calendar months = GregorianCalendar.getInstance(); months.setTimeInMillis(now); months.add(Calendar.MONTH, -1 * lastMonths); startTime = months.getTimeInMillis(); } return startTime; }
From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java
@Override public Inicio manana(Inicio inicio) { Inicio manana = new Inicio(); Integer anio = new Integer(inicio.getAnio()); String trimestre = inicio.getTrimestre(); String leccion = inicio.getLeccion(); String dia = inicio.getDia(); if (StringUtils.isBlank(dia)) { dia = obtieneDia(new GregorianCalendar(Locale.ENGLISH).get(Calendar.DAY_OF_WEEK)); }// ww w. ja v a2 s . com Trimestre t = trimestreService.obtiene(anio + trimestre); if (t != null) { try { Calendar cal = new GregorianCalendar(Locale.ENGLISH); cal.setTime(t.getInicia()); cal.add(Calendar.SECOND, 1); cal.set(Calendar.DAY_OF_WEEK, obtieneDia(dia)); int weeks = ((Long) nf.parse(leccion.substring(1))).intValue(); if (dia.equals("sabado")) { weeks--; } cal.add(Calendar.WEEK_OF_YEAR, weeks); cal.add(Calendar.DAY_OF_MONTH, +1); Date hoy = cal.getTime(); manana.setHoy(hoy); t = trimestreService.obtiene(hoy); DateTime a = new DateTime(t.getInicia()); DateTime b = new DateTime(hoy); Weeks c = Weeks.weeksBetween(a, b); weeks = c.getWeeks(); weeks++; leccion = "l" + dosDigitos.format(weeks); manana.setAnio(t.getNombre().substring(0, 4)); manana.setTrimestre(t.getNombre().substring(4)); manana.setLeccion(leccion); manana.setDia(obtieneDia(cal.get(Calendar.DAY_OF_WEEK))); return manana; } catch (ParseException e) { log.error("No pude poner la fecha de manana", e); } } return null; }
From source file:org.kalypso.ogc.sensor.metadata.MetadataHelper.java
public static void setTimestep(final MetadataList mdl, final Period timestep) { final int[] values = timestep.getValues(); int fieldCount = 0; for (final int value : values) { if (value != 0) fieldCount++;/*w ww.j a v a 2s. c om*/ } if (fieldCount > 1) throw new IllegalArgumentException(Messages.getString("MetadataHelper_2") + timestep); //$NON-NLS-1$ int amount = -1; int calendarField = -1; if (timestep.getDays() != 0) { amount = timestep.getDays(); calendarField = Calendar.DAY_OF_MONTH; } else if (timestep.getHours() != 0) { amount = timestep.getHours(); calendarField = Calendar.HOUR_OF_DAY; } else if (timestep.getMillis() != 0) { amount = timestep.getMillis(); calendarField = Calendar.MILLISECOND; } else if (timestep.getMinutes() != 0) { amount = timestep.getMinutes(); calendarField = Calendar.MINUTE; } else if (timestep.getMonths() != 0) { amount = timestep.getMonths(); calendarField = Calendar.MONTH; } else if (timestep.getSeconds() != 0) { amount = timestep.getSeconds(); calendarField = Calendar.SECOND; } else if (timestep.getWeeks() != 0) { amount = timestep.getWeeks(); calendarField = Calendar.WEEK_OF_YEAR; } else if (timestep.getYears() != 0) { amount = timestep.getYears(); calendarField = Calendar.YEAR; } if (amount == -1) throw new IllegalArgumentException(Messages.getString("MetadataHelper_3")); //$NON-NLS-1$ setTimestep(mdl, calendarField, amount); return; }