Example usage for org.joda.time DateTime dayOfWeek

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

Introduction

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

Prototype

public Property dayOfWeek() 

Source Link

Document

Get the day of week property which provides access to advanced functionality.

Usage

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.google.android.apps.paco.EsmGenerator2.java

License:Open Source License

private DateTime adjustStartDateToBeginningOfPeriod(DateTime startDate) {
    switch (schedule.getEsmPeriodInDays()) {
    case SignalSchedule.ESM_PERIOD_DAY:
        return startDate;
    case SignalSchedule.ESM_PERIOD_WEEK:
        return startDate.dayOfWeek().withMinimumValue();
    case SignalSchedule.ESM_PERIOD_MONTH:
        return startDate.dayOfMonth().withMinimumValue();
    default://  w ww .  java 2s  .  co  m
        throw new IllegalStateException("Cannot get here.");
    }
}

From source file:com.google.android.apps.paco.Experiment.java

License:Open Source License

@JsonIgnore
DateMidnight getPeriodStart(DateTime now) {
    switch (((SignalSchedule) getSignalingMechanisms().get(0)).getEsmPeriodInDays()) {
    case SignalSchedule.ESM_PERIOD_DAY:
        return now.toDateMidnight();
    case SignalSchedule.ESM_PERIOD_WEEK:
        return now.dayOfWeek().withMinimumValue().toDateMidnight();
    case SignalSchedule.ESM_PERIOD_MONTH:
        return now.dayOfMonth().withMinimumValue().toDateMidnight();
    default://from w ww  .  j a  va2s . co  m
        throw new IllegalStateException("Cannot get here.");
    }
}

From source file:com.google.sampling.experiential.server.DSQueryBuilder.java

License:Open Source License

private static DateTime getMondayAfterWeekEnclosing(DateTime today) {
    return today.dayOfWeek().setCopy(DateTimeConstants.SUNDAY).plusDays(1);
}

From source file:com.google.sampling.experiential.server.DSQueryBuilder.java

License:Open Source License

private static DateTime getMondayOfWeekEnclosing(DateTime today) {
    return today.dayOfWeek().setCopy(DateTimeConstants.MONDAY);
}

From source file:com.josecalles.tistiq.task.StatCalculator.java

License:Apache License

public String getWhatDayMostMessagesSent(RealmList<TextMessage> messages) {
    ArrayList<String> dateTimestamps = new ArrayList<>();
    for (TextMessage message : messages) {
        DateTime time = new DateTime(message.getDateReceived());
        String dayOfWeek = time.dayOfWeek().getAsText(Locale.ENGLISH);
        dateTimestamps.add(dayOfWeek);/*from w w  w .j a  v  a2 s .c  o  m*/
    }

    HashMap<String, Integer> daysWithCount = new HashMap<>();
    for (int i = 0; i < dateTimestamps.size(); i++) {
        if (daysWithCount.containsKey(dateTimestamps.get(i))) {
            daysWithCount.put(dateTimestamps.get(i), (daysWithCount.get(dateTimestamps.get(i)) + 1));
        } else {
            daysWithCount.put(dateTimestamps.get(i), 1);
        }
    }
    String dayOnWhich = sortValues(daysWithCount, 1, false).get(0);

    return dayOnWhich + "s";
}

From source file:com.mgl.updater.Updater2.java

