Example usage for org.joda.time LocalDate fromDateFields

List of usage examples for org.joda.time LocalDate fromDateFields

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static LocalDate fromDateFields(Date date) 

Source Link

Document

Constructs a LocalDate from a java.util.Date using exactly the same field values.

Usage

From source file:org.zkoss.ganttz.data.Task.java

License:Open Source License

public LocalDate getBeginDateAsLocalDate() {
    return LocalDate.fromDateFields(getBeginDate().toDayRoundedDate());
}

From source file:org.zkoss.ganttz.LeftTasksTreeRow.java

License:Open Source License

public void updateBean(Component updatedComponent) {
    if (updatedComponent == getNameBox()) {

        task.setName(getNameBox().getValue());

        if (StringUtils.isEmpty(getNameBox().getValue())) {
            getNameBox().setValue(task.getName());
        }//from w ww .  ja va 2  s  .  com

    } else if (updatedComponent == getStartDateTextBox()) {

        try {
            final Date begin = dateFormat.parse(getStartDateTextBox().getValue());
            task.doPositionModifications(position -> position.moveTo(GanttDate.createFrom(begin)));
        } catch (ParseException e) {
            // Do nothing as textbox is rested in the next sentence
        }

        getStartDateTextBox().setValue(dateFormat.format(task.getBeginDate().toDayRoundedDate()));

    } else if (updatedComponent == getEndDateTextBox()) {

        try {
            Date newEnd = dateFormat.parse(getEndDateTextBox().getValue());
            task.resizeTo(LocalDate.fromDateFields(newEnd));
        } catch (ParseException e) {
            // Do nothing as textbox is rested in the next sentence
        }

        getEndDateTextBox().setValue(asString(task.getEndDate().toDayRoundedDate()));
    }

    planner.updateTooltips();
}

From source file:org.zkoss.ganttz.TaskComponent.java

License:Open Source License

private void updateDeadline() {
    // Task mark is placed after midnight date of the deadline day
    if (task.getDeadline() != null) {

        String position = (getMapper().toPixels(LocalDate.fromDateFields(task.getDeadline()).plusDays(1))
                - HALF_DEADLINE_MARK) + "px";

        response(null, new AuInvoke(this, "moveDeadline", position));

    } else {/*  ww w  .j a v  a 2s  .c o m*/
        // Move deadline out of visible area
        response(null, new AuInvoke(this, "moveDeadline", "-100px"));
    }

    if (task.getConsolidatedline() != null) {

        int pixels = getMapper()
                .toPixels(LocalDate.fromDateFields(task.getConsolidatedline().toDayRoundedDate()))
                - CONSOLIDATED_MARK_HALF_WIDTH;

        String position = pixels + "px";
        response(null, new AuInvoke(this, "moveConsolidatedline", position));

    } else {
        // Move consolidated line out of visible area
        response(null, new AuInvoke(this, "moveConsolidatedline", "-100px"));
    }
}

From source file:org.zkoss.ganttz.TaskComponent.java

License:Open Source License

public void updateCompletionReportedHours() {
    if (task.isShowingReportedHours()) {
        int startPixels = this.task.getBeginDate().toPixels(getMapper());

        String widthHoursAdvancePercentage = pixelsFromStartUntil(startPixels,
                this.task.getHoursAdvanceBarEndDate()) + "px";

        response(null, new AuInvoke(this, "resizeCompletionAdvance", widthHoursAdvancePercentage));

        Date firstTimesheetDate = task.getFirstTimesheetDate();
        Date lastTimesheetDate = task.getLastTimesheetDate();

        if (firstTimesheetDate != null && lastTimesheetDate != null) {

            Duration firstDuration = Days
                    .daysBetween(task.getBeginDateAsLocalDate(), LocalDate.fromDateFields(firstTimesheetDate))
                    .toStandardDuration();

            int pixelsFirst = getMapper().toPixels(firstDuration);
            String positionFirst = pixelsFirst + "px";

            Duration lastDuration = Days.daysBetween(task.getBeginDateAsLocalDate(),
                    LocalDate.fromDateFields(lastTimesheetDate).plusDays(1)).toStandardDuration();

            int pixelsLast = getMapper().toPixels(lastDuration);
            String positionLast = pixelsLast + "px";

            response(null, new AuInvoke(this, "showTimsheetDateMarks", positionFirst, positionLast));

        } else {//from   ww w  . j  av a  2 s. c o m
            response(null, new AuInvoke(this, "hideTimsheetDateMarks"));
        }

    } else {
        response(null, new AuInvoke(this, "resizeCompletionAdvance", "0px"));
        response(null, new AuInvoke(this, "hideTimsheetDateMarks"));
    }
}

