Example usage for org.joda.time DateTime monthOfYear

List of usage examples for org.joda.time DateTime monthOfYear

Introduction

In this page you can find the example usage for org.joda.time DateTime monthOfYear.

Prototype

public Property monthOfYear() 

Source Link

Document

Get the month of year property which provides access to advanced functionality.

Usage

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";
    }/*from w  ww .j a v a  2 s . co m*/
    return Integer.toString(dt.getYearOfCentury()) + String.format("%02d", dt.weekOfWeekyear().get());
}

From source file:com.addthis.hydra.task.source.AbstractPersistentStreamSource.java

License:Apache License

/** */
private String replaceDateElements(DateTime time, String template) {
    template = template.replace("{YY}", time.year().getAsString());
    template = template.replace("{Y}", getTwoDigit(time.year().get()));
    template = template.replace("{M}", getTwoDigit(time.monthOfYear().get()));
    template = template.replace("{D}", getTwoDigit(time.dayOfMonth().get()));
    template = template.replace("{H}", getTwoDigit(time.hourOfDay().get()));
    if (log.isDebugEnabled()) {
        log.debug("template=" + template);
    }/*from   w w w  .ja v  a  2 s  . c  o m*/
    return template;
}

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());/*from  w w  w .  j  a  va  2  s . co m*/
        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  .jav a2  s.c om
        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());//from  w ww .  j av a  2s  . 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.chiorichan.plugin.lua.api.OSAPI.java

License:Mozilla Public License

@Override
void initialize() {
    // Push a couple of functions that override original Lua API functions or
    // that add new functionality to it.
    lua.getGlobal("os");

    // Custom os.clock() implementation returning the time the computer has
    // been actively running, instead of the native library...
    lua.pushJavaFunction(new JavaFunction() {
        @Override// w  w  w .  j av a2  s . c om
        public int invoke(LuaState lua) {
            lua.pushNumber(System.currentTimeMillis());
            return 1;
        }
    });
    lua.setField(-2, "clock");

    lua.pushJavaFunction(new JavaFunction() {
        @Override
        public int invoke(LuaState lua) {
            String format = lua.getTop() > 0 && lua.isString(1) ? lua.toString(1) : "%d/%m/%y %H:%M:%S";
            long time = (long) (lua.getTop() > 1 && lua.isNumber(2) ? lua.toNumber(2) * 1000 / 60 / 60
                    : System.currentTimeMillis());
            DateTime dt = new DateTime(time);
            if (format == "*t") {
                lua.newTable(0, 8);
                lua.pushInteger(dt.year().get());
                lua.setField(-2, "year");
                lua.pushInteger(dt.monthOfYear().get());
                lua.setField(-2, "month");
                lua.pushInteger(dt.dayOfMonth().get());
                lua.setField(-2, "day");
                lua.pushInteger(dt.hourOfDay().get());
                lua.setField(-2, "hour");
                lua.pushInteger(dt.minuteOfHour().get());
                lua.setField(-2, "min");
                lua.pushInteger(dt.secondOfMinute().get());
                lua.setField(-2, "sec");
                lua.pushInteger(dt.dayOfWeek().get());
                lua.setField(-2, "wday");
                lua.pushInteger(dt.dayOfYear().get());
                lua.setField(-2, "yday");
            } else
                lua.pushString(dt.toString(DateTimeFormat.forPattern(format)));
            return 1;
        }
    });
    lua.setField(-2, "date");

    /*
     * // Date formatting function.
     * lua.pushScalaFunction(lua => {
     * val format =
     * if (lua.getTop > 0 && lua.isString(1)) lua.toString(1)
     * else "%d/%m/%y %H:%M:%S"
     * val time =
     * if (lua.getTop > 1 && lua.isNumber(2)) lua.toNumber(2) * 1000 / 60 / 60
     * else machine.worldTime + 5000
     * 
     * val dt = GameTimeFormatter.parse(time)
     * def fmt(format: String) {
     * if (format == "*t") {
     * lua.newTable(0, 8)
     * lua.pushInteger(dt.year)
     * lua.setField(-2, "year")
     * lua.pushInteger(dt.month)
     * lua.setField(-2, "month")
     * lua.pushInteger(dt.day)
     * lua.setField(-2, "day")
     * lua.pushInteger(dt.hour)
     * lua.setField(-2, "hour")
     * lua.pushInteger(dt.minute)
     * lua.setField(-2, "min")
     * lua.pushInteger(dt.second)
     * lua.setField(-2, "sec")
     * lua.pushInteger(dt.weekDay)
     * lua.setField(-2, "wday")
     * lua.pushInteger(dt.yearDay)
     * lua.setField(-2, "yday")
     * }
     * else {
     * lua.pushString(GameTimeFormatter.format(format, dt))
     * }
     * }
     * 
     * // Just ignore the allowed leading '!', Minecraft has no time zones...
     * if (format.startsWith("!"))
     * fmt(format.substring(1))
     * else
     * fmt(format)
     * 1
     * })
     * lua.setField(-2, "date")
     * 
     * // Return ingame time for os.time().
     * lua.pushScalaFunction(lua => {
     * if (lua.isNoneOrNil(1)) {
     * // Game time is in ticks, so that each day has 24000 ticks, meaning
     * // one hour is game time divided by one thousand. Also, Minecraft
     * // starts days at 6 o'clock, versus the 1 o'clock of timestamps so we
     * // add those five hours. Thus:
     * // timestamp = (time + 5000) * 60[kh] * 60[km] / 1000[s]
     * lua.pushNumber((machine.worldTime + 5000) * 60 * 60 / 1000)
     * }
     * else {
     * def getField(key: String, d: Int) = {
     * lua.getField(-1, key)
     * val res = lua.toIntegerX(-1)
     * lua.pop(1)
     * if (res == null)
     * if (d < 0) throw new Exception("field '" + key + "' missing in date table")
     * else d
     * else res: Int
     * }
     * 
     * lua.checkType(1, LuaType.TABLE)
     * lua.setTop(1)
     * 
     * val sec = getField("sec", 0)
     * val min = getField("min", 0)
     * val hour = getField("hour", 12)
     * val mday = getField("day", -1)
     * val mon = getField("month", -1)
     * val year = getField("year", -1)
     * 
     * GameTimeFormatter.mktime(year, mon, mday, hour, min, sec) match {
     * case Some(time) => lua.pushNumber(time)
     * case _ => lua.pushNil()
     * }
     * }
     * 1
     * })
     * lua.setField(-2, "time")
     */
    // Pop the os table.
    lua.pop(1);
}

