Example usage for org.joda.time MutableDateTime setDayOfWeek

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

Introduction

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

Prototype

public void setDayOfWeek(final int dayOfWeek) 

Source Link

Document

Set the day of week to the specified value.

Usage

From source file:com.carmatech.cassandra.ShardingFrequency.java

License:Apache License

public static long calculateBucket(final long timestamp, final ShardingFrequency frequency) {
    final MutableDateTime dateTime = new MutableDateTime(timestamp);

    if (frequency.compareTo(SECONDLY) >= 0)
        dateTime.setMillisOfSecond(0);//from w w  w .ja va  2  s  . c  om
    if (frequency.compareTo(MINUTELY) >= 0)
        dateTime.setSecondOfMinute(0);
    if (frequency.compareTo(HOURLY) >= 0)
        dateTime.setMinuteOfHour(0);
    if (frequency.compareTo(DAILY) >= 0)
        dateTime.setHourOfDay(0);
    if (frequency.compareTo(WEEKLY) >= 0)
        dateTime.setDayOfWeek(1);
    if (frequency.compareTo(MONTHLY) >= 0)
        dateTime.setDayOfMonth(1);

    return dateTime.getMillis();
}

From source file:com.ning.metrics.serialization.util.DateTimeUtil.java

License:Apache License

public DateTime truncateToWeek(ReadableDateTime time) {
    MutableDateTime result = new MutableDateTime(time);
    result.setMillisOfSecond(0);/*w ww .  j  a  va 2  s. c om*/
    result.setSecondOfMinute(0);
    result.setMinuteOfHour(0);
    result.setHourOfDay(0);
    result.setHourOfDay(0);

    if (time.getDayOfWeek() != 7) {
        result.setDayOfWeek(1);
        result.add(Days.ONE.multipliedBy(-1));
    }

    return new DateTime(result);
}

From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java

License:Open Source License

private static MutableDateTime toWeekStart(MutableDateTime mdt) {
    mdt.setDayOfWeek(mdt.dayOfWeek().getMinimumValue());
    return toDayStart(mdt);
}

From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java

License:Open Source License

private static MutableDateTime toWeekEnd(MutableDateTime mdt) {
    mdt.setDayOfWeek(mdt.dayOfWeek().getMaximumValue());
    return toDayEnd(mdt);
}

From source file:com.yahoo.bard.webservice.sql.helper.SqlTimeConverter.java

License:Apache License

/**
 * Sets the correct part of a {@link DateTime} corresponding to a
 * {@link SqlDatePartFunction}./*  ww  w. j  a v a2 s .co m*/
 *
 * @param value  The value to be set for the dateTime with the sqlDatePartFn
 * @param sqlDatePartFn  The function used to extract part of a date with sql.
 * @param dateTime  The original dateTime to create a copy of.
 */
protected void setDateTime(int value, SqlDatePartFunction sqlDatePartFn, MutableDateTime dateTime) {
    if (YEAR.equals(sqlDatePartFn)) {
        dateTime.setYear(value);
    } else if (MONTH.equals(sqlDatePartFn)) {
        dateTime.setMonthOfYear(value);
    } else if (WEEK.equals(sqlDatePartFn)) {
        dateTime.setWeekOfWeekyear(value);
        dateTime.setDayOfWeek(1);
    } else if (DAYOFYEAR.equals(sqlDatePartFn)) {
        dateTime.setDayOfYear(value);
    } else if (HOUR.equals(sqlDatePartFn)) {
        dateTime.setHourOfDay(value);
    } else if (MINUTE.equals(sqlDatePartFn)) {
        dateTime.setMinuteOfHour(value);
    } else if (SECOND.equals(sqlDatePartFn)) {
        dateTime.setSecondOfMinute(value);
    } else {
        throw new IllegalArgumentException("Can't set value " + value + " for " + sqlDatePartFn);
    }
}

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

License:Open Source License

/**
 *
 * @param accountUuid//from   w w w .jav a 2 s  .co  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:rapture.kernel.ScheduleApiImpl.java

License:Open Source License

@Override
public List<TimedEventRecord> getCurrentWeekTimeRecords(CallingContext context, int weekOffsetfromNow) {
    // Based on today, get current events
    MutableDateTime now = new MutableDateTime();
    now.setDayOfWeek(1);
    return RangedEventGenerator.generateWeeklyEvents(now.toDateTime());
}

From source file:se.toxbee.sleepfighter.text.DateTextUtils.java

License:Open Source License

/**
 * Returns an array of strings with weekday names.
 *
 * @param indiceLength how long each string should be.
 * @param locale the desired locale.//  w  ww . j a  va2 s.c  om
 * @return the array of strings.
 */
public static final String[] getWeekdayNames(int indiceLength, Locale locale) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern(Strings.repeat("E", indiceLength)).withLocale(locale);

    MutableDateTime time = new MutableDateTime();
    time.setDayOfWeek(DateTimeConstants.MONDAY);

    String[] names = new String[DateTimeConstants.DAYS_PER_WEEK];

    for (int day = 0; day < DateTimeConstants.DAYS_PER_WEEK; day++) {
        String name = fmt.print(time);

        if (name.length() > indiceLength) {
            name = name.substring(0, indiceLength);
        }

        names[day] = name;

        time.addDays(1);
    }

    return names;
}