Example usage for org.joda.time MutableDateTime MutableDateTime

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

Introduction

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

Prototype

public MutableDateTime() 

Source Link

Document

Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:Bootstrap.java

License:Open Source License

public void doJob() {
    if (Play.mode == Play.Mode.DEV) {

        //BigTable.deleteAll();
        // BigTableR.deleteAll();
        ///*from   w  w w .  ja va 2s.com*/
        Invoice.deleteAll();
        Customer.deleteAll();
        Employee.deleteAll();
        User.deleteAll();

        Fixtures.load("test-datas.yml");

        int maxEntries = 2500;
        int maxEntriesR = 500;

        if (BigTable.count() == 0) {
            Logger.info("Creating " + maxEntries + " entries for testing");

            BigTable bigTable;
            // Create an enty in the past, so that AsyncBlotter can fetch the updated rows
            MutableDateTime aDate = new MutableDateTime();
            aDate.setMonthOfYear(1);
            aDate.setYear(2010);

            for (int i = 0; i < maxEntries; i++) {
                bigTable = new BigTable();
                bigTable.variable01 = Math.random() * 100;
                bigTable.variable02 = Math.random() * 100;
                bigTable.lastUpdated = aDate.toDate();
                if (i % 100 == 0) {
                    aDate.addDays(1);
                    Logger.info("Created " + i + " entries" + aDate.toString());
                }
                bigTable.save();
            }
        }
        if (BigTableR.count() == 0) {
            Logger.info("Creating " + maxEntriesR + " entries for BigTableR");

            BigTableR bigTableR;

            int j = 0;
            String locCurs = "Localisation #0";
            String segCurs = "Segment #0";
            String perCurs = "Period #0";

            for (int i = 0; i < maxEntriesR; i++) {
                bigTableR = new BigTableR();
                bigTableR.difference = Math.random();
                bigTableR.evolution = Math.random() * 10;
                bigTableR.localisation = locCurs;
                bigTableR.segment = segCurs;
                bigTableR.period = perCurs;
                bigTableR.indicator = new StringBuffer("Indicator #").append(i).toString();
                bigTableR.product = new Long(10 * i);
                if (i % 100 == 0) {
                    Logger.info("Created " + i + " entries");
                    locCurs = new StringBuffer("Localisation ").append(j).toString();
                    segCurs = new StringBuffer("Segment #").append(j).toString();
                    perCurs = new StringBuffer("Period #").append(j).toString();
                    j++;
                }
                bigTableR.save();
            }

        }
    }
}

From source file:com.soen.hasslefree.models.PhysicianAvailability.java

public boolean generateTimeSlots(DateTime startTime, DateTime endTime, int dropInDurationInMinutes) {
    MutableDateTime slotStatTime = new MutableDateTime();
    MutableDateTime slotEndTime = new MutableDateTime();

    long availabilityStartTimeInMillis = startTime.getMillis();
    long availabilityEndTimeInMillis = startTime.getMillis();

    long availableDuration = availabilityEndTimeInMillis - availabilityStartTimeInMillis;
    long slotDuration = dropInDurationInMinutes * 60 * 1000; // 20 min * 60 sec * 1000 millisecond
    ArrayList<RoomTimeSlot> roomSlots = RoomTimeSlot.getFilteredAvailableRoomSlotsForDate(startTime, endTime);

    if (availableDuration > 0) {

        long currentSlotStartTime = availabilityStartTimeInMillis;
        boolean stopSlicing = false;

        while (!stopSlicing) {
            //<editor-fold defaultstate="collapsed" desc="new PhysicianTimeSlot ">
            int roomSlotIndex = hasFoundFreeRoomSlot(currentSlotStartTime, roomSlots);
            if (roomSlotIndex < 0) {
                return false;
            } else {
                PhysicianTimeSlot newTimeSlot = new PhysicianTimeSlot();
                slotStatTime.setMillis(currentSlotStartTime);
                slotEndTime.setMillis(currentSlotStartTime + slotDuration);

                newTimeSlot.setStartTime(slotStatTime.toDateTime());
                newTimeSlot.setEndTime(slotEndTime.toDateTime());
                newTimeSlot.setIsAvailable(true);
                newTimeSlot.setPhysicianAvailability(this);
                newTimeSlot.setRelatedPhysician(this.relatedPhysician);
                RoomTimeSlot roomTime = roomSlots.get(roomSlotIndex);
                newTimeSlot.setRelatedRoomTimeSlot(roomTime);

                roomTime.setPhysicianTimeSlot(newTimeSlot);
                roomTime.setIsAvailable(false);

                //</editor-fold>
                this.physicianTimeSlots.add(newTimeSlot);
                availableDuration = availableDuration - slotDuration;
                currentSlotStartTime = currentSlotStartTime + slotDuration;
                if (availableDuration < slotDuration) { // I removed = because I want to add the last slot to the time slots.
                    stopSlicing = true;//from w  w w .j a  v  a 2s. c  om
                }
            }
        }

    }

    ObjectDao physicianAvailabilityDao = new ObjectDao();
    reserveRoomSlot(roomSlots);
    physicianAvailabilityDao.addOrUpdateObject(this);
    return true;
}