From source file:org.zkoss.ganttz.util.Interval.java

License:Open Source License

public Interval(Date start, Date finish) {
    this(LocalDate.fromDateFields(start), LocalDate.fromDateFields(finish));
}

From source file:ru.caramel.juniperbot.module.social.service.impl.YouTubeServiceImpl.java

License:Open Source License

@Override
@Transactional/*from  w  w w  .j a  v  a2 s .c  o m*/
public void subscribe(YouTubeChannel channel) {
    LocalDate now = LocalDate.now();
    LocalDate expiredAt = channel.getExpiresAt() != null ? LocalDate.fromDateFields(channel.getExpiresAt())
            : LocalDate.now();
    if (now.isBefore(expiredAt)) {
        return;
    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("hub.callback", String.format("%s/api/public/youtube/callback/publish?secret=%s&channel=%s",
            brandingService.getWebHost(), pubSubSecret, CommonUtils.urlEncode(channel.getChannelId())));
    map.add("hub.topic", CHANNEL_RSS_ENDPOINT + channel.getChannelId());
    map.add("hub.mode", "subscribe");
    map.add("hub.verify", "async");
    map.add("hub.verify_token", pubSubSecret);
    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);

    ResponseEntity<String> response = restTemplate.postForEntity(PUSH_ENDPOINT, request, String.class);
    if (!response.getStatusCode().is2xxSuccessful()) {
        throw new IllegalStateException("Could not subscribe to " + channel.getChannelId());
    }
    channel.setExpiresAt(DateTime.now().plusDays(7).toDate());
    channelRepository.save(channel);
}

From source file:uk.ac.ox.oucs.vle.CourseDAOImpl.java

License:Educational Community License

@SuppressWarnings("unchecked")
public List<CourseGroupDAO> findCourseGroupByDept(final String deptId, final Range range, final Date now,
        final boolean external) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        /**//from  w  ww. jav a  2s . c om
         * Note:
         * This can't be easily migrated to Hibernate Query API as collections are not supported
         * org.hibernate.MappingException: collection was not an association: uk.ac.ox.oucs.vle.CourseGroupDAO.otherDepartments
         */
        // Need the DISTINCT ROOT ENTITY filter.
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Date startLastYear = getPreviousYearBeginning(LocalDate.fromDateFields(now)).toDate();
            StringBuffer querySQL = new StringBuffer();
            querySQL.append("SELECT DISTINCT cg.* ");
            querySQL.append("FROM course_group cg ");
            querySQL.append("LEFT JOIN course_group_otherDepartment cgd on cgd.courseGroupMuid = cg.muid ");
            querySQL.append("LEFT JOIN course_group_component cgc on cgc.courseGroupMuid = cg.muid ");
            querySQL.append("LEFT JOIN course_component cc on cgc.courseComponentMuid = cc.muid ");
            querySQL.append("WHERE ");

            querySQL.append("visibility != 'PR' AND ");

            if (external) {
                querySQL.append("visibility != 'RS' AND ");
            }

            querySQL.append("hideGroup = false AND ");

            switch (range) {
            case UPCOMING:
                querySQL.append(
                        "((cc.baseDate is null AND cc.startsText is not null) OR cc.baseDate > :now) AND ");
                break;
            case PREVIOUS:
                querySQL.append(
                        "((cc.baseDate is null AND cc.startsText is null) OR (cc.baseDate <= :now AND cc.baseDate >= :lastYear)) AND ");
                break;
            }

            querySQL.append("(otherDepartment = :deptId ");
            querySQL.append("OR (dept = :deptId and (subunit is NULL or subunit = ''))) ");
            querySQL.append("ORDER BY cg.title ");

            Query query = session.createSQLQuery(querySQL.toString()).addEntity(CourseGroupDAO.class);
            query.setString("deptId", deptId);
            query.setDate("now", now);
            if (range.equals(range.PREVIOUS)) {
                query.setDate("lastYear", startLastYear);
            }

            return query.list();
        }
    });
}