public void process() {

    List<NewContract> nContractList = XHelper.getInstance().fromFileNameToNCList(CONTRACT_FILE);
    ControllerFactory controllerFactory = new ControllerFactory();
    ContractHelper contractHelper = new ContractHelper();

    TextPaneLogger logger = new TextPaneLogger(progressBarListener);

    try (ConnectionHandler cHandler = new ConnectionHandler(logger)) {
        cHandler.connect();/*ww w  .  j a v  a  2s. c o  m*/
        progressBarListener.propertyChange(new PropertyChangeEvent(this, "UpdaterLog", null,
                nContractList.size() + " Contracts to be processed."));

        int counter = 0;
        for (NewContract nc : nContractList) {

            ContractEntity contractEntity = controllerFactory.getContractJpaController()
                    .findContract(nc.symbol());
            if (contractEntity == null) {
                contractEntity = new ContractEntity(nc.symbol(), nc.exchange(), nc.currency());
                controllerFactory.getContractJpaController().create(contractEntity);
            }

            BarEntity latestBar = contractHelper.getLatestBar(contractEntity,
                    controllerFactory.getBarJpaController());
            SimpleDateFormat sdf = new SimpleDateFormat(YMD); // move this 2 lines
            String endDateTime = sdf.format(new DateTime().toDate());

            counter++;
            HistoricalDataLoaderWorker handler = null;
            if (latestBar == null) {
                progressBarListener.propertyChange(
                        new PropertyChangeEvent(this, "UpdaterLog", null, "Processing all " + counter + " of "
                                + nContractList.size() + " Contract: " + contractEntity.getSymbol()));
                handler = new HistoricalDataLoaderWorker(nc, contractEntity, cHandler.getController(),
                        endDateTime, 5, Types.DurationUnit.YEAR, controllerFactory.getBarJpaController(),
                        logger);
            } else {
                DateTime endDate = new DateTime();
                DateTime startDate = new DateTime(latestBar.getDate().getTime());

                int days = 0;
                DateTime nextDay = startDate.plusDays(1);
                while (nextDay.isBefore(endDate)) {
                    DateTime.Property p = nextDay.dayOfWeek();
                    if (p.get() < 6) {
                        days++;
                    }
                    nextDay = nextDay.plusDays(1);
                }

                if (days > 1) { // TODO if after market close it can be 0.
                    progressBarListener.propertyChange(new PropertyChangeEvent(this, "UpdaterLog", null,
                            "Processing " + counter + " of " + nContractList.size() + " Contract: "
                                    + contractEntity.getSymbol() + " days: " + days));
                    handler = new HistoricalDataLoaderWorker(nc, contractEntity, cHandler.getController(),
                            endDateTime, days, controllerFactory.getBarJpaController(), logger);
                } else {
                    progressBarListener.propertyChange(new PropertyChangeEvent(this, "UpdaterLog", null,
                            "Processing " + counter + " of " + nContractList.size() + " Contract: "
                                    + contractEntity.getSymbol() + " no days"));
                }
            }
            if (progressBarListener != null) {
                float f = ((counter * 1f) / nContractList.size()) * 100f;
                progressBarListener
                        .propertyChange(new PropertyChangeEvent(this, "UpdaterProgress", null, Math.round(f)));
            }
            if (handler != null) {
                long bMillis = System.currentTimeMillis();
                handler.execute();
                handler.get();
                handler.end();
                while ((System.currentTimeMillis() - bMillis) < _10s) {
                    Thread.sleep(_1s);
                }
            }
        }
        progressBarListener.propertyChange(new PropertyChangeEvent(this, "UpdaterLog", null, "End"));
    } catch (Exception e) {
        Logger.getLogger(Updater2.class.getName()).log(Level.SEVERE, null, e);
    }

}

From source file:com.microsoft.office365.snippetapp.Snippets.CalendarSnippets.java

License:MIT License

/**
 * Creates a recurring event. This snippet will create an event that recurs
 * every Tuesday and Thursday from 1PM to 2PM. You can modify this snippet
 * to work with other recurrence patterns.
 *
 * @param subject      The subject of the event
 * @param itemBodyHtml The body of the event as HTML
 * @param attendees    A list of attendee email addresses
 * @return String The id of the created event
 *///from   ww  w  .j av a2s.co m
public String createRecurringCalendarEvent(String subject, String itemBodyHtml, List<String> attendees)
        throws ExecutionException, InterruptedException {

    //Create a new Office 365 Event object
    Event newEvent = new Event();
    newEvent.setSubject(subject);
    ItemBody itemBody = new ItemBody();
    itemBody.setContent(itemBodyHtml);
    itemBody.setContentType(BodyType.HTML);
    newEvent.setBody(itemBody);

    //Set the attendee list
    List<Attendee> attendeeList = convertEmailStringsToAttendees(attendees);
    newEvent.setAttendees(attendeeList);

    //Set start date to the next occurring Tuesday
    DateTime startDate = DateTime.now();
    if (startDate.getDayOfWeek() < DateTimeConstants.TUESDAY) {
        startDate = startDate.dayOfWeek().setCopy(DateTimeConstants.TUESDAY);
    } else {
        startDate = startDate.plusWeeks(1);
        startDate = startDate.dayOfWeek().setCopy(DateTimeConstants.TUESDAY);
    }

    //Set start time to 1 PM
    startDate = startDate.hourOfDay().setCopy(13).withMinuteOfHour(0).withSecondOfMinute(0)
            .withMillisOfSecond(0);

    //Set end time to 2 PM
    DateTime endDate = startDate.hourOfDay().setCopy(14);

    //Set start and end time on the new Event (next Tuesday 1-2PM)
    newEvent.setStart(startDate.toCalendar(Locale.getDefault()));
    newEvent.setIsAllDay(false);
    newEvent.setEnd(endDate.toCalendar(Locale.getDefault()));

    //Configure the recurrence pattern for the new event
    //In this case the meeting will occur every Tuesday and Thursday from 1PM to 2PM
    RecurrencePattern recurrencePattern = new RecurrencePattern();
    List<DayOfWeek> daysMeetingRecursOn = new ArrayList();
    daysMeetingRecursOn.add(DayOfWeek.Tuesday);
    daysMeetingRecursOn.add(DayOfWeek.Thursday);
    recurrencePattern.setType(RecurrencePatternType.Weekly);
    recurrencePattern.setDaysOfWeek(daysMeetingRecursOn);
    recurrencePattern.setInterval(1); //recurs every week

    //Create a recurring range. In this case the range does not end
    //and the event occurs every Tuesday and Thursday forever.
    RecurrenceRange recurrenceRange = new RecurrenceRange();
    recurrenceRange.setType(RecurrenceRangeType.NoEnd);
    recurrenceRange.setStartDate(startDate.toCalendar(Locale.getDefault()));

    //Create a pattern of recurrence. It contains the recurrence pattern
    //and recurrence range created previously.
    PatternedRecurrence patternedRecurrence = new PatternedRecurrence();
    patternedRecurrence.setPattern(recurrencePattern);
    patternedRecurrence.setRange(recurrenceRange);

    //Finally pass the patterned recurrence to the new Event object.
    newEvent.setRecurrence(patternedRecurrence);

    //Create the event and return the id
    return mCalendarClient.getMe().getEvents().select("ID").add(newEvent).get().getId();
}

