Example usage for org.joda.time.format ISODateTimeFormat dateTime

List of usage examples for org.joda.time.format ISODateTimeFormat dateTime

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTime.

Prototype

public static DateTimeFormatter dateTime() 

Source Link

Document

Returns a formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).

Usage

From source file:org.emonocot.job.sitemap.SitemapFilesListener.java

License:Open Source License

public void beforeChunk() {
    //Check sizes (MB & count) & if over limit
    if (FileUtils.sizeOf(currentFile.getFile()) >= MAX_SITEMAP_LENGTH
            || (chunkOfFile * commitSize) >= MAX_URL_COUNT) {
        logger.debug("Creating a new file");
        try {/*from   w w w. j  a  va  2  s .c  om*/
            Url u = new Url();
            u.setLastmod(ISODateTimeFormat.dateTime().print((ReadableInstant) null));
            u.setLoc(new URL(portalBaseUrl + "/sitemap/" + currentFile.getFilename()));
            sitemapNames.add(u);
        } catch (MalformedURLException e) {
            logger.error("Unable create Url for sitemap", e);
        }
        //close & open writer with new name
        staxWriter.close();
        currentFile = new FileSystemResource(
                sitemapSpoolDir + "/" + currentStep.getStepName() + ++fileCount + ".xml");
        logger.debug("Open:" + currentFile.isOpen());
        logger.debug("Writable:" + currentFile.isWritable());
        staxWriter.setResource((Resource) currentFile);
        staxWriter.open(currentStep.getExecutionContext());

        chunkOfFile = 0;
    }
}

From source file:org.epics.archiverappliance.common.TimeUtils.java

public static java.sql.Timestamp convertFromISO8601String(String tsstr) {
    // Sample ISO8601 string 2011-02-01T08:00:00.000Z
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    DateTime dt = fmt.parseDateTime(tsstr);
    Timestamp ts = new Timestamp(dt.getMillis());
    return ts;/*from  w  w  w . j ava  2 s  .c  o m*/
}

From source file:org.epics.archiverappliance.common.TimeUtils.java

public static String convertToISO8601String(java.sql.Timestamp ts) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    DateTime dateTime = new DateTime(ts.getTime(), DateTimeZone.UTC);
    String retval = fmt.print(dateTime);
    return retval;
}

From source file:org.epics.archiverappliance.common.TimeUtils.java

public static String convertToISO8601String(long epochSeconds) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC);
    String retval = fmt.print(dateTime);
    return retval;
}

From source file:org.fao.geonet.domain.ISODate.java

License:Open Source License

public static String parseISODateTimes(String input1, String input2) {
    DateTimeFormatter dto = ISODateTimeFormat.dateTime();
    PeriodFormatter p = ISOPeriodFormat.standard();
    DateTime odt1;// w w  w. j  ava  2s. c o  m
    String odt = "";

    // input1 should be some sort of ISO time
    // eg. basic: 20080909, full: 2008-09-09T12:21:00 etc
    // convert everything to UTC so that we remove any timezone
    // problems
    try {
        DateTime idt = parseBasicOrFullDateTime(input1);
        odt1 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC"));
        odt = odt1.toString();

    } catch (Exception e) {
        Log.error("geonetwork.domain", "Error parsing ISO DateTimes, error: " + e.getMessage(), e);
        return DEFAULT_DATE_TIME;
    }

    if (input2 == null || input2.equals(""))
        return odt;

    // input2 can be an ISO time as for input1 but also an ISO time period
    // eg. -P3D or P3D - if an ISO time period then it must be added to the
    // DateTime generated for input1 (odt1)
    // convert everything to UTC so that we remove any timezone
    // problems
    try {
        boolean minus = false;
        if (input2.startsWith("-P")) {
            input2 = input2.substring(1);
            minus = true;
        }

        if (input2.startsWith("P")) {
            Period ip = p.parsePeriod(input2);
            DateTime odt2;
            if (!minus)
                odt2 = odt1.plus(ip.toStandardDuration().getMillis());
            else
                odt2 = odt1.minus(ip.toStandardDuration().getMillis());
            odt = odt + "|" + odt2.toString();
        } else {
            DateTime idt = parseBasicOrFullDateTime(input2);
            DateTime odt2 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC"));
            odt = odt + "|" + odt2.toString();
        }
    } catch (Exception e) {
        Log.error("geonetwork.domain", "Error parsing ISO DateTimes, error: " + e.getMessage(), e);
        return odt + "|" + DEFAULT_DATE_TIME;
    }

    return odt;
}

