List of usage examples for org.joda.time DateTime getMonthOfYear
public int getMonthOfYear()
From source file:com.aionemu.gameserver.services.QuestService.java
License:Open Source License
private static Timestamp countNextRepeatTime(Player player, QuestTemplate template) { DateTime now = DateTime.now(); DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 9, 0, 0); if (template.isDaily()) { if (now.isAfter(repeatDate)) { repeatDate = repeatDate.plusHours(24); }/*from w ww. j a va 2 s. c o m*/ PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400855, "9")); } else { int daysToAdd = 7; int startDay = 7; for (QuestRepeatCycle weekDay : template.getRepeatCycle()) { int diff = weekDay.getDay() - repeatDate.getDayOfWeek(); if (diff > 0 && diff < daysToAdd) { daysToAdd = diff; } if (startDay > weekDay.getDay()) { startDay = weekDay.getDay(); } } if (startDay == daysToAdd) { daysToAdd = 7; } else if (daysToAdd == 7 && startDay < 7) { daysToAdd = 7 - repeatDate.getDayOfWeek() + startDay; } repeatDate = repeatDate.plusDays(daysToAdd); PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400857, new DescriptionId(1800667), "9")); } return new Timestamp(repeatDate.getMillis()); }
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; }/*w w w . j a 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 ww w . j ava2 s . co 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.aliakseipilko.flightdutytracker.view.adapter.MonthBarChartAdapter.java
License:Open Source License
private void processDutyHours() { List<BarEntry> barDutyEntries = new ArrayList<>(); float xValueCount = 0f; long startMonth = new DateTime(flights.minDate("startDutyTime")).getMonthOfYear(); long currentYear = 0; long currentMonth = 0; 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; if (currentYear == 0 && currentMonth == 0) { currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barDutyEntries.add(newEntry); xValueCount++;//from ww w . j av a 2 s .com } else { if (currentMonth + 1 < 13) { //Add on any skipped months to xValueCount if (currentMonth + 1 != startDateTime.getMonthOfYear()) { xValueCount += (startDateTime.getMonthOfYear() - currentMonth) - 1; } } //Check if the month is the same as the previous flight // All flights are provided in an ordered list by the repo if (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.getYear() != currentYear) { } //New month //Update these for the next iteration currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barDutyEntries.add(newEntry); xValueCount++; } } } IAxisValueFormatter xAxisValueFormatter = new MonthAxisValueFormatter(((int) startMonth - 1)); 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.MonthBarChartAdapter.java
License:Open Source License
private void processFlightHours() { List<BarEntry> barFlightEntries = new ArrayList<>(); float xValueCount = 0f; long startMonth = new DateTime(flights.minDate("startFlightTime")).getMonthOfYear(); long currentYear = 0; long currentMonth = 0; 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; if (currentYear == 0 && currentMonth == 0) { currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barFlightEntries.add(newEntry); xValueCount++;/*from w ww . jav a 2s . c o m*/ } else { //Check if year wraps around if (currentMonth + 1 < 13) { //Add on any skipped months to xValueCount if (currentMonth + 1 != startDateTime.getMonthOfYear()) { xValueCount += (startDateTime.getMonthOfYear() - currentMonth) - 1; } } //Check if the month is the same as the previous flight // All flights are provided in an ordered list by the repo if (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.getYear() != currentYear) { } //New month //Update these for the next iteration currentYear = startDateTime.getYear(); currentMonth = startDateTime.getMonthOfYear(); //Add new entry using day of month as x value BarEntry newEntry = new BarEntry(xValueCount, decHoursDiff); barFlightEntries.add(newEntry); xValueCount++; } } } IAxisValueFormatter xAxisValueFormatter = new MonthAxisValueFormatter(((int) startMonth - 1)); IAxisValueFormatter yAxisValueFormatter = new DefaultAxisValueFormatter(2); BarDataSet dataSet = new BarDataSet(barFlightEntries, "Flight Hours"); dataSet.setValueTextSize(16f); BarData barDutyData = new BarData(dataSet); barDutyData.setBarWidth(0.9f); barDutyData.setHighlightEnabled(false); view.setupFlightBarChart(barDutyData, xAxisValueFormatter, yAxisValueFormatter); }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.mapping.ConfigurationToOslpSetConfigurationRequestConverter.java
License:Open Source License
private String convertSummerTimeWinterTimeDetails(final DateTime dateTime) { LOGGER.info("dateTime: {}", dateTime); final StringBuilder timeDetails = new StringBuilder(); timeDetails.append(String.format("%02d", dateTime.getMonthOfYear())); timeDetails.append(dateTime.getDayOfWeek() - 1); timeDetails.append(String.format("%02d", dateTime.getHourOfDay())); timeDetails.append(String.format("%02d", dateTime.getMinuteOfHour())); final String formattedTimeDetails = timeDetails.toString(); LOGGER.info("formattedTimeDetails: {}", formattedTimeDetails); return formattedTimeDetails; }
From source file:com.almende.eve.agent.MeetingAgent.java
License:Apache License
/** * Merge the busy intervals of all attendees, and the preferred intervals *///from w w w. j a v a2 s .c o m private void mergeTimeConstraints() { final ArrayList<Interval> infeasibleIntervals = new ArrayList<Interval>(); final ArrayList<Weight> preferredIntervals = new ArrayList<Weight>(); final Activity activity = getActivity(); if (activity != null) { // read and merge the stored busy intervals of all attendees for (final Attendee attendee : activity.withConstraints().withAttendees()) { final String agent = attendee.getAgent(); if (attendee.getResponseStatus() != RESPONSE_STATUS.declined) { if (new Boolean(true).equals(attendee.getOptional())) { // This attendee is optional. // Add its busy intervals to the soft constraints final List<Interval> attendeeBusy = getAgentBusy(agent); if (attendeeBusy != null) { for (final Interval i : attendeeBusy) { final Weight wi = new Weight(i.getStart(), i.getEnd(), WEIGHT_BUSY_OPTIONAL_ATTENDEE); preferredIntervals.add(wi); } } } else { // this attendee is required. // Add its busy intervals to the hard constraints final List<Interval> attendeeBusy = getAgentBusy(agent); if (attendeeBusy != null) { infeasibleIntervals.addAll(attendeeBusy); } } } // else This attendee declined. Ignore this attendees busy // interval } // read the time preferences and add them to the soft constraints final List<Preference> preferences = activity.withConstraints().withTime().withPreferences(); for (final Preference p : preferences) { if (p != null) { final Weight wi = new Weight(new DateTime(p.getStart()), new DateTime(p.getEnd()), p.getWeight()); preferredIntervals.add(wi); } } } // add office hours profile to the soft constraints // TODO: don't include (hardcoded) office hours here, should be handled // by a PersonalAgent final DateTime timeMin = DateTime.now(); final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS); final List<Interval> officeHours = IntervalsUtil.getOfficeHours(timeMin, timeMax); for (final Interval i : officeHours) { final Weight wi = new Weight(i, WEIGHT_OFFICE_HOURS); preferredIntervals.add(wi); } // add delay penalties to the soft constraints final DateTime now = DateTime.now(); final MutableDateTime d = new MutableDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0); for (int i = 0; i <= LOOK_AHEAD_DAYS; i++) { final DateTime start = d.toDateTime(); final DateTime end = start.plusDays(1); final Weight wi = new Weight(start, end, WEIGHT_DELAY_PER_DAY * i); preferredIntervals.add(wi); d.addDays(1); } // order and store the aggregated lists with intervals IntervalsUtil.order(infeasibleIntervals); getState().put("infeasible", infeasibleIntervals); WeightsUtil.order(preferredIntervals); getState().put("preferred", preferredIntervals); }
From source file:com.anrisoftware.sscontrol.dns.service.DnsServiceImpl.java
License:Open Source License
private int generateSerial(int serial) { DateTime date = new DateTime(); String string = format("%d%d%d%02d", date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), serial); return Integer.parseInt(string); }
From source file:com.barchart.feed.base.instrument.enums.MarketDisplay.java
License:BSD License
/** such as future January = "F" */ public static String timeMonthCode(/* local */TimeValue time) { time = filter(time);/*from w w w . j ava 2 s . co m*/ final DateTime date = new DateTime(time.asMillisUTC()); final int month = date.getMonthOfYear(); switch (month) { case 1: return "F"; case 2: return "G"; case 3: return "H"; case 4: return "J"; case 5: return "K"; case 6: return "M"; case 7: return "N"; case 8: return "Q"; case 9: return "U"; case 10: return "V"; case 11: return "X"; case 12: return "Z"; default: return "?"; } }
From source file:com.barchart.feed.base.provider.MarketDisplayBaseImpl.java
License:BSD License
@Override public String timeMonthCode(TimeValue time) { time = filter(time);/*from w w w .j ava 2 s . c o m*/ final DateTime date = new DateTime(time.asMillisUTC()); final int month = date.getMonthOfYear(); switch (month) { case 1: return "F"; case 2: return "G"; case 3: return "H"; case 4: return "J"; case 5: return "K"; case 6: return "M"; case 7: return "N"; case 8: return "Q"; case 9: return "U"; case 10: return "V"; case 11: return "X"; case 12: return "Z"; default: return "?"; } }