List of usage examples for org.joda.time DateTime withDayOfWeek
public DateTime withDayOfWeek(int dayOfWeek)
From source file:ca.farrelltonsolar.classic.DayLogCalendar.java
License:Apache License
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { theView = inflater.inflate(R.layout.day_log_calendar, container, false); Bundle args = getArguments();//from w w w . j a v a 2 s . c o m int monthOffset = args != null ? args.getInt(ARG_MONTH) : 0; month = DateTime.now().minusMonths(monthOffset).withTimeAtStartOfDay().withDayOfMonth(1); adapter = new CalendarAdapter(this.getActivity(), month); GridView gridview = (GridView) theView.findViewById(R.id.gridview); gridview.setAdapter(adapter); gridview.setVelocityScale(5); TextView title = (TextView) theView.findViewById(R.id.title); title.setText(month.toString("MMMM yyyy")); View linearLayout = theView.findViewById(R.id.headerlayout); DateTime days = month; for (int i = 0; i < 7; i++) { int d = ((i + 6) % 7) + 1; days = days.withDayOfWeek(d); TextView aDay = new TextView(theView.getContext()); aDay.setText(DateTimeFormat.forPattern("E").print(days)); aDay.setGravity(Gravity.CENTER); aDay.setTextColor(Color.BLACK); aDay.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); ((LinearLayout) linearLayout).addView(aDay); } return theView; }
From source file:com.arpnetworking.kairosdb.aggregators.MovingWindowAggregator.java
License:Apache License
/** * For YEARS, MONTHS, WEEKS, DAYS: Computes the timestamp of the first * millisecond of the day of the timestamp. For HOURS, Computes the timestamp of * the first millisecond of the hour of the timestamp. For MINUTES, Computes the * timestamp of the first millisecond of the minute of the timestamp. For * SECONDS, Computes the timestamp of the first millisecond of the second of the * timestamp. For MILLISECONDS, returns the timestamp * * @param timestamp Timestamp in milliseconds to use as a basis for range alignment * @return timestamp aligned to the configured sampling unit *//*from ww w.ja va 2 s.c om*/ @SuppressWarnings("fallthrough") @SuppressFBWarnings("SF_SWITCH_FALLTHROUGH") private long alignRangeBoundary(final long timestamp) { DateTime dt = new DateTime(timestamp, _timeZone); final TimeUnit tu = m_sampling.getUnit(); switch (tu) { case YEARS: dt = dt.withDayOfYear(1).withMillisOfDay(0); break; case MONTHS: dt = dt.withDayOfMonth(1).withMillisOfDay(0); break; case WEEKS: dt = dt.withDayOfWeek(1).withMillisOfDay(0); break; case DAYS: dt = dt.withHourOfDay(0); case HOURS: dt = dt.withMinuteOfHour(0); case MINUTES: dt = dt.withSecondOfMinute(0); case SECONDS: default: dt = dt.withMillisOfSecond(0); break; } return dt.getMillis(); }
From source file:com.boxedfolder.carrot.service.impl.AnalyticsServiceImpl.java
License:Open Source License
@Override public List<AnalyticsLog> findAll(DateTime from, DateTime to) { // Defaults to weekly if (from == null || to == null) { from = new DateTime(); from = from.withDayOfWeek(1).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); to = new DateTime(); to = to.withDayOfWeek(1).plusWeeks(1).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); }// w w w. j av a2s .co m return analyticsLogRepository.findAll(from, to); }
From source file:com.epam.ta.reportportal.core.project.impl.ProjectInfoWidgetDataConverter.java
License:Open Source License
/** * <b>Quantity of Launches</b> project info widget content * /*from w ww. jav a 2 s . c o m*/ * @param initial * @param interval * @return */ public Map<String, List<ChartObject>> getLaunchesQuantity(List<Launch> initial, InfoInterval interval) { final String START_PERIOD = "start"; final String END_PERIOD = "end"; final String COUNT = "count"; final String INTERVAL = "interval"; HashMap<String, List<ChartObject>> result = new HashMap<>(); if (initial.isEmpty()) { return result; } ProjectInfoGroup criteria = grouping.get(interval); Map<String, List<Launch>> grouped = groupBy(initial, criteria); for (Entry<String, List<Launch>> entry : grouped.entrySet()) { List<Launch> launches = entry.getValue(); Integer count = null != launches ? launches.size() : 0; ChartObject group = new ChartObject(); Map<String, String> values = new HashMap<>(); values.put(COUNT, String.valueOf(count)); values.put(INTERVAL, interval.getInterval()); if (criteria != BY_DAY) { DateTime parse = DateTime.parse(entry.getKey()); // TODO remove Yoda time. replace with JDK8 values.put(START_PERIOD, parse.withDayOfWeek(DateTimeConstants.MONDAY).toString("yyy-MM-dd")); values.put(END_PERIOD, parse.withDayOfWeek(DateTimeConstants.SUNDAY).toString("yyy-MM-dd")); } else { values.put(START_PERIOD, entry.getKey()); } group.setName("Number of launches"); group.setValues(values); result.put(entry.getKey(), Collections.singletonList(group)); } return result; }
From source file:com.netflix.ice.processor.BillingFileProcessor.java
License:Apache License
private void archiveSummary(Map<Product, ReadWriteData> dataMap, String prefix) throws Exception { DateTime monthDateTime = new DateTime(startMilli, DateTimeZone.UTC); for (Product product : dataMap.keySet()) { String prodName = product == null ? "all" : product.name; ReadWriteData data = dataMap.get(product); Collection<TagGroup> tagGroups = data.getTagGroups(); // init daily, weekly and monthly List<Map<TagGroup, Double>> daily = Lists.newArrayList(); List<Map<TagGroup, Double>> weekly = Lists.newArrayList(); List<Map<TagGroup, Double>> monthly = Lists.newArrayList(); // get last month data ReadWriteData lastMonthData = new DataWriter(prefix + "hourly_" + prodName + "_" + AwsUtils.monthDateFormat.print(monthDateTime.minusMonths(1)), true).getData(); // aggregate to daily, weekly and monthly int dayOfWeek = monthDateTime.getDayOfWeek(); int daysFromLastMonth = dayOfWeek - 1; int lastMonthNumHours = monthDateTime.minusMonths(1).dayOfMonth().getMaximumValue() * 24; for (int hour = 0 - daysFromLastMonth * 24; hour < data.getNum(); hour++) { if (hour < 0) { // handle data from last month, add to weekly Map<TagGroup, Double> prevData = lastMonthData.getData(lastMonthNumHours + hour); for (TagGroup tagGroup : tagGroups) { Double v = prevData.get(tagGroup); if (v != null && v != 0) { addValue(weekly, 0, tagGroup, v); }// w ww .j av a 2s . c om } } else { // this month, add to weekly, monthly and daily Map<TagGroup, Double> map = data.getData(hour); for (TagGroup tagGroup : tagGroups) { Double v = map.get(tagGroup); if (v != null && v != 0) { addValue(monthly, 0, tagGroup, v); addValue(daily, hour / 24, tagGroup, v); addValue(weekly, (hour + daysFromLastMonth * 24) / 24 / 7, tagGroup, v); } } } } // archive daily int year = monthDateTime.getYear(); DataWriter writer = new DataWriter(prefix + "daily_" + prodName + "_" + year, true); ReadWriteData dailyData = writer.getData(); dailyData.setData(daily, monthDateTime.getDayOfYear() - 1, false); writer.archive(); // archive monthly writer = new DataWriter(prefix + "monthly_" + prodName, true); ReadWriteData monthlyData = writer.getData(); monthlyData.setData(monthly, Months.monthsBetween(config.startDate, monthDateTime).getMonths(), false); writer.archive(); // archive weekly writer = new DataWriter(prefix + "weekly_" + prodName, true); ReadWriteData weeklyData = writer.getData(); DateTime weekStart = monthDateTime.withDayOfWeek(1); int index; if (!weekStart.isAfter(config.startDate)) index = 0; else index = Weeks.weeksBetween(config.startDate, weekStart).getWeeks() + (config.startDate.dayOfWeek() == weekStart.dayOfWeek() ? 0 : 1); weeklyData.setData(weekly, index, true); writer.archive(); } }
From source file:com.sos.scheduler.model.objects.JodaTools.java
License:Apache License
/** * \brief calculate a date for a specific weekday based on a given date * \detail/*from w w w . jav a2 s .c o m*/ * @param date - the base date * @param weekday - the weekday * @return */ public static DateTime getNextWeekday(DateTime date, int weekday) { if (date.getDayOfWeek() > weekday) date = date.plusWeeks(1); return date.withDayOfWeek(weekday); }
From source file:com.sos.scheduler.model.objects.JodaTools.java
License:Apache License
/** * \brief calculate a date for a specific weekday based on a given date * \detail/* w ww . j ava2 s . c om*/ * * @param date * @param weekday * @return */ public static DateTime getPreviousWeekday(DateTime date, int weekday) { if (date.getDayOfWeek() < weekday) date = date.minusWeeks(1); return date.withDayOfWeek(weekday); }
From source file:com.vaushell.superpipes.nodes.buffer.Slot.java
License:Open Source License
/** * Return the time to wait to be in a slot and not to burst. * * @param date Actual date/*from ww w. j ava 2 s . c o m*/ * @return the time to wait */ public Duration getSmallestDiff(final DateTime date) { if (areWeInside(date)) { return new Duration(0L); } Duration smallest = null; for (final int dayOfWeek : daysOfWeek) { DateTime next = date.withDayOfWeek(dayOfWeek).withMillisOfDay(minMillisOfDay); if (next.isBefore(date)) { next = next.plusWeeks(1); } final Duration duration = new Duration(date, next); if (smallest == null || duration.isShorterThan(smallest)) { smallest = duration; } } return smallest; }
From source file:cron.Times.java
License:Open Source License
private void addDaysOfWeek(ImmutableSortedSet.Builder<DateTime> builder, DateTime base) { int month = base.getMonthOfYear(); Iterator<Integer> iterator = daysOfWeek.iterator(); base = base.withDayOfWeek(iterator.next()); if (base.getMonthOfYear() != month) base = base.plusWeeks(1);//from ww w .ja v a 2 s .co m do { builder.add(base); base = base.plusWeeks(1); } while (base.getMonthOfYear() == month); }
From source file:dk.teachus.frontend.utils.WeekDayChoiceRenderer.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from w w w . j a va 2 s . co m*/ public Object getDisplayValue(Object object) { StringBuilder display = new StringBuilder(); DateTimeFormatter formatter = null; if (format == Format.LONG) { formatter = Formatters.getFormatWeekDay(); } else if (format == Format.SHORT) { formatter = Formatters.getFormatWeekDayShort(); } if (object != null) { if (object instanceof List) { DateTime dt = new DateTime(); List<WeekDay> weekDays = (List<WeekDay>) object; for (WeekDay weekDay : weekDays) { if (display.length() > 0) { display.append(", "); //$NON-NLS-1$ } dt = dt.withDayOfWeek(weekDay.getYodaWeekDay()); display.append(formatter.print(dt)); } } else if (object instanceof WeekDay) { WeekDay weekDay = (WeekDay) object; DateTime dt = new DateTime().withDayOfWeek(weekDay.getYodaWeekDay()); display.append(formatter.print(dt)); } } return display; }