From source file:org.fao.geonet.kernel.harvest.harvester.thredds.Harvester.java

License:Open Source License

/** 
 * Get uuid and change date for thredds dataset
 *
  * @param ds     the dataset to be processed 
 **//*  w ww .j a  v  a  2 s  .  com*/

private RecordInfo getDatasetInfo(InvDataset ds) {
    Date lastModifiedDate = null;

    List<DateType> dates = ds.getDates();

    for (DateType date : dates) {
        if (date.getType().equalsIgnoreCase("modified")) {
            lastModifiedDate = date.getDate();
        }
    }

    String datasetChangeDate = null;

    if (lastModifiedDate != null) {
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        datasetChangeDate = fmt.print(new DateTime(lastModifiedDate));
    }

    return new RecordInfo(getUuid(ds), datasetChangeDate);
}

From source file:org.fao.geonet.util.JODAISODate.java

License:Open Source License

public static String parseISODateTimes(String input1, String input2) {
    DateTimeFormatter dto = ISODateTimeFormat.dateTime();
    PeriodFormatter p = ISOPeriodFormat.standard();
    DateTime odt1;//from   w w  w.j a  v  a 2 s  .co m
    String odt = "";

    // input1 should be some sort of ISO time 
    // eg. basic: 20080909, full: 2008-09-09T12:21:00 etc
    // convert everything to UTC so that we remove any timezone
    // problems
    try {
        DateTime idt = parseBasicOrFullDateTime(input1);
        odt1 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC"));
        odt = odt1.toString();

    } catch (Exception e) {
        e.printStackTrace();
        return dt;
    }

    if (input2 == null || input2.equals(""))
        return odt;

    // input2 can be an ISO time as for input1 but also an ISO time period
    // eg. -P3D or P3D - if an ISO time period then it must be added to the
    // DateTime generated for input1 (odt1)
    // convert everything to UTC so that we remove any timezone
    // problems
    try {
        boolean minus = false;
        if (input2.startsWith("-P")) {
            input2 = input2.substring(1);
            minus = true;
        }

        if (input2.startsWith("P")) {
            Period ip = p.parsePeriod(input2);
            DateTime odt2;
            if (!minus)
                odt2 = odt1.plus(ip.toStandardDuration().getMillis());
            else
                odt2 = odt1.minus(ip.toStandardDuration().getMillis());
            odt = odt + "|" + odt2.toString();
        } else {
            DateTime idt = parseBasicOrFullDateTime(input2);
            DateTime odt2 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC"));
            odt = odt + "|" + odt2.toString();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return odt + "|" + dt;
    }

    return odt;
}

From source file:org.fenixedu.academic.thesis.ui.controller.ConfigurationController.java

License:Open Source License

@Atomic(mode = TxMode.WRITE)
private void edit(ConfigurationBean configurationBean) throws OverlappingIntervalsException {

    ThesisProposalsConfiguration thesisProposalsConfiguration = FenixFramework
            .getDomainObject(configurationBean.getExternalId());

    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();

    DateTime proposalPeriodStartDT = formatter.parseDateTime(configurationBean.getProposalPeriodStart());
    DateTime proposalPeriodEndDT = formatter.parseDateTime(configurationBean.getProposalPeriodEnd());
    DateTime candidacyPeriodStartDT = formatter.parseDateTime(configurationBean.getCandidacyPeriodStart());
    DateTime candidacyPeriodEndDT = formatter.parseDateTime(configurationBean.getCandidacyPeriodEnd());

    Interval proposalPeriod = new Interval(proposalPeriodStartDT, proposalPeriodEndDT);
    Interval candidacyPeriod = new Interval(candidacyPeriodStartDT, candidacyPeriodEndDT);

    for (ThesisProposalsConfiguration config : thesisProposalsConfiguration.getExecutionDegree()
            .getThesisProposalsConfigurationSet()) {
        if (!config.equals(thesisProposalsConfiguration) && (config.getProposalPeriod().overlaps(proposalPeriod)
                || config.getCandidacyPeriod().overlaps(candidacyPeriod)
                || config.getProposalPeriod().overlaps(candidacyPeriod)
                || config.getCandidacyPeriod().overlaps(proposalPeriod))) {
            throw new OverlappingIntervalsException();
        }/*w w w.j ava2s.  c o m*/
    }

    Set<ThesisProposalsConfiguration> sharedConfigs = thesisProposalsConfiguration.getThesisProposalSet()
            .stream().flatMap(proposal -> proposal.getThesisConfigurationSet().stream())
            .collect(Collectors.toSet());
    sharedConfigs.add(thesisProposalsConfiguration);

    sharedConfigs.forEach(config -> {
        config.setProposalPeriod(proposalPeriod);
        config.setCandidacyPeriod(candidacyPeriod);

        config.setMaxThesisCandidaciesByStudent(configurationBean.getMaxThesisCandidaciesByStudent());
        config.setMaxThesisProposalsByUser(configurationBean.getMaxThesisProposalsByUser());

        config.setMinECTS1stCycle(configurationBean.getMinECTS1stCycle());
        config.setMinECTS2ndCycle(configurationBean.getMinECTS2ndCycle());
    });

}

From source file:org.fenixedu.learning.domain.executionCourse.LessonBean.java

License:Open Source License

private String isoDate(int dayOfWeek, int hour, int minutes, int seconds) {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minutes);
    calendar.set(Calendar.SECOND, seconds);
    return ISODateTimeFormat.dateTime().print(calendar.getTime().getTime());
}

