List of usage examples for org.joda.time DateTime getDayOfYear
public int getDayOfYear()
From source file:brickhouse.udf.date.DayOfYearUDF.java
License:Apache License
public static int evaluate(String dateStr) { DateTime dt = YYYYMMDD.parseDateTime(dateStr); return dt.getDayOfYear(); }
From source file:com.aliakseipilko.flightdutytracker.view.adapter.DayBarChartAdapter.java
License:Open Source License
private void processDutyHours() { List<BarEntry> barDutyEntries = new ArrayList<>(); float xValueCount = 0f; int maxDaysInMonth = 0; long startDay = new DateTime(flights.minDate("startDutyTime")).getDayOfMonth(); long currentYear = 0; long currentMonth = 0; long currentDay = 0; boolean isMonthWrapping = false; for (Flight flight : flights) { DateTime startDateTime = new DateTime(flight.getStartDutyTime()); DateTime endDateTime = new DateTime(flight.getEndDutyTime()); float decHoursDiff = (Seconds.secondsBetween(startDateTime, endDateTime).getSeconds() / 60f) / 60f; //Dont display stats for today as they will be malformed if (startDateTime.getDayOfYear() == DateTime.now().getDayOfYear() && startDateTime.getYear() == DateTime.now().getYear()) { continue; }/*from w w w . ja v a 2 s .c om*/ if (currentYear == 0 && currentMonth == 0 && currentDay == 0) { currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); currentDay = startDateTime.getDayOfMonth(); maxDaysInMonth = determineDaysInMonth((int) currentMonth, (int) currentYear); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barDutyEntries.add(newEntry); xValueCount++; } else { //Check if month is wrapping if (currentDay + 1 >= maxDaysInMonth) { isMonthWrapping = true; } else { //Check if days are adjacent //Add skipped days onto xValueCount to display blank spaces in graph if (currentDay + 1 != startDateTime.getDayOfMonth()) { xValueCount += (startDateTime.getDayOfMonth() - currentDay) - 1; } } //Check if the date is the same as the previous flight // All flights are provided in an ordered list by the repo if (currentDay == startDateTime.getDayOfMonth() && currentMonth == startDateTime.getMonthOfYear() && currentYear == startDateTime.getYear()) { //Get last entry in list BarEntry lastEntry = barDutyEntries.get(barDutyEntries.size() - 1); //Add the additional hours in that day on, X value (the date) does not change lastEntry = new BarEntry(lastEntry.getX(), lastEntry.getY() + decHoursDiff); //Remove the last entry and add the modified entry instead of it barDutyEntries.remove(barDutyEntries.size() - 1); barDutyEntries.add(lastEntry); } else { //Check if days of month wrap around if (startDateTime.getMonthOfYear() != currentMonth) { isMonthWrapping = true; } //New day //Update these for the next iteration currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); currentDay = startDateTime.getDayOfMonth(); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barDutyEntries.add(newEntry); xValueCount++; } } } IAxisValueFormatter xAxisValueFormatter = new DayAxisValueFormatter((int) (startDay - 1), maxDaysInMonth); IAxisValueFormatter yAxisValueFormatter = new DefaultAxisValueFormatter(2); BarDataSet dataSet = new BarDataSet(barDutyEntries, "Duty Hours"); dataSet.setValueTextSize(16f); BarData barDutyData = new BarData(dataSet); barDutyData.setBarWidth(0.9f); barDutyData.setHighlightEnabled(false); view.setupDutyBarChart(barDutyData, xAxisValueFormatter, yAxisValueFormatter); }
From source file:com.aliakseipilko.flightdutytracker.view.adapter.DayBarChartAdapter.java
License:Open Source License
private void processFlightHours() { List<BarEntry> barFlightEntries = new ArrayList<>(); float xValueCount = 0f; int maxDaysInMonth = 0; long startDay = new DateTime(flights.minDate("startFlightTime")).getDayOfMonth(); long currentYear = 0; long currentMonth = 0; long currentDay = 0; boolean isMonthWrapping = false; for (Flight flight : flights) { DateTime startDateTime = new DateTime(flight.getStartFlightTime()); DateTime endDateTime = new DateTime(flight.getEndFlightTime()); float decHoursDiff = (Seconds.secondsBetween(startDateTime, endDateTime).getSeconds() / 60f) / 60f; //Dont display stats for today as they will be malformed if (startDateTime.getDayOfYear() == DateTime.now().getDayOfYear() && startDateTime.getYear() == DateTime.now().getYear()) { continue; }//from w w w . j a v a2 s . c o m if (currentYear == 0 && currentMonth == 0 && currentDay == 0) { currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); currentDay = startDateTime.getDayOfMonth(); maxDaysInMonth = determineDaysInMonth((int) currentMonth, (int) currentYear); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barFlightEntries.add(newEntry); xValueCount++; } else { //Check if month is wrapping if (currentDay + 1 >= maxDaysInMonth) { isMonthWrapping = true; } else { //Check if days are adjacent //Add skipped days onto xValueCount to display blank spaces in graph if (currentDay + 1 != startDateTime.getDayOfMonth()) { xValueCount = xValueCount + (startDateTime.getDayOfMonth() - currentDay) - 1; } } //Check if the date is the same as the previous flight // All flights are provided in an ordered list by the repo if (currentDay == startDateTime.getDayOfMonth() && currentMonth == startDateTime.getMonthOfYear() && currentYear == startDateTime.getYear()) { //Get last entry in list BarEntry lastEntry = barFlightEntries.get(barFlightEntries.size() - 1); //Add the additional hours in that day on, X value (the date) does not change lastEntry = new BarEntry(lastEntry.getX(), lastEntry.getY() + decHoursDiff); //Remove the last entry and add the modified entry instead of it barFlightEntries.remove(barFlightEntries.size() - 1); barFlightEntries.add(lastEntry); } else { //Check if days of month wrap around if (startDateTime.getMonthOfYear() != currentMonth) { isMonthWrapping = true; } //New day //Update these for the next iteration currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); currentDay = startDateTime.getDayOfMonth(); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barFlightEntries.add(newEntry); xValueCount++; } } } IAxisValueFormatter xAxisValueFormatter = new DayAxisValueFormatter((int) (startDay - 1), maxDaysInMonth); IAxisValueFormatter yAxisValueFormatter = new DefaultAxisValueFormatter(2); BarDataSet dataSet = new BarDataSet(barFlightEntries, "Flight Hours"); dataSet.setValueTextSize(16f); BarData barFlightData = new BarData(dataSet); barFlightData.setBarWidth(0.9f); barFlightData.setHighlightEnabled(false); view.setupFlightBarChart(barFlightData, xAxisValueFormatter, yAxisValueFormatter); }
From source file:com.animedetour.android.database.event.EventRepository.java
License:Open Source License
/** * Find All events for a specified day.//from ww w.j ava 2 s . c o m * * This is run by the START time of the event * * @param day The day to lookup events for * @return an observable that will update with events data */ public Subscription findAllOnDay(DateTime day, Observer<List<Event>> observer) { String key = "findAllOnDay:" + day.getDayOfYear(); return this.subscriptionFactory.createCollectionSubscription(this.allByDayFactory.createWorker(day), observer, key); }
From source file:com.animedetour.android.schedule.EventActivity.java
License:Open Source License
/** * Get details string for event/*ww w . jav a2s . c o m*/ * * The details for an event include the time and location for the event. * * @return The details string for the event */ protected String getEventDetailsString() { DateTime start = this.event.getStart(); DateTime end = this.event.getEnd(); String format = start.getDayOfYear() == end.getDayOfYear() ? this.getString(R.string.panel_details) : this.getString(R.string.panel_details_multiday); String location = this.event.getRoom(); return String.format(format, start.toDate(), end.toDate(), location); }
From source file:com.chiorichan.dvr.storage.Interface.java
License:Mozilla Public License
public File calculateContainingFile(DateTime td, String inputName) { String sep = System.getProperty("file.separator", "/"); // Main storage folder File file = new File(DVRLoader.getConfiguration().getString("config.storage", DVRLoader.instance.getDataFolder().getAbsolutePath())); // [storage]/2014/126/video1/block_[specialepoch].opv file = new File(file, td.getYear() + sep + td.getDayOfYear() + sep + inputName); // Create the needed directory structure. file.mkdirs();/*from w w w . j a va2 s. com*/ return new File(file, "block_" + getTen(td) + ".opv"); }
From source file:com.clevercloud.bianca.lib.date.DateModule.java
License:Open Source License
/** * Returns the parsed date.//from w ww.j av a 2s .c o m */ public Value strptime(Env env, String date, String format) { ArrayValueImpl array = new ArrayValueImpl(); DateTimeFormatterBuilder fb = new DateTimeFormatterBuilder(); int length = format.length(); for (int i = 0; i < length; i++) { char ch = format.charAt(i); if (ch != '%') { fb.appendLiteral(ch); continue; } switch (format.charAt(++i)) { case 'a': fb.appendDayOfWeekShortText(); break; case 'A': fb.appendDayOfWeekText(); break; case 'h': case 'b': fb.appendMonthOfYearShortText(); ; break; case 'B': fb.appendMonthOfYearText(); break; // TODO: case 'c' case 'C': fb.appendCenturyOfEra(2, 2); break; case 'd': fb.appendDayOfMonth(2); break; case 'D': fb.appendMonthOfYear(2); fb.appendLiteral('/'); fb.appendDayOfMonth(2); fb.appendLiteral('/'); fb.appendYear(2, 2); break; // TODO: case 'e' case 'F': fb.appendYear(4, 4); fb.appendLiteral('-'); fb.appendMonthOfYear(2); fb.appendLiteral('-'); fb.appendDayOfMonth(2); break; // TODO: case 'g' // TODO: case 'G' case 'H': fb.appendHourOfDay(2); break; case 'I': fb.appendHourOfHalfday(2); break; case 'j': fb.appendDayOfYear(3); break; // TODO: case 'l' case 'm': fb.appendMonthOfYear(2); break; case 'M': fb.appendMinuteOfHour(2); break; case 'n': fb.appendLiteral("\n"); break; case 'p': case 'P': fb.appendHalfdayOfDayText(); break; case 'r': fb.appendHourOfHalfday(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); fb.appendLiteral(' '); fb.appendHalfdayOfDayText(); break; case 'R': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); break; // TODO: case 's' case 'S': fb.appendSecondOfMinute(2); break; case 't': fb.appendLiteral("\t"); break; case 'T': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); break; // TODO: case 'u' // TODO: case 'U' // TODO: case 'V' // TODO: case 'w' // TODO: case 'W' // TODO: case 'x' // TODO: case 'X' case 'y': fb.appendYear(2, 2); break; case 'Y': fb.appendYear(4, 4); break; case 'z': fb.appendTimeZoneOffset(null, true, 2, 2); break; case 'Z': fb.appendTimeZoneName(); break; case '%': fb.appendLiteral('%'); break; default: fb.appendLiteral(ch); } } DateTimeFormatter dtf = fb.toFormatter().withLocale(Locale.getDefault()).withOffsetParsed(); org.joda.time.DateTime dt = new org.joda.time.DateTime(); String unparsed = ""; try { dt = dtf.parseDateTime(date); } catch (IllegalArgumentException e) { String delims = "[\"]+"; String[] splits = e.getMessage().split(delims); unparsed = unparsed.concat(splits[3]); } // According to manual strptime(3) if (dt.getCenturyOfEra() == 0) { if (dt.getYear() > 68) { dt = dt.withCenturyOfEra(19); } else { dt = dt.withCenturyOfEra(20); } } array.put("tm_sec", dt.getSecondOfMinute()); array.put("tm_min", dt.getMinuteOfHour()); array.put("tm_hour", dt.getHourOfDay()); array.put("tm_mday", dt.getDayOfMonth()); array.put("tm_mon", dt.getMonthOfYear() - 1); array.put("tm_year", dt.getYearOfCentury() + ((dt.getCenturyOfEra() - 19) * 100)); // Years since 1900 array.put("tm_wday", dt.getDayOfWeek() % 7); array.put("tm_yday", dt.getDayOfYear() - 1); array.put("unparsed", unparsed); return array; }
From source file:com.edoli.calendarlms.CalendarAdapter.java
License:Apache License
@SuppressWarnings("deprecation") @Override/*from w w w. java 2s . c o m*/ public View getView(int position, View convertView, ViewGroup parent) { Context context = parent.getContext(); RelativeLayout view = new RelativeLayout(context); DateTime date = mDate.plusDays(position); AbsListView.LayoutParams layoutParams = null; int gHeight = mGridView.getMeasuredHeight(); int cHeight = gHeight / 6; int gWidth = mGridView.getMeasuredWidth(); int cWidth = gWidth / 7; int row = position / 7; int column = position % 7; layoutParams = new AbsListView.LayoutParams(cWidth, cHeight); if (column == 6) { layoutParams.width = gWidth - cWidth * 6; } if (row == 5) { layoutParams.height = gHeight - cHeight * 5; } view.setLayoutParams(layoutParams); int day = date.getDayOfMonth(); TextView dayView = new TextView(context); RelativeLayout.LayoutParams dayParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); dayParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); dayParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); dayView.setLayoutParams(dayParams); dayView.setText(day + ""); dayView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); if (column == 0) { dayView.setTextColor(Color.RED); } // Set Background of cell int fillColor = 0; int strokeColor = 0; if (date.getMonthOfYear() != mMonth) { fillColor = Color.argb(51, 0, 0, 0); strokeColor = Color.GRAY; dayView.setTextColor(Color.GRAY); } else { fillColor = Color.argb(51, 238, 238, 230); strokeColor = Color.GRAY; } // Set different color or event cell if (mCalendarEvents != null) { for (CalendarEvent event : mCalendarEvents) { DateTime eventDate = event.getDate(); if (eventDate.getDayOfYear() == date.getDayOfYear()) { fillColor = Color.argb(51, 205, 92, 92); } } } ShapeDrawable drawable = new CellShapeDrawable(fillColor, strokeColor, row, column); view.setBackgroundDrawable(drawable); view.addView(dayView); return view; }
From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java
License:Apache License
/** * @return Day of year in GPS time (GMT time) *//*from www.j a v a2 s.c o m*/ public static int getCurrentDayOfYear() { DateTime current = DateTime.now(DateTimeZone.UTC); // Since current is derived from UTC time, we need to add leap second here. long gpsTimeMillis = current.getMillis() + getLeapSecond(current); DateTime gpsCurrent = new DateTime(gpsTimeMillis, UTC_ZONE); return gpsCurrent.getDayOfYear(); }
From source file:com.hmsinc.epicenter.webapp.chart.TimeSeriesChart.java
License:Open Source License
/** * @param period/*from w ww . ja v a 2 s . c om*/ * @param date * @return */ private static org.jfree.data.time.RegularTimePeriod getEntryPeriod(final TimeSeriesPeriod period, final DateTime date) { final org.jfree.data.time.RegularTimePeriod ret; switch (period) { case DAY: ret = new Day(date.getDayOfMonth(), date.getMonthOfYear(), date.getYear()); break; case HOUR: ret = new Hour(date.getHourOfDay(), date.getDayOfYear(), date.getMonthOfYear(), date.getYear()); break; case MONTH: ret = new Month(date.getMonthOfYear(), date.getYear()); break; case YEAR: ret = new Year(date.getYear()); break; default: throw new UnsupportedOperationException("Unsupported period: " + period); } return ret; }