Example usage for org.joda.time DateMidnight getMillis

List of usage examples for org.joda.time DateMidnight getMillis

Introduction

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

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:lt.norma.crossbow.contracts.DerivativesContract.java

License:Open Source License

/**
 * Calculates years to contracts maturity. Assumes an average year of 365.25 days, or 31557600000
 * milliseconds.//from   w w w.  j a  v  a 2  s  .c  om
 * 
 * @param now
 *           current date
 * @return years to option's maturity
 * @throws ContractException
 *            throws an exception if the contract has expired
 */
public final double yearsToMaturity(DateMidnight now) throws ContractException {
    if (now.isAfter(maturityDate)) {
        throw new ContractException(this, "Cannot calculate years to matyrity for " + this.toString()
                + " contract. The contract is expired.");
    }

    return (maturityDate.getMillis() - now.getMillis()) / 31557600000.0;
}

From source file:net.naonedbus.manager.impl.HoraireManager.java

License:Open Source License

/**
 * Indique si le cache contient les horaires de l'arrt pour la date donne.
 * /*from w ww .  j av a  2s .  c  o  m*/
 * @return {@code true} si le cache contient tous les horaires pour l'arret
 *         et la date demande {@code false} si les donnes ne sont pas en
 *         cache.
 */
public boolean isInDB(final ContentResolver contentResolver, final Arret arret, final DateMidnight date,
        final int count) {

    final ScheduleToken token = new ScheduleToken(date.getMillis(), arret.getId());
    return isInDB(contentResolver, token, count);
}

From source file:net.naonedbus.manager.impl.HoraireManager.java

License:Open Source License

/**
 * Rcuprer les horaires d'un arrt./* w  w  w . j  a  v a2 s.  com*/
 * 
 * @throws IOException
 */
public List<Horaire> getSchedules(final ContentResolver contentResolver, final Arret arret,
        final DateMidnight date, final DateTime after) throws IOException {
    // Le cache ne doit stocker que les horaires du jour et du lendemain.

    final DateMidnight cacheLimit = new DateMidnight().plusDays(DAYS_IN_CACHE);
    final DateMidnight today = new DateMidnight();
    final DateTime now = new DateTime();
    List<Horaire> horaires;

    if (date.isBefore(cacheLimit)) {

        final ScheduleToken todayToken = new ScheduleToken(date.getMillis(), arret.getId());

        // Partie atomique
        synchronized (mDatabaseLock) {

            if (!isInDB(contentResolver, todayToken)) {
                // Charger les horaires depuis le web et les stocker en base

                if (date.isEqual(today) && now.getHourOfDay() < END_OF_TRIP_HOURS) {
                    // Charger la veille si besoin (pour les horaires aprs
                    // minuit)
                    final ScheduleToken yesterdayToken = new ScheduleToken(date.minusDays(1).getMillis(),
                            arret.getId());

                    if (isInDB(contentResolver, yesterdayToken)) {
                        horaires = mController.getAllFromWeb(arret, date.minusDays(1));
                        fillDB(contentResolver, yesterdayToken, horaires);
                    }
                }

                horaires = mController.getAllFromWeb(arret, date);
                fillDB(contentResolver, todayToken, horaires);
            }

            // Charger les horaires depuis la base
            final Uri.Builder builder = HoraireProvider.CONTENT_URI.buildUpon();
            builder.path(HoraireProvider.HORAIRE_JOUR_URI_PATH_QUERY);
            builder.appendQueryParameter(HoraireProvider.PARAM_ARRET_ID, String.valueOf(arret.getId()));
            builder.appendQueryParameter(HoraireProvider.PARAM_JOUR, mIso8601Format.format(date.toDate()));
            builder.appendQueryParameter(HoraireProvider.PARAM_INCLUDE_LAST_DAY_TRIP, "true");

            // Eviter l'affichage de doublons
            if (after != null) {
                builder.appendQueryParameter(HoraireProvider.PARAM_AFTER_TIME,
                        mIso8601Format.format(after.toDate()));
            }

            final Cursor cursor = contentResolver.query(builder.build(), null, null, null, null);
            horaires = getFromCursor(cursor);
            cursor.close();
        }

    } else {
        horaires = mController.getAllFromWeb(arret, date);
    }

    return horaires;
}

