Example usage for org.joda.time MutableDateTime toDateTime

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

Introduction

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

Prototype

DateTime toDateTime();

Source Link

Document

Get this object as a DateTime.

Usage

From source file:org.obp.utils.TimeUtil.java

License:Apache License

public static final long fromUtcHHMMSS(double time) {
    int hhmmss = (int) time;
    MutableDateTime mdt = MutableDateTime.now(DateTimeZone.UTC);
    mdt.setSecondOfMinute(hhmmss % 100);
    mdt.setMinuteOfHour((hhmmss / 100) % 100);
    mdt.setHourOfDay(hhmmss / 10000);// w  w  w.ja  v a2s.  c  o m
    mdt.setMillisOfSecond((int) ((time - hhmmss) * 1000));
    return mdt.toDateTime().getMillis();
}

From source file:org.osframework.util.DateUtil.java

License:Apache License

static DateTime forceMidnight(DateTime dt) {
    MutableDateTime mdt = dt.toMutableDateTime();
    mdt.setHourOfDay(0);/*w ww  .j  a v a2s . c o m*/
    mdt.setMinuteOfHour(0);
    mdt.setSecondOfMinute(0);
    return mdt.toDateTime();
}

From source file:org.wicketopia.joda.util.format.JodaFormatSupport.java

License:Apache License

public T convertToObject(String value, Locale locale) {
    if (Strings.isEmpty(value)) {
        return null;
    }/*ww  w  . j  a v a 2s.co  m*/

    DateTimeFormatter format = formatProvider.getFormatter();

    if (format == null) {
        throw new IllegalStateException("format must be not null");
    }
    format = format.withLocale(locale).withPivotYear(pivotYear);
    if (applyTimeZoneDifference) {
        TimeZone zone = getClientTimeZone();
        // instantiate now/ current time
        MutableDateTime dt = new MutableDateTime();
        if (zone != null) {
            // set time zone for client
            format = format.withZone(DateTimeZone.forTimeZone(zone));
            dt.setZone(DateTimeZone.forTimeZone(zone));
        }
        try {
            // parse date retaining the time of the submission
            int result = format.parseInto(dt, value, 0);
            if (result < 0) {
                throw new ConversionException(new ParseException("unable to parse date " + value, ~result));
            }
        } catch (RuntimeException e) {
            throw new ConversionException(e);
        }
        // apply the server time zone to the parsed value
        dt.setZone(getServerTimeZone());
        return translator.fromDateTime(dt.toDateTime());
    } else {
        try {
            DateTime date = format.parseDateTime(value);
            return date == null ? null : translator.fromDateTime(date);
        } catch (RuntimeException e) {
            throw new ConversionException(e);
        }
    }
}

From source file:org.wicketstuff.datetime.extensions.yui.calendar.DateTimeField.java

License:Apache License

/**
 * @see org.apache.wicket.Component#onBeforeRender()
 *///  w ww  .  j a  v a  2 s .  c  o m
@Override
protected void onBeforeRender() {
    dateField.setRequired(isRequired());
    hoursField.setRequired(isRequired());
    minutesField.setRequired(isRequired());

    boolean use12HourFormat = use12HourFormat();
    amOrPmChoice.setVisible(use12HourFormat);

    Date modelObject = (Date) getDefaultModelObject();
    if (modelObject == null) {
        date = null;
        hours = null;
        minutes = null;
    } else {
        MutableDateTime mDate = new MutableDateTime(modelObject);
        // convert date to the client's time zone if we have that info
        TimeZone zone = getClientTimeZone();
        if (zone != null) {
            mDate.setZone(DateTimeZone.forTimeZone(zone));
        }

        date = mDate.toDateTime().toLocalDate().toDate();

        if (use12HourFormat) {
            int hourOfHalfDay = mDate.get(DateTimeFieldType.hourOfHalfday());
            hours = hourOfHalfDay == 0 ? 12 : hourOfHalfDay;
        } else {
            hours = mDate.get(DateTimeFieldType.hourOfDay());
        }

        amOrPm = (mDate.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM : AM_PM.PM;
        minutes = mDate.getMinuteOfHour();
    }

    super.onBeforeRender();
}

From source file:org.xmlcml.euclid.JodaDate.java

License:Apache License

public static DateTime parseDate(String s) {
    if (s.endsWith("Z")) {
        MutableDateTime dateTime = ZULU_FORMATTER.parseMutableDateTime(s);
        dateTime.setZone(DateTimeZone.UTC);
        return dateTime.toDateTime();
    } else if (Character.isLetter(s.charAt(0))) {
        DateTime dateTime = JodaDate.parseQuietly(ALPHA_FORMATTER2, s);
        if (dateTime == null) {
            dateTime = JodaDate.parseQuietly(ALPHA_FORMATTER1, s);
        }//from www . j  a  va  2 s. c o m
        return dateTime;
    } else {
        return DATETIME_FORMATTER.parseDateTime(s);
    }
}

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);//from  w w  w .j ava 2 s. c o m
    return RangedEventGenerator.generateWeeklyEvents(now.toDateTime());
}

From source file:y.elf.DbReader.java

License:Open Source License

public static List<ElfValue> readOldCentralineFile(String filename, int defaultvalue, int fieldnn) {
    final String separatorDate = "/";
    final String separatorTime = ":";
    final int UNUSED = Integer.MIN_VALUE;

    List<ElfValue> list = new ArrayList<ElfValue>();

    BufferedReader reader = null;

    try {/*w w w  .j  a  v  a2  s.  co m*/
        reader = new BufferedReader(new FileReader(filename));
        String line;
        MutableDateTime lasttime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0);
        final MutableDateTime invalidtime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0);

        while ((line = reader.readLine()) != null) {
            if (line.isEmpty())
                continue;

            try {
                boolean valid = true;
                final String[] parts = tokenize(line);
                int value = UNUSED;
                int maxvalue = 0;

                for (int i = 0; i < parts.length; i++) {
                    if (parts[i].equals("*"))
                        valid = false;
                    else if (parts[i].contains(separatorDate)) {
                        final String[] date = parts[i].split(separatorDate);

                        lasttime.setDayOfMonth(Integer.parseInt(date[0]));
                        lasttime.setMonthOfYear(Integer.parseInt(date[1]));
                        lasttime.setYear(Integer.parseInt(date[2]));
                    } else if (parts[i].contains(separatorTime)) {
                        final String[] hour = parts[i].split(separatorTime);
                        lasttime.setHourOfDay(Integer.parseInt(hour[0]));
                        lasttime.setMinuteOfHour(Integer.parseInt(hour[1]));
                    } else if (value == UNUSED)
                        value = translateValue(parts[i], defaultvalue);
                    else
                        maxvalue = translateValue(parts[i], defaultvalue);
                }

                if (lasttime.equals(invalidtime)) // invalid line (header)
                    continue;

                final DateTime currentdatetime = lasttime.toDateTime();

                if (value > 0) {
                    if (fieldnn == 2)
                        list.add(new ElfValue(currentdatetime, maxvalue, value, valid));
                    else
                        list.add(new ElfValue(currentdatetime, value, maxvalue, valid));
                } else
                    list.add(new ElfValue(currentdatetime, 0, 0, false));
            } catch (Exception e) {
                continue;
            } // on error, skip line
        }
    } catch (Exception e) {
        //         System.out.println(e.getMessage());
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {
            }
    }

    return list;
}