From source file:org.filteredpush.qc.date.DateUtils.java

License:Apache License

/**
 * Does eventDate match an ISO date that contains a time (including the instant of 
 * midnight (a time with all zero elements)). 
 * //from   w ww .ja v  a2 s . co  m
 * @param eventDate string to check for an ISO date with a time.
 * @return true if eventDate is an ISO date that includes a time, or if eventDate is an 
 * ISO date range either the start or end of which contains a time.  
 */
public static boolean containsTime(String eventDate) {
    boolean result = false;
    if (!isEmpty(eventDate)) {
        if (eventDate.endsWith("UTC")) {
            eventDate = eventDate.replace("UTC", "Z");
        }
        DateTimeParser[] parsers = { ISODateTimeFormat.dateHour().getParser(),
                ISODateTimeFormat.dateTimeParser().getParser(), ISODateTimeFormat.dateHourMinute().getParser(),
                ISODateTimeFormat.dateHourMinuteSecond().getParser(),
                ISODateTimeFormat.dateTime().getParser() };
        DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
        if (eventDate.matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) {
            try {
                LocalDate match = LocalDate.parse(eventDate, formatter);
                result = true;
                logger.debug(match);
            } catch (Exception e) {
                // not a date with a time
                logger.error(e.getMessage());
            }
        }
        if (isRange(eventDate) && eventDate.contains("/") && !result) {
            String[] bits = eventDate.split("/");
            if (bits != null && bits.length > 1) {
                // does either start or end date contain a time?
                if (bits[0].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) {
                    try {
                        LocalDate match = LocalDate.parse(bits[0], formatter);
                        result = true;
                        logger.debug(match);
                    } catch (Exception e) {
                        // not a date with a time
                        logger.error(e.getMessage());
                    }
                }
                if (bits[1].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) {
                    try {
                        LocalDate match = LocalDate.parse(bits[1], formatter);
                        result = true;
                        logger.debug(match);
                    } catch (Exception e) {
                        // not a date with a time
                        logger.error(e.getMessage());
                    }
                }
            }
        }
    }
    return result;
}