Example usage for org.joda.time MutableDateTime setDayOfMonth

List of usage examples for org.joda.time MutableDateTime setDayOfMonth

Introduction

In this page you can find the example usage for org.joda.time MutableDateTime setDayOfMonth.

Prototype

public void setDayOfMonth(final int dayOfMonth) 

Source Link

Document

Set the day of the month to the specified value.

Usage

From source file:ke.co.tawi.babblesms.server.session.SessionStatisticsFactory.java

License:Open Source License

/**
 *
 * @param accountUuid/*from w w  w  .  j  a v  a 2  s  .  c  o m*/
 * @return session statistics
 */
public static SessionStatistics getSessionStatistics(String accountUuid) {
    int count;
    //int[] arraycount = new int[2];

    SessionStatistics stats = new SessionStatistics();

    // Get the list of all networks
    List<Network> networkList = networkDAO.getAllNetworks();
    ;

    //set the count of all incoming SMS
    stats.setAllIncomingSMSCount(countUtils.getIncomingCount(accountUuid));

    //set the count of all outgoing SMS
    stats.setAllOutgoingSMSCount(countUtils.getOutgoingLog(accountUuid));

    //set the count of all outgoing Group SMS
    //stats.setAllOutgoingSMSCount(countUtils.getOutgoingGroupLog(accountUuid));

    // Set up data for the pie charts
    for (Network network : networkList) {
        //get the count of incoming SMS according to the account and network
        count = countUtils.getIncomingCount(accountUuid, network);

        //if count is greater than zero, add the information
        if (count > 0) {
            stats.addNetworkIncomingCount(network, count);
        }

        //get the count of outgoing SMS according to the account and network
        count = countUtils.getOutgoingCount(accountUuid, network);

        //if count is greater than zero, add the information
        if (count > 0) {
            stats.addNetworkOutgoingSMSCount(network, count);
        }
    }

    // Set up data for the bar charts
    DateTime dateMidnightStart = DateTime.now().minus(Hours.hours(24 * (IncomingBarDay.DAY_COUNT)));
    DateTime dateMidnightEnd = dateMidnightStart.plus(Hours.hours(24));
    int numDays = 0;
    do {
        for (Network network : networkList) {

            //get the daily count for incoming
            count = countUtils.getIncomingCount(accountUuid, network, new Date(dateMidnightStart.getMillis()),
                    new Date(dateMidnightEnd.getMillis()));
            if (count > 0) {
                stats.addNetworkIncomingUSSDCountDay(
                        new SimpleDateFormat("MMM d").format(new Date(dateMidnightStart.getMillis())), network,
                        count);
            }
            //get the daily count for outgoing
            count = countUtils.getOutgoingCount(accountUuid, network, new Date(dateMidnightStart.getMillis()),
                    new Date(dateMidnightEnd.getMillis()));

            if (count > 0) {
                stats.addNetworkOutgoingUSSDCountDay(
                        new SimpleDateFormat("MMM d").format(new Date(dateMidnightStart.getMillis())), network,
                        count);
            }

        }
        dateMidnightStart = dateMidnightStart.plus(Hours.hours(24));
        dateMidnightEnd = dateMidnightEnd.plus(Hours.hours(24));
        numDays++;
    } while (numDays < IncomingBarDay.DAY_COUNT);

    // Set up data for the Weekly bar charts                
    int numWeeks = 0;
    MutableDateTime startwkMutableDateTime = new MutableDateTime();
    MutableDateTime endwkMutableDateTime;
    startwkMutableDateTime.setDayOfWeek(1); //get the first day of the week
    startwkMutableDateTime.setMillisOfDay(0); //get 00:00:00 time of the day

    //go back to 7 weeks
    startwkMutableDateTime.addWeeks(-7);

    do {
        // set the end date by creating a copy
        endwkMutableDateTime = new MutableDateTime(startwkMutableDateTime);
        //push it by one week
        endwkMutableDateTime.addWeeks(1);

        for (Network network : networkList) {

            //get the Weekly count for Incoming USSD
            count = countUtils.getIncomingCount(accountUuid, network,
                    new Date(startwkMutableDateTime.toDate().getTime()),
                    new Date(endwkMutableDateTime.toDate().getTime()));

            if (count > 0) {
                stats.addNetworkIncomingUSSDCountWeek(
                        new SimpleDateFormat("MMM d").format(new Date(startwkMutableDateTime.getMillis())),
                        network, count);
            }

            //get the Weekly count for Outgoing USSD
            count = countUtils.getOutgoingCount(accountUuid, network,
                    new Date(startwkMutableDateTime.toDate().getTime()),
                    new Date(endwkMutableDateTime.toDate().getTime()));
            if (count > 0) {
                stats.addNetworkOutgoingUSSDCountWeek(
                        new SimpleDateFormat("MMM d").format(new Date(startwkMutableDateTime.getMillis())),
                        network, count);
            }

        }
        // get the next week
        startwkMutableDateTime.addWeeks(1);
        numWeeks++;
    } while (numWeeks < 7);

    // Set up data for the monthly bar charts               
    int numMonths = 0;
    MutableDateTime startMutableDateTime = new MutableDateTime();
    MutableDateTime endMutableDateTime;
    startMutableDateTime.setDayOfMonth(1); //get the first day of the month
    startMutableDateTime.setMillisOfDay(0); //get 00:00:00 time of the day

    //go back to 6 months
    startMutableDateTime.addMonths(-5);

    do {
        //set the end date by creating a copy
        endMutableDateTime = new MutableDateTime(startMutableDateTime);
        //push it by one month
        endMutableDateTime.addMonths(1);
        //System.out.println("Start date: " + startMutableDateTime);
        //System.out.println("End date: " + endMutableDateTime);

        for (Network network : networkList) {
            //change to use millis
            count = countUtils.getIncomingCount(accountUuid, network,
                    new Date(startMutableDateTime.toDate().getTime()),
                    new Date(endMutableDateTime.toDate().getTime()));

            if (count > 0) {
                stats.addNetworkIncomingUSSDCountMonth(
                        new SimpleDateFormat("MMM").format(new Date(startMutableDateTime.getMillis())), network,
                        count);
            }

            //System.out.println(count);                            
        }
        //get the next month
        startMutableDateTime.addMonths(1);
        numMonths++;
    } while (numMonths < 6);

    return stats;
}