From source file:com.mycollab.module.project.view.ticket.CreatedDateOrderComponent.java

License:Open Source License

@Override
public void insertTickets(List<ProjectTicket> tickets) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(MyCollabUI.getLongDateFormat())
            .withLocale(UserUIContext.getUserLocale());
    for (ProjectTicket ticket : tickets) {
        if (ticket.getCreatedTime() != null) {
            Date createdDate = ticket.getCreatedTime();
            DateTime jodaTime = new DateTime(createdDate, DateTimeZone.UTC);
            DateTime monDay = jodaTime.dayOfWeek().withMinimumValue();
            String monDayStr = formatter.print(monDay);
            Long time = new LocalDate(monDay).toDate().getTime();
            if (createdDateAvailables.containsKey(time)) {
                DefaultTicketGroupComponent groupComponent = createdDateAvailables.get(time);
                groupComponent.insertTicket(ticket);
            } else {
                DateTime maxValue = monDay.dayOfWeek().withMaximumValue();
                String sundayStr = formatter.print(maxValue);
                String titleValue = String.format("%s - %s", monDayStr, sundayStr);

                DefaultTicketGroupComponent groupComponent = new DefaultTicketGroupComponent(titleValue);
                createdDateAvailables.put(time, groupComponent);
                addComponent(groupComponent);
                groupComponent.insertTicket(ticket);
            }/*from  w  w  w  .  j  a  v  a2s . c  o  m*/
        } else {
            if (unspecifiedTasks == null) {
                unspecifiedTasks = new DefaultTicketGroupComponent(
                        UserUIContext.getMessage(GenericI18Enum.OPT_UNDEFINED));
                addComponent(unspecifiedTasks, 0);
            }
            unspecifiedTasks.insertTicket(ticket);
        }
    }
}

From source file:com.mycollab.module.project.view.ticket.DueDateOrderComponent.java

License:Open Source License

@Override
public void insertTickets(List<ProjectTicket> tickets) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(MyCollabUI.getLongDateFormat())
            .withLocale(UserUIContext.getUserLocale());
    for (ProjectTicket ticket : tickets) {
        if (ticket.getDueDate() != null) {
            Date dueDate = ticket.getDueDate();
            DateTime jodaTime = new DateTime(dueDate, DateTimeZone.UTC);
            DateTime monDay = jodaTime.dayOfWeek().withMinimumValue();
            String monDayStr = formatter.print(monDay);
            Long time = new LocalDate(monDay).toDate().getTime();
            if (dueDateAvailables.containsKey(time)) {
                DefaultTicketGroupComponent groupComponent = dueDateAvailables.get(time);
                groupComponent.insertTicket(ticket);
            } else {
                DateTime maxValue = monDay.dayOfWeek().withMaximumValue();
                String sundayStr = formatter.print(maxValue);
                String titleValue = String.format("%s - %s", monDayStr, sundayStr);

                DefaultTicketGroupComponent groupComponent = new DefaultTicketGroupComponent(titleValue);
                dueDateAvailables.put(time, groupComponent);
                addComponent(groupComponent);
                groupComponent.insertTicket(ticket);
            }//  w  w w  . j  a v  a2 s .  com
        } else {
            if (unspecifiedTasks == null) {
                unspecifiedTasks = new DefaultTicketGroupComponent(
                        UserUIContext.getMessage(GenericI18Enum.OPT_UNDEFINED));
                addComponent(unspecifiedTasks);
            }
            unspecifiedTasks.insertTicket(ticket);
        }
    }
}