From source file:uk.org.rbc1b.roms.controller.volunteer.VolunteerBadgePdfModelFactory.java

License:Open Source License

/**
 * Determines the colour of the badge depending on the volunteer details
 * such as their age and departmental assignment.
 *
 * @param volunteer volunteer/*from w  ww  .  ja  va 2s  .  co m*/
 * @return VolunteerBadgeColour the colour
 */
public VolunteerBadgeColour determineBadgeColour(Volunteer volunteer) {
    LocalDate birthDate = LocalDate.fromDateFields(volunteer.getPerson().getBirthDate());
    LocalDate now = new LocalDate();
    Years age = Years.yearsBetween(birthDate, now);

    // volunteer badge colour depends on age or assignment
    if (age.getYears() >= 13 && age.getYears() <= 15) {
        return VolunteerBadgeColour.GREEN;
    } else if (age.getYears() >= 16 && age.getYears() <= 17) {
        return VolunteerBadgeColour.ORANGE;
    } else if (isVolunteerAssignmentDangerous(volunteer)) {
        return VolunteerBadgeColour.RED;
    } else {
        return VolunteerBadgeColour.GREY;
    }
}

From source file:wikidash.SessionConstruction.java

private static void countActionsPerDay(ArrayList<WikiSession> dashboardSessions) {
    ArrayList<Action> actions = new ArrayList<>();
    TreeMap<String, TreeMap<String, Integer>> actionsPerDayCountMap = new TreeMap<>();

    for (WikiSession w : dashboardSessions) {
        actions.addAll(w.getActions());//  w  ww  .j a v  a 2 s.com
    }

    String actionString;
    LocalDate date;
    TreeMap<String, Integer> actionsOnThisDay;

    for (Action a : actions) {
        actionString = a.getAction();
        if (Arrays.asList(relevantActions).contains(actionString)) {
            date = LocalDate.fromDateFields(a.getTimestamp());
            if (!actionsPerDayCountMap.containsKey(date.toString())) {
                actionsPerDayCountMap.put(date.toString(), new TreeMap<String, Integer>());
            }

            actionsOnThisDay = actionsPerDayCountMap.get(date.toString());

            if (!actionsOnThisDay.containsKey(actionString)) {
                actionsOnThisDay.put(actionString, 1);
            } else {
                actionsOnThisDay.put(actionString, actionsOnThisDay.get(actionString) + 1);
            }
        }

    }

    LocalDate startDate = LocalDate.fromDateFields(Collections.min(actions).getTimestamp());
    LocalDate endDate = LocalDate.fromDateFields(Collections.max(actions).getTimestamp());

    System.out.print("day");
    for (String relAction : relevantActions) {
        System.out.print(";" + relAction);
    }
    System.out.println();

    for (LocalDate day = startDate; day.isBefore(endDate); day = day.plusDays(1)) {
        String line = day.toString();
        TreeMap<String, Integer> dayActions = actionsPerDayCountMap.get(day.toString());
        if (dayActions == null) {
            for (String relAction : relevantActions) {
                line += ";0";
            }
        } else {
            for (String relAction : relevantActions) {
                line += ";" + ((dayActions.get(relAction) == null) ? "0" : dayActions.get(relAction));
            }
        }
        System.out.println(line);
    }

}