From source file:com.soen.hasslefree.models.Room.java

public void generateTimeSlots(DateTime clinicStartTime, DateTime clinicEndTime, int dropInDurationInMinutes) {
    MutableDateTime slotStatTime = new MutableDateTime();
    MutableDateTime slotEndTime = new MutableDateTime();

    //ArrayList<ClinicHours> clinicHoursList = ClinicHours.getAllClinicHours();
    // ClinicHours clinicHours = clinicHoursList.get(0);
    long availabilityStartTime = clinicStartTime.getMillis();
    long availabilityEndTime = clinicEndTime.getMillis();

    long availableDuration = availabilityEndTime - availabilityStartTime;
    long slotDuration = dropInDurationInMinutes * 60 * 1000; // dropIn Duration min * 60 sec * 1000 millisecond

    if (availableDuration > 0) {

        long currentSlotStartTime = availabilityStartTime;
        boolean stopSlicing = false;
        while (!stopSlicing) {
            //<editor-fold defaultstate="collapsed" desc="new RoomTimeSlot ">
            RoomTimeSlot newTimeSlot = new RoomTimeSlot();
            slotStatTime.setMillis(currentSlotStartTime);
            slotEndTime.setMillis(currentSlotStartTime + slotDuration);

            newTimeSlot.setStartTime(slotStatTime.toDateTime());
            newTimeSlot.setEndTime(slotEndTime.toDateTime());
            newTimeSlot.setIsAvailable(true);
            newTimeSlot.setRelatedRoom(this);

            //</editor-fold>
            this.roomTimeSlots.add(newTimeSlot);
            availableDuration = availableDuration - slotDuration;
            currentSlotStartTime = currentSlotStartTime + slotDuration;
            if (availableDuration < slotDuration) { // I ti should be smaller than only to add the last slot to the time slots.
                stopSlicing = true;//from   w w  w . j a va2  s . c  o  m
            }
        }

    }
}

From source file:com.xpn.xwiki.plugin.jodatime.JodaTimePlugin.java

License:Open Source License

/**
 * @see org.joda.time.MutableDateTime#MutableDateTime()
 */
public MutableDateTime getMutableDateTime() {
    return new MutableDateTime();
}

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

License:Open Source License

/**
 *
 * @param accountUuid/* w  w  w  .j  a va2s.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:org.apache.beam.sdk.io.gcp.spanner.MutationGroupEncoder.java

License:Apache License

private static int encodeDate(Date date) {

    MutableDateTime jodaDate = new MutableDateTime();
    jodaDate.setDate(date.getYear(), date.getMonth(), date.getDayOfMonth());

    return Days.daysBetween(MIN_DATE, jodaDate).getDays();
}

From source file:org.elasticsearch.index.field.data.longs.MultiValueLongFieldData.java

License:Apache License

@Override
public MutableDateTime[] dates(int docId) {
    int length = 0;
    for (int[] ordinal : ordinals) {
        if (ordinal[docId] != 0) {
            length++;//from w  w  w. ja  v a2  s.  c  o  m
        }
    }
    if (length == 0) {
        return EMPTY_DATETIME_ARRAY;
    }
    MutableDateTime[] dates;
    if (length < VALUE_CACHE_SIZE) {
        dates = dateTimesCache.get().get()[length];
    } else {
        dates = new MutableDateTime[length];
        for (int i = 0; i < dates.length; i++) {
            dates[i] = new MutableDateTime();
        }
    }
    int i = 0;
    for (int[] ordinal : ordinals) {
        int loc = ordinal[docId];
        if (loc != 0) {
            dates[i++].setMillis(values[loc]);
        }
    }
    return dates;
}

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);/*w w w  . j  a va2  s .  co m*/
    date.setMillisOfDay(0);
    date.setMonthOfYear(month);
    return date.toDateTime();
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJISOSetYear() {
    int COUNT = COUNT_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setYear");
        for (int j = 0; j < COUNT; j++) {
            dt.setYear(1972);//www .j a  va 2s . c om
            if (dt == null) {
                System.out.println("Anti optimise");
            }
        }
        end(COUNT);
    }
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJISOSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);/*from www  . ja va 2  s .co  m*/
            if (dt == null) {
                System.out.println("Anti optimise");
            }
        }
        end(COUNT);
    }
}