From source file:op.care.prescription.PnlScheduleDose.java

License:Open Source License

private void initPanel() {

    tabWdh.setTitleAt(0, SYSTools.xx("misc.msg.daily"));
    tabWdh.setTitleAt(1, SYSTools.xx("misc.msg.weekly"));
    tabWdh.setTitleAt(2, SYSTools.xx("misc.msg.monthly"));

    lblLDate.setText(SYSTools.xx(internalClassID + ".lblLDate") + " ");
    lblOnThe.setText(SYSTools.xx(internalClassID + ".lblOnThe"));
    lblMonth.setText(SYSTools.xx("misc.msg.months"));
    lblEach.setText(SYSTools.xx("misc.msg.every"));
    lblEvery1.setText(SYSTools.xx("misc.msg.every"));
    lblEvery2.setText(SYSTools.xx("misc.msg.every"));
    lblWeeksAt.setText(SYSTools.xx("misc.msg.weeks") + " " + SYSTools.xx("misc.msg.atchrono"));
    lblDays.setText(SYSTools.xx("misc.msg.Days2"));

    ArrayList<Date> timelist = SYSCalendar.getTimeList();
    cmbUhrzeit.setModel(new DefaultComboBoxModel(timelist.toArray()));
    cmbUhrzeit.setRenderer(SYSCalendar.getTimeRenderer());

    String[] wdaymodel = new String[] { SYSTools.xx("misc.msg.dayOfMonth"), SYSTools.xx("misc.msg.monday"),
            SYSTools.xx("misc.msg.tuesday"), SYSTools.xx("misc.msg.wednesday"),
            SYSTools.xx("misc.msg.thursday"), SYSTools.xx("misc.msg.friday"), SYSTools.xx("misc.msg.saturday"),
            SYSTools.xx("misc.msg.sunday") };
    cmbWDay.setModel(new DefaultComboBoxModel(wdaymodel));

    lblMon.setText(SYSTools.xx("misc.msg.monday"));
    lblTue.setText(SYSTools.xx("misc.msg.tuesday"));
    lblWed.setText(SYSTools.xx("misc.msg.wednesday"));
    lblThu.setText(SYSTools.xx("misc.msg.thursday"));
    lblFri.setText(SYSTools.xx("misc.msg.friday"));
    lblSat.setText(SYSTools.xx("misc.msg.saturday"));
    lblSun.setText(SYSTools.xx("misc.msg.sunday"));

    lblVeryEarly.setText(SYSTools.xx("misc.msg.earlyinthemorning.long"));
    lblMorning.setText(SYSTools.xx("misc.msg.morning.long"));
    lblNoon.setText(SYSTools.xx("misc.msg.noon.long"));
    lblAfternoon.setText(SYSTools.xx("misc.msg.afternoon.long"));
    lblEvening.setText(SYSTools.xx("misc.msg.evening.long"));
    lblVeryLate.setText(SYSTools.xx("misc.msg.lateatnight.long"));

    txtEveryDay.setText("1");
    txtEveryWeek.setText("1");
    txtEveryMonth.setText("1");
    txtEveryWDayOfMonth.setText("1");

    //        txtEveryDay.setText(schedule.getTaeglich().toString());
    //        txtEveryWeek.setText(schedule.getWoechentlich().toString());
    //        txtEveryMonth.setText(schedule.getMonatlich().toString());
    //        txtEveryWDayOfMonth.setText(schedule.getTagNum().toString());

    tabWdh.setSelectedIndex(TAB_DAILY);/*from   www.j  a v  a 2  s . c o m*/

    if (schedule.getWoechentlich() > 0) {
        cbMon.setSelected(schedule.getMon() > 0);
        cbTue.setSelected(schedule.getTue() > 0);
        cbWed.setSelected(schedule.getWed() > 0);
        cbThu.setSelected(schedule.getThu() > 0);
        cbFri.setSelected(schedule.getFri() > 0);
        cbSat.setSelected(schedule.getSat() > 0);
        cbSun.setSelected(schedule.getSun() > 0);
        tabWdh.setSelectedIndex(TAB_WEEKLY);
    }

    if (schedule.getMonatlich() > 0) {
        if (schedule.getTagNum() > 0) {
            txtEveryWDayOfMonth.setText(Short.toString(schedule.getTagNum()));
            cmbWDay.setSelectedIndex(0);
        } else {
            if (schedule.getMon() > 0) {
                cmbWDay.setSelectedIndex(1);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getMon()));
            } else if (schedule.getTue() > 0) {
                cmbWDay.setSelectedIndex(2);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getTue()));
            } else if (schedule.getWed() > 0) {
                cmbWDay.setSelectedIndex(3);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getWed()));
            } else if (schedule.getThu() > 0) {
                cmbWDay.setSelectedIndex(4);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getThu()));
            } else if (schedule.getFri() > 0) {
                cmbWDay.setSelectedIndex(5);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getFri()));
            } else if (schedule.getSat() > 0) {
                cmbWDay.setSelectedIndex(6);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getSat()));
            } else if (schedule.getSun() > 0) {
                cmbWDay.setSelectedIndex(7);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getSun()));
            }
        }
        tabWdh.setSelectedIndex(TAB_MONTHLY);
    }

    //        jdcLDatum.setMinSelectableDate(new Date());
    //        jdcLDatum.setDate(new Date(Math.max(schedule.getLDatum().getTime(), SYSCalendar.startOfDay())));

    DateMidnight scheduleLDate = new DateMidnight(schedule.getLDatum());
    DateMidnight today = new DateMidnight();
    DateMidnight ldate = new DateMidnight(Math.max(scheduleLDate.getMillis(), today.getMillis()));
    txtLDate.setText(DateFormat.getDateInstance().format(ldate.toDate()));

    txtVeryEarly.setText(schedule.getNachtMo().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtMorning.setText(schedule.getMorgens().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtNoon.setText(schedule.getMittags().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtAfternoon.setText(schedule.getNachmittags().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtEvening.setText(schedule.getAbends().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtVeryLate.setText(schedule.getNachtAb().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtTimeDose.setText(schedule.getUhrzeitDosis().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());

    txtMorning.setBackground(SYSConst.lightblue);
    txtNoon.setBackground(SYSConst.gold7);
    txtAfternoon.setBackground(SYSConst.melonrindgreen);
    txtEvening.setBackground(SYSConst.bermuda_sand);
    txtVeryLate.setBackground(SYSConst.bluegrey);

    Date now = null;
    if (schedule.getUhrzeitDosis().compareTo(BigDecimal.ZERO) > 0) {
        splitRegularPos = 0.0d;
        now = schedule.getUhrzeit();
    } else {
        now = new Date();
        splitRegularPos = 1.0d;
    }

    for (Date zeit : timelist) {
        if (SYSCalendar.compareTime(zeit, now) >= 0) {
            now = zeit;
            break;
        }
    }
    cmbUhrzeit.setSelectedItem(now);
    lblTimeDose.setText(SYSTools.xx(internalClassID + ".lblTimeDose") + " "
            + DateFormat.getTimeInstance(DateFormat.SHORT).format(now) + " "
            + SYSTools.xx("misc.msg.Time.short"));

    panelMainComponentResized(null);
}

From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java

License:Apache License

/**
 * Get a JSON-appropriate representation of each recurrence of an event
 * within the specified time period.// w w  w .j  a va2s.  c  om
 *
 * @param e
 * @param interval
 * @param usersConfiguredDateTimeZone
 * @return
 * @throws IOException
 * @throws URISyntaxException
 * @throws ParseException
 */
protected Set<CalendarDisplayEvent> getDisplayEvents(VEvent e, Interval interval, Locale locale,
        DateTimeZone usersConfiguredDateTimeZone) throws IOException, URISyntaxException, ParseException {

    final VEvent event = (VEvent) e.copy();

    DateTime eventStart;
    DateTime eventEnd = null;

    if (event.getStartDate().getTimeZone() == null && !event.getStartDate().isUtc()) {
        if (log.isDebugEnabled()) {
            log.debug("Identified event " + event.getSummary() + " as a floating event");
        }

        int offset = usersConfiguredDateTimeZone.getOffset(event.getStartDate().getDate().getTime());
        eventStart = new DateTime(event.getStartDate().getDate().getTime() - offset,
                usersConfiguredDateTimeZone);
        if (event.getEndDate() != null) {
            eventEnd = new DateTime(event.getEndDate().getDate().getTime() - offset,
                    usersConfiguredDateTimeZone);
        }

    } else {
        eventStart = new DateTime(event.getStartDate().getDate(), usersConfiguredDateTimeZone);
        if (event.getEndDate() != null) {
            eventEnd = new DateTime(event.getEndDate().getDate(), usersConfiguredDateTimeZone);
        }
    }

    if (eventEnd == null) {
        eventEnd = eventStart;
    }

    // Multi-day events may begin in the past;  make sure to choose a date in range for the first pass...
    final Date firstDayToProcess = interval.contains(event.getStartDate().getDate().getTime())
            ? event.getStartDate().getDate()
            : interval.getStart().toDate();

    DateMidnight startOfTheSpecificDay = new DateMidnight(firstDayToProcess, usersConfiguredDateTimeZone);
    DateMidnight endOfTheSpecificDay = startOfTheSpecificDay.plusDays(1);

    final DateTimeFormatter df = getDateFormatter(locale, usersConfiguredDateTimeZone);
    final DateTimeFormatter tf = getTimeFormatter(locale, usersConfiguredDateTimeZone);
    final Set<CalendarDisplayEvent> events = new HashSet<CalendarDisplayEvent>();
    final Interval eventInterval = new Interval(eventStart, eventEnd);

    do {
        final Interval theSpecificDay = new Interval(startOfTheSpecificDay.getMillis(),
                endOfTheSpecificDay.getMillis(), usersConfiguredDateTimeZone);

        /*
         * Test if the event interval abuts the start of the day or is within the day.
         * This start time check is needed for the corner case where a zero duration interval
         * is set for midnight.
         * The start times are tested directly as opposed to using abuts() because that method
         * also returns true if the intervals abut at the end of the day. We want to associate
         * instant events that start at midnight with the starting day, not the ending day.
         */
        if (theSpecificDay.getStart().isEqual(eventStart) || theSpecificDay.overlaps(eventInterval)) {
            final CalendarDisplayEvent json = new CalendarDisplayEvent(event, eventInterval, theSpecificDay, df,
                    tf);
            events.add(json);
        }

        startOfTheSpecificDay = startOfTheSpecificDay.plusDays(1);
        endOfTheSpecificDay = endOfTheSpecificDay.plusDays(1);

    } while (!startOfTheSpecificDay.isAfter(eventEnd) && interval.contains(startOfTheSpecificDay));

    return events;
}

From source file:org.key2gym.business.services.OrdersServiceBean.java

License:Apache License

/**
 * Checks whether the provided date is today.
 *
 * @param date the date to check/*w w w . j a  va  2 s.  c o  m*/
 * @return true, if the date's time is past the today's midnight.
 */
public boolean isToday(Date date) {
    DateMidnight today = new DateMidnight();
    DateMidnight tomorrow = today.plusDays(1);
    return today.getMillis() <= date.getTime() && tomorrow.getMillis() > date.getTime();
}

From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java

License:Open Source License

private ASSystemTime standardDate(TimeZone timeZone) {
    DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);

    DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone);

    long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis());
    long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant);

    if (firstDSTTransitionInstant == secondDSTTransitionInstant) {
        return systemTimeFromInstant(0, DateTimeZone.UTC);
    }// w  w  w. j  ava2 s  . c o  m

    if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) {
        return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone);
    }
    return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone);
}

From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java

License:Open Source License

private ASSystemTime dayLightDate(TimeZone timeZone) {
    DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);

    DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone);

    long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis());
    long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant);

    if (firstDSTTransitionInstant == secondDSTTransitionInstant) {
        return systemTimeFromInstant(0, DateTimeZone.UTC);
    }/*from   ww  w  .jav a  2s . c om*/

    if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) {
        return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone);
    }
    return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone);
}