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:TimeLib.java
/** * Based on code posted at//from www.java2s. co m * http://forum.java.sun.com/thread.jspa?threadID=488676&messageID=2292012 */ private static int estimateUnitsBetween(long t0, long t1, int field) { long d = t1 - t0; switch (field) { case Calendar.MILLISECOND: return (int) d; // this could be very inaccurate. TODO: use long instead of int? case Calendar.SECOND: return (int) (d / SECOND_MILLIS + .5); case Calendar.MINUTE: return (int) (d / MINUTE_MILLIS + .5); case Calendar.HOUR_OF_DAY: case Calendar.HOUR: return (int) (d / HOUR_MILLIS + .5); case Calendar.DAY_OF_WEEK_IN_MONTH: case Calendar.DAY_OF_MONTH: // case Calendar.DATE : // codes to same int as DAY_OF_MONTH return (int) (d / DAY_MILLIS + .5); case Calendar.WEEK_OF_YEAR: return (int) (d / WEEK_MILLIS + .5); case Calendar.MONTH: return (int) (d / MONTH_MILLIS + .5); case Calendar.YEAR: return (int) (d / YEAR_MILLIS + .5); case DECADE: return (int) (d / DECADE_MILLIS + .5); case CENTURY: return (int) (d / CENTURY_MILLIS + .5); case MILLENIUM: return (int) (d / MILLENIUM_MILLIS + .5); default: return 0; } }
From source file:org.openmrs.module.clinicalsummary.rule.reminder.adult.pregnancy.StartARVStageHIVReminderRule.java
@Override protected Result evaluate(LogicContext context, Integer patientId, Map<String, Object> parameters) { Result result = new Result(); EncounterWithRestrictionRule encounterWithRestrictionRule = new EncounterWithStringRestrictionRule(); parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN)); parameters.put(EvaluableConstants.ENCOUNTER_FETCH_SIZE, 1); Result encounterResults = encounterWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(encounterResults)) { Result encounterResult = encounterResults.latest(); AntiRetroViralRule antiRetroViralRule = new AntiRetroViralRule(); // prepare the encounter types parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_NONCLINICALMEDICATION)); Result arvResults = antiRetroViralRule.eval(context, patientId, parameters); if (CollectionUtils.isEmpty(arvResults)) { Calendar calendar = Calendar.getInstance(); calendar.setTime(encounterResult.getResultDate()); calendar.add(Calendar.WEEK_OF_YEAR, 42); Date fortyTwoWeeksLater = calendar.getTime(); ObsWithRestrictionRule obsWithRestrictionRule = new ObsWithStringRestrictionRule(); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("REASON ANTIRETROVIRALS STARTED", "CURRENT WHO HIV STAGE", "PATIENT REPORTED WHO STAGE PRIOR TO ENROLLMENT AT AMPATH, ADULT")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList("WHO STAGE 3 ADULT", "WHO STAGE 4 ADULT", "ADULT WHO STAGE 3 WITH CD4 COUNT LESS THAN 350")); Result whoStageResults = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(whoStageResults) && whoStageResults.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add(/*ww w . j a va 2 s.c o m*/ new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } } } return result; }
From source file:org.openmrs.module.clinicalsummary.rule.reminder.adult.pregnancy.StartARVDiscordantHIVReminderRule.java
@Override protected Result evaluate(LogicContext context, Integer patientId, Map<String, Object> parameters) { Result result = new Result(); EncounterWithRestrictionRule encounterWithRestrictionRule = new EncounterWithStringRestrictionRule(); parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN)); parameters.put(EvaluableConstants.ENCOUNTER_FETCH_SIZE, 1); Result encounterResults = encounterWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(encounterResults)) { Result encounterResult = encounterResults.latest(); AntiRetroViralRule antiRetroViralRule = new AntiRetroViralRule(); // prepare the encounter types parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_NONCLINICALMEDICATION)); Result arvResults = antiRetroViralRule.eval(context, patientId, parameters); if (CollectionUtils.isEmpty(arvResults)) { Calendar calendar = Calendar.getInstance(); calendar.setTime(encounterResult.getResultDate()); calendar.add(Calendar.WEEK_OF_YEAR, 42); Date fortyTwoWeeksLater = calendar.getTime(); ObsWithRestrictionRule obsWithRestrictionRule = new ObsWithStringRestrictionRule(); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("DISCORDANT COUPLE")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList("YES")); Result discordantCoupleResults = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(discordantCoupleResults) && discordantCoupleResults.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add(//from w w w. j a va2s. c om new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("REASON ANTIRETROVIRALS STARTED", "MOST AT RISK PERSON FOR GETTING HIV INFECTION")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList("DISCORDANT COUPLE")); Result discordantCoupleAnswerResults = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(discordantCoupleAnswerResults) && discordantCoupleAnswerResults.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add( new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } } } return result; }
From source file:org.openmrs.module.clinicalsummary.rule.reminder.adult.pregnancy.StartARVBreastfeedingHIVReminderRule.java
@Override protected Result evaluate(LogicContext context, Integer patientId, Map<String, Object> parameters) { Result result = new Result(); EncounterWithRestrictionRule encounterWithRestrictionRule = new EncounterWithStringRestrictionRule(); parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN)); parameters.put(EvaluableConstants.ENCOUNTER_FETCH_SIZE, 1); Result encounterResults = encounterWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(encounterResults)) { Result encounterResult = encounterResults.latest(); AntiRetroViralRule antiRetroViralRule = new AntiRetroViralRule(); // prepare the encounter types parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_NONCLINICALMEDICATION)); Result arvResults = antiRetroViralRule.eval(context, patientId, parameters); if (CollectionUtils.isEmpty(arvResults)) { Calendar calendar = Calendar.getInstance(); calendar.setTime(encounterResult.getResultDate()); calendar.add(Calendar.WEEK_OF_YEAR, 42); Date fortyTwoWeeksLater = calendar.getTime(); ObsWithRestrictionRule obsWithRestrictionRule = new ObsWithStringRestrictionRule(); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("MOTHER CURRENTLY BREASTFEEDING")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList("YES")); Result currentlyBreastfeedingResults = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(currentlyBreastfeedingResults) && currentlyBreastfeedingResults.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add(/* w ww . j a v a 2 s. c om*/ new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("INFANT FEEDING METHOD")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList("BREASTFEEDING EXCLUSIVELY", "BREASTFEEDING PREDOMINATELY", "MIXED FEEDING")); Result feedingMethodResults = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(feedingMethodResults) && feedingMethodResults.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add( new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } } } return result; }
From source file:odin.util.ReadGoogleSpreadsheet.java
private static void process(String sprintName) throws MalformedURLException, IOException, ServiceException, GeneralSecurityException, ParseException, Exception { logger.info("Getting worksheet (same name as sprint): " + sprintName); StringBuffer returnBody = new StringBuffer(); returnBody.append("<p>" + ReadGoogleSpreadsheet.class.getName() + " Completed"); URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full"); ListFeed listFeedSpreadsheet = GoogleOAuthIntegration.getSpreadsheetService().getFeed(SPREADSHEET_FEED_URL, ListFeed.class); WorksheetEntry worksheet = getWorkSheet(sprintName); logger.info("Worksheet title: " + worksheet.getTitle().getPlainText()); returnBody.append("<ul><li>Worksheet title: " + worksheet.getTitle().getPlainText() + "</li></ul>"); // Fetch the list feed of the worksheet. URL listFeedUrl = worksheet.getListFeedUrl(); ListFeed listFeed = GoogleOAuthIntegration.getSpreadsheetService().getFeed(listFeedUrl, ListFeed.class); // StringBuffer sb = new StringBuffer(); // Iterate through each row, printing its cell values. for (ListEntry row : listFeed.getEntries()) { String username = null;/*from w ww .j a v a2 s. c o m*/ // Print the first column's cell value // Iterate over the remaining columns, and print each cell value for (String tag : row.getCustomElements().getTags()) { logger.info("CustomElement tag value: " + row.getCustomElements().getValue(tag)); if (tag.equals("username")) username = row.getCustomElements().getValue(tag); if (tag.startsWith("week")) { // Get week number from Google spreadsheet tag String weekNumber = tag.substring(4); // Get last date of that week. SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.WEEK_OF_YEAR, new Integer(weekNumber).intValue()); cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); String wkEndDtS = sdf.format(cal.getTime()); logger.info("wkEndDtS=" + wkEndDtS); // get hours int hours = 0; if (row.getCustomElements().getValue(tag) != null) hours = new Integer(row.getCustomElements().getValue(tag)).intValue(); // Update availability in local database Availability.setAvailability(wkEndDtS, username, hours); } } } OdinResponse res = new OdinResponse(); res.setStatusCode(0); res.setReasonPhrase("OK"); res.setMessageBody(returnBody.toString()); sendJobMessage(res); }
From source file:org.openmrs.module.clinicalsummary.rule.reminder.adult.pregnancy.StartARVPregnantHIVReminderRule.java
@Override protected Result evaluate(LogicContext context, Integer patientId, Map<String, Object> parameters) { Result result = new Result(); EncounterWithRestrictionRule encounterWithRestrictionRule = new EncounterWithStringRestrictionRule(); parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN)); parameters.put(EvaluableConstants.ENCOUNTER_FETCH_SIZE, 1); Result encounterResults = encounterWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(encounterResults)) { Result encounterResult = encounterResults.latest(); AntiRetroViralRule antiRetroViralRule = new AntiRetroViralRule(); // prepare the encounter types parameters.put(EvaluableConstants.ENCOUNTER_TYPE, Arrays.asList(EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_INITIAL, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_RETURN, EvaluableNameConstants.ENCOUNTER_TYPE_ADULT_NONCLINICALMEDICATION)); Result arvResults = antiRetroViralRule.eval(context, patientId, parameters); if (CollectionUtils.isEmpty(arvResults)) { Calendar calendar = Calendar.getInstance(); calendar.setTime(encounterResult.getResultDate()); calendar.add(Calendar.WEEK_OF_YEAR, 42); Date fortyTwoWeeksLater = calendar.getTime(); ObsWithRestrictionRule obsWithRestrictionRule = new ObsWithStringRestrictionRule(); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(PREGNANCY_STATUS)); parameters.put(EvaluableConstants.OBS_FETCH_SIZE, 1); Result pregnancyStatus = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(pregnancyStatus)) { Result pregnancyStatusResult = pregnancyStatus.latest(); if (pregnancyStatusResult.toBoolean() && pregnancyStatusResult.getResultDate().before(fortyTwoWeeksLater)) { result.add(new Result( String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; }// w w w . j a va 2s .c o m } parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("URINE PREGNANCY TEST")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList(EvaluableNameConstants.POSITIVE)); Result urinePregnancy = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(urinePregnancy) && urinePregnancy.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add( new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(EvaluableNameConstants.PROBLEM_ADDED)); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList("PREGNANCY")); Result problemAdded = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(problemAdded) && problemAdded.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add( new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("PREGNANCY STATUS, CODED")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList(EvaluableNameConstants.YES)); Result pregnancyStatusCoded = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(pregnancyStatusCoded) && pregnancyStatusCoded.latest().getResultDate().before(fortyTwoWeeksLater)) { result.add( new Result(String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(EvaluableNameConstants.NUMBER_OF_WEEKS_PREGNANT)); Result numberOfWeeksPregnant = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(numberOfWeeksPregnant)) { Result numberOfWeeksPregnantResult = numberOfWeeksPregnant.latest(); if (numberOfWeeksPregnant.toNumber() > 0 && numberOfWeeksPregnantResult.getResultDate().before(fortyTwoWeeksLater)) { result.add(new Result( String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } } parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("ANTENATAL CARE ENROLLED")); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList(EvaluableNameConstants.YES)); Result ancEnrolled = obsWithRestrictionRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(ancEnrolled)) { Result ancEnrolledResult = ancEnrolled.latest(); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(EvaluableNameConstants.PROBLEM_ADDED)); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList("PREGNANCY, MISCARRIAGE", "PREGNANCY, TERMINATION")); Result pregnancyProblemAdded = obsWithRestrictionRule.eval(context, patientId, parameters); if ((CollectionUtils.isEmpty(pregnancyProblemAdded) || pregnancyProblemAdded.latest() .getResultDate().before(encounterResult.getResultDate())) && ancEnrolledResult.getResultDate().before(fortyTwoWeeksLater)) { result.add(new Result( String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); return result; } } } } return result; }
From source file:org.osaf.cosmo.scheduler.ForwardLookingNotificationJob.java
@Override protected Report generateReport(JobExecutionContext context) throws JobExecutionException { TimeZone tz = timezone == null ? null : TimeZoneUtils.getTimeZone(timezone); Locale loc = locale == null ? Locale.getDefault() : new Locale(locale); // start date is the start of the day of the fire time Calendar cal = new GregorianCalendar(); if (tz != null) cal.setTimeZone(tz);/*from www . j ava 2 s .co m*/ cal.setTime(context.getFireTime()); cal.set(Calendar.AM_PM, Calendar.AM); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date startDate = new Date(cal.getTime().getTime()); // End date is either 1 day or 1 week later // depending on report type if (REPORT_TYPE_DAILY.equals(reportType)) cal.add(Calendar.DAY_OF_YEAR, 1); else cal.add(Calendar.WEEK_OF_YEAR, 1); cal.add(Calendar.SECOND, -1); Date endDate = cal.getTime(); if (log.isDebugEnabled()) { log.debug("startDate=" + startDate); log.debug("endDate = " + endDate); } // get results List<UpcomingResult> upcomingItems = new ArrayList<UpcomingResult>(); List<NowResult> nowItems = new ArrayList<NowResult>(); Iterator<String> it = getCollectionUids().iterator(); while (it.hasNext()) { String colUid = it.next(); // We have to handle changes to underlying collections. // A collection could have been deleted, or access to the // collection has been removed. In both cases, remove the // collection from the list so that the next job run // won't attempt to access it. try { getCollectionResults(colUid, startDate, endDate, tz, upcomingItems, nowItems); } catch (ItemSecurityException ise) { // user is not authorized for collection, // remove collection for next execution log.info("user " + getUsername() + " not authorized for collection " + colUid + ", removing from schedule " + context.getJobDetail().getName()); it.remove(); } catch (ItemNotFoundException infe) { // collection not found, remove collection for next execution log.info("collection " + colUid + " not found removing from schedule " + getUsername() + ":" + context.getJobDetail().getName()); it.remove(); } } // sort results Comparator<UpcomingResult> comparator = new UpcomingResultComparator(false, tz); Collections.sort(upcomingItems, comparator); // return results ForwardLookingReport report = new ForwardLookingReport(getUser()); report.setStartDate(startDate); report.setTimezone(tz == null ? TimeZone.getDefault() : tz); report.setLocale(loc); report.setReportType(reportType); report.setUpcomingItems(upcomingItems); report.setNowItems(nowItems); return report; }
From source file:org.opencms.notification.CmsNotificationCandidates.java
/** * Collects all resources that will expire in short time, or will become valid, or are not modified since a long time.<p> * /*from w w w. j a v a 2s. c om*/ * @param cms the CmsObject * * @throws CmsException if something goes wrong */ public CmsNotificationCandidates(CmsObject cms) throws CmsException { m_resources = new ArrayList(); m_cms = cms; m_cms.getRequestContext() .setCurrentProject(m_cms.readProject(OpenCms.getSystemInfo().getNotificationProject())); String folder = "/"; GregorianCalendar now = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); now.setTimeInMillis(System.currentTimeMillis()); GregorianCalendar inOneWeek = (GregorianCalendar) now.clone(); inOneWeek.add(Calendar.WEEK_OF_YEAR, 1); Iterator resources; CmsResource resource; // read all files with the 'notification-interval' property set try { resources = m_cms .readResourcesWithProperty(folder, CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL) .iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); int notification_interval = Integer.parseInt(m_cms .readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL, true) .getValue()); GregorianCalendar intervalBefore = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); intervalBefore.setTimeInMillis(resource.getDateLastModified()); intervalBefore.add(Calendar.DAY_OF_YEAR, notification_interval); GregorianCalendar intervalAfter = (GregorianCalendar) intervalBefore.clone(); intervalAfter.add(Calendar.WEEK_OF_YEAR, -1); for (int i = 0; (i < 100) && intervalAfter.getTime().before(now.getTime()); i++) { if (intervalBefore.getTime().after(now.getTime())) { m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_UPDATE_REQUIRED, intervalBefore.getTime())); } intervalBefore.add(Calendar.DAY_OF_YEAR, notification_interval); intervalAfter.add(Calendar.DAY_OF_YEAR, notification_interval); } } } catch (CmsDbEntryNotFoundException e) { // no resources with property 'notification-interval', ignore } // read all files that were not modified longer than the max notification-time GregorianCalendar oneYearAgo = (GregorianCalendar) now.clone(); oneYearAgo.add(Calendar.DAY_OF_YEAR, -OpenCms.getSystemInfo().getNotificationTime()); // create a resource filter to get the resources with CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION .addRequireLastModifiedBefore(oneYearAgo.getTimeInMillis()); resources = m_cms.readResources(folder, filter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_OUTDATED, new Date(resource.getDateLastModified()))); } // get all resources that will expire within the next week CmsResourceFilter resourceFilter = CmsResourceFilter.IGNORE_EXPIRATION .addRequireExpireBefore(inOneWeek.getTimeInMillis()); resourceFilter = resourceFilter.addRequireExpireAfter(now.getTimeInMillis()); resources = m_cms.readResources(folder, resourceFilter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_EXPIRES, new Date(resource.getDateExpired()))); } // get all resources that will release within the next week resourceFilter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireReleaseBefore(inOneWeek.getTimeInMillis()); resourceFilter = resourceFilter.addRequireReleaseAfter(now.getTimeInMillis()); resources = m_cms.readResources(folder, resourceFilter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_RELEASE, new Date(resource.getDateReleased()))); } }
From source file:com.ocs.dynamo.utils.DateUtils.java
/** * Translates a week code (yyyy-ww) to the starting day (this is taken to be a Monday) of that * week// w w w . jav a 2 s . c o m * * @param weekCode * @return */ public static Date getStartDateOfWeek(String weekCode) { if (weekCode != null && weekCode.matches(WEEK_CODE_PATTERN)) { int year = getYearFromWeekCode(weekCode); int week = getWeekFromWeekCode(weekCode); Calendar calendar = new GregorianCalendar(DynamoConstants.DEFAULT_LOCALE); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.WEEK_OF_YEAR, week); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return truncate(calendar).getTime(); } return null; }
From source file:com.linuxbox.enkive.statistics.gathering.past.PastGatherer.java
protected void setEndDate(int grain) { Calendar end = Calendar.getInstance(); end.set(Calendar.MILLISECOND, 0); end.set(Calendar.SECOND, 0);//from w w w .ja v a2 s . c o m end.set(Calendar.MINUTE, 0); if (grain == CONSOLIDATION_HOUR) { end.add(Calendar.HOUR_OF_DAY, -hrKeepTime); } else if (grain == CONSOLIDATION_DAY) { end.set(Calendar.HOUR_OF_DAY, 0); end.add(Calendar.DATE, -dayKeepTime); } else if (grain == CONSOLIDATION_WEEK) { end.set(Calendar.HOUR_OF_DAY, 0); while (end.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { end.add(Calendar.DATE, -1); } end.add(Calendar.WEEK_OF_YEAR, -weekKeepTime); } else if (grain == CONSOLIDATION_MONTH) { end.set(Calendar.HOUR_OF_DAY, 0); end.set(Calendar.DAY_OF_MONTH, 1); end.add(Calendar.MONTH, -monthKeepTime); } this.endDate = end.getTime(); }