From source file:com.example.android.sunshine.wear.Utility.java

License:Apache License

static public String getDayMonthDateYear(Context context, DateTime dateTime) {
    String dayName = dateTime.dayOfWeek().getAsText();
    String monthName = dateTime.monthOfYear().getAsText();
    int date = dateTime.getDayOfMonth();
    int year = dateTime.getYear();
    dayName = dayName.substring(0, 2);/*from  w w w  .  j a va2  s  . co  m*/
    return context.getString(R.string.datetime_display_1, dayName, monthName, date, year);

}

From source file:com.excilys.ebi.bank.web.tld.Functions.java

License:Apache License

public static int monthOfYear(DateTime dateTime) {
    return dateTime.monthOfYear().get();
}

From source file:com.excilys.ebi.bank.web.tld.Functions.java

License:Apache License

public static String monthOfYearAsText(DateTime dateTime) {
    return dateTime.monthOfYear().getAsText();
}

From source file:com.huang.rp.blog.access.service.AccessService.java

License:Apache License

/**
 * ?//from   w  ww .  j  av a 2s .c  om
 * @return
 */
public Map<String, Map<String, List<BlogPostsWithBLOBs>>> getTimelineList(HttpServletRequest request,
        AccessFilter filter) {
    if (filter == null)
        filter = new AccessFilter();
    filter.setRows(Integer.MAX_VALUE - 1);
    filter.setSord("desc");
    filter.setSidx("id");
    CookieVO cookieVO = parseCookie(request);
    filter.setSearchStr(cookieVO.getSearch());
    filter.setTagId(cookieVO.getTag());
    filter.setUserId(cookieVO.getUserId());
    filter.setHighLight(true);
    List<BlogPostsWithBLOBs> excerptList = getArticleExcerptListByFilter(request, filter);
    Map<String, Map<String, List<BlogPostsWithBLOBs>>> timeline = Maps.newLinkedHashMap();
    for (BlogPostsWithBLOBs spost : excerptList) {
        Date postDate = spost.getPostDate();
        DateTime dt = new DateTime(postDate.getTime());
        String yearMonthKey = dt.monthOfYear().getAsText(Locale.ENGLISH) + "," + dt.getYearOfEra();////key May,2015?
        Map<String, List<BlogPostsWithBLOBs>> yearMonthPostMap = timeline.get(yearMonthKey);
        if (yearMonthPostMap == null) {
            yearMonthPostMap = Maps.newLinkedHashMap();
            timeline.put(yearMonthKey, yearMonthPostMap);
        }
        String dayKey = "Day" + dt.getDayOfMonth();
        List<BlogPostsWithBLOBs> dayPostList = yearMonthPostMap.get(dayKey);
        if (dayPostList == null) {
            dayPostList = Lists.newArrayList();
            yearMonthPostMap.put(dayKey, dayPostList);
        }
        dayPostList.add(spost);

    }
    return timeline;
}