From source file:org.calrissian.accumulorecipes.commons.support.TimeUnit.java

License:Apache License

public long normalize(long timestamp) {
    MutableDateTime ts = new MutableDateTime(timestamp, DateTimeZone.UTC);

    /**// w w  w.  j a v a  2 s . com
     * NOTE: order of switch matters.
     *
     * This switch is designed to fall through from most to least significant. Zeroes all non significant
     * portions of the time before finally breaking at the end.
     */
    switch (this) {
    case MONTHS:
        ts.setDayOfMonth(1);
    case DAYS:
        ts.setHourOfDay(0);
    case HOURS:
        ts.setMinuteOfHour(0);
    case MINUTES:
        ts.setSecondOfMinute(0);
        ts.setMillisOfSecond(0);
        break;
    default:
        throw new IllegalArgumentException("Unsupported time unit");
    }

    return ts.getMillis();
}

From source file:org.gdg.frisbee.android.eventseries.EventListFragment.java

License:Apache License

private DateTime getMonthStart(int month) {
    MutableDateTime date = new MutableDateTime();
    date.setDayOfMonth(1);
    date.setMillisOfDay(0);/*w w w . ja  v  a  2 s  .  co m*/
    date.setMonthOfYear(month);
    return date.toDateTime();
}

From source file:org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter.java

License:Open Source License

@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }//  www.  j  av  a  2s  . c o  m

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}

From source file:y.elf.DbReader.java

License:Open Source License

public static List<ElfValue> readOldCentralineFile(String filename, int defaultvalue, int fieldnn) {
    final String separatorDate = "/";
    final String separatorTime = ":";
    final int UNUSED = Integer.MIN_VALUE;

    List<ElfValue> list = new ArrayList<ElfValue>();

    BufferedReader reader = null;

    try {//from   w  w w .jav  a 2s  .  co m
        reader = new BufferedReader(new FileReader(filename));
        String line;
        MutableDateTime lasttime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0);
        final MutableDateTime invalidtime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0);

        while ((line = reader.readLine()) != null) {
            if (line.isEmpty())
                continue;

            try {
                boolean valid = true;
                final String[] parts = tokenize(line);
                int value = UNUSED;
                int maxvalue = 0;

                for (int i = 0; i < parts.length; i++) {
                    if (parts[i].equals("*"))
                        valid = false;
                    else if (parts[i].contains(separatorDate)) {
                        final String[] date = parts[i].split(separatorDate);

                        lasttime.setDayOfMonth(Integer.parseInt(date[0]));
                        lasttime.setMonthOfYear(Integer.parseInt(date[1]));
                        lasttime.setYear(Integer.parseInt(date[2]));
                    } else if (parts[i].contains(separatorTime)) {
                        final String[] hour = parts[i].split(separatorTime);
                        lasttime.setHourOfDay(Integer.parseInt(hour[0]));
                        lasttime.setMinuteOfHour(Integer.parseInt(hour[1]));
                    } else if (value == UNUSED)
                        value = translateValue(parts[i], defaultvalue);
                    else
                        maxvalue = translateValue(parts[i], defaultvalue);
                }

                if (lasttime.equals(invalidtime)) // invalid line (header)
                    continue;

                final DateTime currentdatetime = lasttime.toDateTime();

                if (value > 0) {
                    if (fieldnn == 2)
                        list.add(new ElfValue(currentdatetime, maxvalue, value, valid));
                    else
                        list.add(new ElfValue(currentdatetime, value, maxvalue, valid));
                } else
                    list.add(new ElfValue(currentdatetime, 0, 0, false));
            } catch (Exception e) {
                continue;
            } // on error, skip line
        }
    } catch (Exception e) {
        //         System.out.println(e.getMessage());
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {
            }
    }

    return list;
}