List of usage examples for org.joda.time DateTime weekOfWeekyear
public Property weekOfWeekyear()
From source file:com.addthis.hydra.job.backup.WeeklyBackup.java
License:Apache License
@Override public String getFormattedDateString(long timeMillis) { // For better handling of days at the end of the year. DateTime dt = new DateTime(timeMillis); if (dt.monthOfYear().get() == 12 && dt.weekOfWeekyear().get() < 3) { return dt.getYearOfCentury() + "53"; }/* w ww .j a v a 2s .c o m*/ return Integer.toString(dt.getYearOfCentury()) + String.format("%02d", dt.weekOfWeekyear().get()); }
From source file:com.certus.actions.getChartExpencesAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestString = request.getParameter("expenses"); //String requestString = "year"; DateTime today = new DateTime(); GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.registerTypeAdapter(ChartExpenses.class, new ChartExpenseAdapter()).create(); switch (requestString) { case "week": DateTime startOfWeek = today.weekOfWeekyear().roundFloorCopy(); DateTime endOfWeek = today.weekOfWeekyear().roundCeilingCopy(); Map<String, Double> mapWeekSale = new ReportsController().getSalesByWeek(startOfWeek.toDate(), endOfWeek.toDate());/* w w w. j a va2 s . c om*/ Map<String, Double> sortedMapWeekSale = new TreeMap<>(ReportsController.DAYS_OF_WEEK_COMPARATOR); sortedMapWeekSale.putAll(mapWeekSale); Map<String, Double> mapWeekExpense = new ReportsController().getExpenesByWeek(startOfWeek.toDate(), endOfWeek.toDate()); Map<String, Double> sortedMapWeekExpense = new TreeMap<>(ReportsController.DAYS_OF_WEEK_COMPARATOR); sortedMapWeekExpense.putAll(mapWeekExpense); if (mapWeekExpense.size() != mapWeekSale.size()) { try { throw new Exception("Invalid size exception"); } catch (Exception ex) { Logger.getLogger(getChartExpencesAction.class.getName()).log(Level.SEVERE, null, ex); } } Iterator itSale = mapWeekSale.entrySet().iterator(); Iterator itExp = mapWeekExpense.entrySet().iterator(); List<ChartExpenses> expList = new ArrayList<>(); while (itSale.hasNext() || itExp.hasNext()) { Map.Entry<String, Double> sale = null; Map.Entry<String, Double> exp = null; if (itSale.hasNext()) { sale = (Map.Entry<String, Double>) itSale.next(); } if (itExp.hasNext()) { exp = (Map.Entry<String, Double>) itExp.next(); } if (sale != null && exp != null) { if (sale.getKey().equals(exp.getKey())) { expList.add(new ChartExpenses(sale.getKey(), sale.getValue(), exp.getValue())); } } } expList.sort(new DaysComparator()); String elementWeek = gson.toJson(expList); response.setContentType("application/json"); response.getWriter().write(elementWeek); break; case "month": DateTime startOfMonth = today.monthOfYear().roundFloorCopy(); DateTime endOfMonth = today.monthOfYear().roundCeilingCopy(); Map<String, Double> mapMonthSale = new ReportsController().getSalesByMonth(startOfMonth.toDate(), endOfMonth.toDate()); Map<String, Double> sortedMapMonthSale = new TreeMap<>(ReportsController.DAYS_OF_MONTH_COMPARATOR); sortedMapMonthSale.putAll(mapMonthSale); Map<String, Double> mapMonthExp = new ReportsController().getExpenesByMonth(startOfMonth.toDate(), endOfMonth.toDate()); Map<String, Double> sortedMapMonthExp = new TreeMap<>(ReportsController.DAYS_OF_MONTH_COMPARATOR); sortedMapMonthExp.putAll(mapMonthExp); if (mapMonthSale.size() != mapMonthExp.size()) { try { throw new Exception("Invalid size exception"); } catch (Exception ex) { Logger.getLogger(getChartExpencesAction.class.getName()).log(Level.SEVERE, null, ex); } } Iterator itSaleMonth = mapMonthSale.entrySet().iterator(); Iterator itExpMonth = mapMonthExp.entrySet().iterator(); List<ChartExpenses> expMonthList = new ArrayList<>(); while (itSaleMonth.hasNext() || itExpMonth.hasNext()) { Map.Entry<String, Double> sale = null; Map.Entry<String, Double> exp = null; if (itSaleMonth.hasNext()) { sale = (Map.Entry<String, Double>) itSaleMonth.next(); } if (itExpMonth.hasNext()) { exp = (Map.Entry<String, Double>) itExpMonth.next(); } if (sale != null && exp != null) { if (sale.getKey().equals(exp.getKey())) { expMonthList.add(new ChartExpenses(sale.getKey(), sale.getValue(), exp.getValue())); } } } expMonthList.sort(new MonthDaysComparator()); String elementMonth = gson.toJson(expMonthList); response.setContentType("application/json"); response.getWriter().write(elementMonth); break; case "year": DateTime startOfYear = today.year().roundFloorCopy(); DateTime endOfYear = today.year().roundCeilingCopy(); Map<String, Double> mapYearSale = new ReportsController().getSalesByYear(startOfYear.toDate(), endOfYear.toDate()); Map<String, Double> sortedMapYear = new TreeMap<>(ReportsController.MONTH_OF_YEAR_COMPARATOR); sortedMapYear.putAll(mapYearSale); Map<String, Double> mapYearExp = new ReportsController().getExpenesByYear(startOfYear.toDate(), endOfYear.toDate()); Map<String, Double> sortedMapYearExp = new TreeMap<>(ReportsController.MONTH_OF_YEAR_COMPARATOR); sortedMapYearExp.putAll(mapYearExp); if (mapYearExp.size() != mapYearSale.size()) { try { throw new Exception("Invalid size exception"); } catch (Exception ex) { Logger.getLogger(getChartExpencesAction.class.getName()).log(Level.SEVERE, null, ex); } } Iterator itSaleYear = mapYearSale.entrySet().iterator(); Iterator itExpYear = mapYearExp.entrySet().iterator(); List<ChartExpenses> expYearList = new ArrayList<>(); while (itSaleYear.hasNext() || itExpYear.hasNext()) { Map.Entry<String, Double> sale = null; Map.Entry<String, Double> exp = null; if (itSaleYear.hasNext()) { sale = (Map.Entry<String, Double>) itSaleYear.next(); } if (itExpYear.hasNext()) { exp = (Map.Entry<String, Double>) itExpYear.next(); } if (sale != null && exp != null) { if (sale.getKey().equals(exp.getKey())) { expYearList.add(new ChartExpenses(sale.getKey(), sale.getValue(), exp.getValue())); } } } expYearList.sort(new YearMonthsComparator()); String elementYear = gson.toJson(expYearList); response.setContentType("application/json"); response.getWriter().write(elementYear); break; default: break; } }
From source file:com.certus.actions.getChartOrdersAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestString = request.getParameter("orders"); DateTime today = new DateTime(); GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.registerTypeAdapter(ChartsCriteria.class, new ChartsCriteriaAdapter()).create(); switch (requestString) { case "week": DateTime startOfWeek = today.weekOfWeekyear().roundFloorCopy(); DateTime endOfWeek = today.weekOfWeekyear().roundCeilingCopy(); Map<String, Double> mapWeek = new ReportsController().getOrdersByWeek(startOfWeek.toDate(), endOfWeek.toDate());//from w w w . j av a2 s.c o m Map<String, Double> sortedMapWeek = new TreeMap<>(ReportsController.DAYS_OF_WEEK_COMPARATOR); sortedMapWeek.putAll(mapWeek); List<ChartsCriteria> orderListWeek = new ArrayList<>(); for (Map.Entry<String, Double> m : sortedMapWeek.entrySet()) { orderListWeek.add(new ChartsCriteria(m.getKey(), m.getValue())); } String elementWeek = gson.toJson(orderListWeek); response.setContentType("application/json"); response.getWriter().write(elementWeek); break; case "month": DateTime startOfMonth = today.monthOfYear().roundFloorCopy(); DateTime endOfMonth = today.monthOfYear().roundCeilingCopy(); Map<String, Double> mapMonth = new ReportsController().getOrdersByMonth(startOfMonth.toDate(), endOfMonth.toDate()); Map<String, Double> sortedMapMonth = new TreeMap<>(ReportsController.DAYS_OF_MONTH_COMPARATOR); sortedMapMonth.putAll(mapMonth); List<ChartsCriteria> orderListMonth = new ArrayList<>(); for (Map.Entry<String, Double> m : sortedMapMonth.entrySet()) { orderListMonth.add(new ChartsCriteria(m.getKey(), m.getValue())); } String elementMonth = gson.toJson(orderListMonth); response.setContentType("application/json"); response.getWriter().write(elementMonth); break; case "year": DateTime startOfYear = today.year().roundFloorCopy(); DateTime endOfYear = today.year().roundCeilingCopy(); Map<String, Double> mapYear = new ReportsController().getOrdersByYear(startOfYear.toDate(), endOfYear.toDate()); Map<String, Double> sortedMapYear = new TreeMap<>(ReportsController.MONTH_OF_YEAR_COMPARATOR); sortedMapYear.putAll(mapYear); List<ChartsCriteria> orderListYear = new ArrayList<>(); for (Map.Entry<String, Double> m : sortedMapYear.entrySet()) { orderListYear.add(new ChartsCriteria(m.getKey(), m.getValue())); } String elementYear = gson.toJson(orderListYear); response.setContentType("application/json"); response.getWriter().write(elementYear); break; default: break; } }
From source file:com.certus.actions.getChartSalesAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestString = request.getParameter("sales"); DateTime today = new DateTime(); GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.registerTypeAdapter(ChartsCriteria.class, new ChartsCriteriaAdapter()).create(); switch (requestString) { case "week": DateTime startOfWeek = today.weekOfWeekyear().roundFloorCopy(); DateTime endOfWeek = today.weekOfWeekyear().roundCeilingCopy(); Map<String, Double> mapWeek = new ReportsController().getSalesByWeek(startOfWeek.toDate(), endOfWeek.toDate());// w w w. ja v a2s . com Map<String, Double> sortedMapWeek = new TreeMap<>(ReportsController.DAYS_OF_WEEK_COMPARATOR); sortedMapWeek.putAll(mapWeek); List<ChartsCriteria> saleListWeek = new ArrayList<>(); for (Map.Entry<String, Double> m : sortedMapWeek.entrySet()) { saleListWeek.add(new ChartsCriteria(m.getKey(), m.getValue())); } String elementWeek = gson.toJson(saleListWeek); response.setContentType("application/json"); response.getWriter().write(elementWeek); break; case "month": DateTime startOfMonth = today.monthOfYear().roundFloorCopy(); DateTime endOfMonth = today.monthOfYear().roundCeilingCopy(); Map<String, Double> mapMonth = new ReportsController().getSalesByMonth(startOfMonth.toDate(), endOfMonth.toDate()); Map<String, Double> sortedMapMonth = new TreeMap<>(ReportsController.DAYS_OF_MONTH_COMPARATOR); sortedMapMonth.putAll(mapMonth); List<ChartsCriteria> saleListMonth = new ArrayList<>(); for (Map.Entry<String, Double> m : sortedMapMonth.entrySet()) { saleListMonth.add(new ChartsCriteria(m.getKey(), m.getValue())); } String elementMonth = gson.toJson(saleListMonth); response.setContentType("application/json"); response.getWriter().write(elementMonth); break; case "year": DateTime startOfYear = today.year().roundFloorCopy(); DateTime endOfYear = today.year().roundCeilingCopy(); Map<String, Double> mapYear = new ReportsController().getSalesByYear(startOfYear.toDate(), endOfYear.toDate()); Map<String, Double> sortedMapYear = new TreeMap<>(ReportsController.MONTH_OF_YEAR_COMPARATOR); sortedMapYear.putAll(mapYear); List<ChartsCriteria> saleListYear = new ArrayList<>(); for (Map.Entry<String, Double> m : sortedMapYear.entrySet()) { saleListYear.add(new ChartsCriteria(m.getKey(), m.getValue())); } String elementYear = gson.toJson(saleListYear); response.setContentType("application/json"); response.getWriter().write(elementYear); break; default: break; } }
From source file:com.sap.dirigible.runtime.metrics.TimeUtils.java
License:Open Source License
private static DateTime dateTimeCeiling(DateTime dt, Period p) { if (p.getYears() != 0) { return dt.yearOfEra().roundCeilingCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundCeilingCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundCeilingCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundCeilingCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundCeilingCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundCeilingCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundCeilingCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*from ww w . ja v a 2 s . c o m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:com.squarespace.template.plugins.PluginDateUtils.java
License:Apache License
/** * Takes a strftime()-compatible format string and outputs the properly formatted date. *///from w ww. j ava 2s. co m public static void formatDate(Locale locale, String fmt, long instant, String tzName, StringBuilder buf) { DateTimeZone zone = null; try { zone = DateTimeZone.forID(tzName); } catch (IllegalArgumentException e) { zone = DateTimeZone.getDefault(); } DateTime date = new DateTime(instant, zone); int index = 0; int len = fmt.length(); while (index < len) { char c1 = fmt.charAt(index); index++; if (c1 != '%' || index == len) { buf.append(c1); continue; } char c2 = fmt.charAt(index); switch (c2) { case 'A': buf.append(date.dayOfWeek().getAsText(locale)); break; case 'a': buf.append(date.dayOfWeek().getAsShortText(locale)); break; case 'B': buf.append(date.monthOfYear().getAsText(locale)); break; case 'b': buf.append(date.monthOfYear().getAsShortText(locale)); break; case 'C': leftPad(date.centuryOfEra().get(), '0', 2, buf); break; case 'c': formatAggregate(DateTimeAggregate.FULL, locale, date, buf); break; case 'D': formatAggregate(DateTimeAggregate.MMDDYY, locale, date, buf); break; case 'd': leftPad(date.dayOfMonth().get(), '0', 2, buf); break; case 'e': leftPad(date.dayOfMonth().get(), ' ', 2, buf); break; case 'F': formatAggregate(DateTimeAggregate.YYYYMMDD, locale, date, buf); break; case 'G': buf.append(date.year().get()); break; case 'g': leftPad(date.yearOfCentury().get(), '0', 2, buf); break; case 'H': leftPad(date.hourOfDay().get(), '0', 2, buf); break; case 'h': buf.append(date.monthOfYear().getAsShortText(locale)); break; case 'I': leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf); break; case 'j': leftPad(date.dayOfYear().get(), '0', 3, buf); break; case 'k': leftPad(date.get(DateTimeFieldType.clockhourOfDay()), ' ', 2, buf); break; case 'l': leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), ' ', 2, buf); break; case 'M': leftPad(date.minuteOfHour().get(), '0', 2, buf); break; case 'm': leftPad(date.monthOfYear().get(), '0', 2, buf); break; case 'n': buf.append('\n'); break; case 'P': buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "am" : "pm"); break; case 'p': buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM"); break; case 'R': formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf); break; case 'S': leftPad(date.secondOfMinute().get(), '0', 2, buf); break; case 's': buf.append(instant / 1000); break; case 't': buf.append('\t'); break; case 'T': // Equivalent of %H:%M:%S formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf); buf.append(':'); leftPad(date.secondOfMinute().get(), '0', 2, buf); break; case 'U': // TODO: fix week-of-year number leftPad(date.weekOfWeekyear().get(), '0', 2, buf); break; case 'u': buf.append(date.dayOfWeek().get()); break; case 'V': // TODO: fix week-of-year number leftPad(date.weekOfWeekyear().get(), '0', 2, buf); break; case 'v': // Equivalent of %e-%b-%Y leftPad(date.dayOfMonth().get(), ' ', 2, buf); buf.append('-'); buf.append(date.monthOfYear().getAsShortText()); buf.append('-'); buf.append(date.getYear()); break; case 'W': // TODO: fix week-of-year number break; case 'w': buf.append(date.dayOfWeek().get()); break; case 'X': formatAggregate(DateTimeAggregate.HHMMSSP, locale, date, buf); break; case 'x': formatAggregate(DateTimeAggregate.MMDDYYYY, locale, date, buf); break; case 'Y': buf.append(date.getYear()); break; case 'y': leftPad(date.getYearOfCentury(), '0', 2, buf); break; case 'Z': // Note: Joda's nameKey happens to be the same as the shortName. Making // this change to workaround Joda https://github.com/JodaOrg/joda-time/issues/288 buf.append(zone.getNameKey(date.getMillis())); break; case 'z': int offset = date.getZone().getOffset(instant) / 60000; int hours = (int) Math.floor(offset / 60); int minutes = (hours * 60) - offset; if (offset < 0) { buf.append('-'); } leftPad(Math.abs(hours), '0', 2, buf); leftPad(Math.abs(minutes), '0', 2, buf); break; default: // no match, emit literals. buf.append(c1).append(c2); } index++; } }
From source file:com.thinkbiganalytics.ingest.GetTableDataSupport.java
License:Apache License
protected static Date maxAllowableDateFromUnit(Date fromDate, UnitSizes unit) { DateTime jodaDate = new DateTime(fromDate); switch (unit) { case HOUR:/*from www . ja v a 2 s.c o m*/ return jodaDate.hourOfDay().roundFloorCopy().toDate(); case DAY: return jodaDate.withHourOfDay(0).hourOfDay().roundFloorCopy().toDate(); case WEEK: return jodaDate.weekOfWeekyear().roundFloorCopy().toDate(); case MONTH: return jodaDate.monthOfYear().roundFloorCopy().toDate(); case YEAR: return jodaDate.withMonthOfYear(1).withDayOfMonth(1).withHourOfDay(0).hourOfDay().roundFloorCopy() .toDate(); } return fromDate; }
From source file:edu.nyu.vida.data_polygamy.utils.FrameworkUtils.java
License:BSD License
public static String getTemporalStr(int temporalResolution, int time) { DateTime dt = new DateTime(((long) time) * 1000, DateTimeZone.UTC); String temporal = ""; switch (temporalResolution) { case HOUR:/*from w ww . j av a 2 s . c om*/ temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString() + "-" + dt.dayOfMonth().getAsString() + "-" + dt.hourOfDay().getAsString(); break; case DAY: temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString() + "-" + dt.dayOfMonth().getAsString(); break; case WEEK: temporal = dt.weekyear().getAsString() + "-" + dt.weekOfWeekyear().getAsString(); break; case MONTH: temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString(); break; case YEAR: temporal = dt.year().getAsString(); break; default: temporal = null; break; } return temporal; }
From source file:edu.nyu.vida.data_polygamy.utils.FrameworkUtils.java
License:BSD License
public static String getTemporalStr(int temporalResolution, DateTime dt) { String temporal = ""; switch (temporalResolution) { case HOUR:/* w ww . j a v a 2s.co m*/ temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString() + "-" + dt.dayOfMonth().getAsString() + "-" + dt.hourOfDay().getAsString(); break; case DAY: temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString() + "-" + dt.dayOfMonth().getAsString(); break; case WEEK: temporal = dt.weekyear().getAsString() + "-" + dt.weekOfWeekyear().getAsString(); break; case MONTH: temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString(); break; case YEAR: temporal = dt.year().getAsString(); break; default: temporal = null; break; } return temporal; }
From source file:edu.nyu.vida.data_polygamy.utils.FrameworkUtils.java
License:BSD License
public static int getTime(int temporalResolution, String[] input, int tempPosition) { String temporal = ""; String format = ""; long time = 0L; try {// w w w. j a v a 2 s. c o m time = ((long) Double.parseDouble(input[tempPosition])) * 1000; } catch (Exception e) { return -1; } if (time < 0) return -1; DateTime dt = new DateTime(time, DateTimeZone.UTC); switch (temporalResolution) { case HOUR: temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString() + "-" + dt.dayOfMonth().getAsString() + "-" + dt.hourOfDay().getAsString(); format = "yyyy-MM-dd-HH z"; break; case DAY: temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString() + "-" + dt.dayOfMonth().getAsString(); format = "yyyy-MM-dd z"; break; case WEEK: temporal = dt.weekyear().getAsString() + "-" + dt.weekOfWeekyear().getAsString(); format = "xxxx-ww z"; break; case MONTH: temporal = dt.year().getAsString() + "-" + dt.monthOfYear().getAsString(); format = "yyyy-MM z"; break; case YEAR: temporal = dt.year().getAsString(); format = "yyyy z"; break; default: temporal = null; format = ""; break; } if (temporal == null) return -1; DateTimeFormatter formatter = DateTimeFormat.forPattern(format); return (int) (formatter.parseDateTime(temporal + " UTC").getMillis() / 1000); }