Example usage for org.joda.time LocalDateTime toString

List of usage examples for org.joda.time LocalDateTime toString

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime toString.

Prototype

@ToString
public String toString() 

Source Link

Document

Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSS).

Usage

From source file:ca.ualberta.physics.cssdp.jaxb.LocalDateTimeAdapter.java

License:Apache License

public String marshal(LocalDateTime v) throws Exception {
    return v.toString();
}

From source file:ca.ualberta.physics.cssdp.util.JSONLocalDateTimeSerializer.java

License:Apache License

@Override
public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    jgen.writeString(value.toString());
}

From source file:cherry.sqlman.tool.metadata.MetadataServiceImpl.java

License:Apache License

@Transactional
@Override/*from  w w w.j ava  2  s. c  o  m*/
public int create(SqlType sqlType, String ownedBy) {
    LocalDateTime now = bizDateTime.now();
    BSqlMetadata record = new BSqlMetadata();
    record.setSqlType(sqlType.code());
    record.setName(now.toString());
    record.setDescription(now.toString());
    record.setOwnedBy(ownedBy);
    record.setRegisteredAt(now);
    record.setChangedAt(now);
    Integer id = queryFactory.insert(m).populate(record).executeWithKey(m.id);
    checkState(id != null, "failed to create %s: %s", m.getTableName(), record);
    return id.intValue();
}

From source file:com.axelor.apps.tool.xml.DateToXML.java

License:Open Source License

public static XMLGregorianCalendar convert(LocalDateTime in) {

    XMLGregorianCalendar date = null;

    try {/*  ww  w. j a  va 2 s . c  o  m*/

        date = DatatypeFactory.newInstance().newXMLGregorianCalendar(in.toString());

    } catch (DatatypeConfigurationException e) {

        LOG.error(e.getMessage());

    }

    return date;
}

From source file:com.axelor.csv.script.ImportDateTime.java

License:Open Source License

public String importDateTime(String inputDateTime) {
    String tm = "[0-9]{2}:[0-9]{2}:[0-9]{2}";
    String patTime = "(" + dt + " " + tm + "|NOW)(\\[(" + String.format(pat, 4, "y") + "?"
            + String.format(pat, 2, "M") + "?" + String.format(pat, 2, "d") + "?" + String.format(pat, 2, "H")
            + "?" + String.format(pat, 2, "m") + "?" + String.format(pat, 2, "s") + "?" + ")\\])?";
    try {//  w  w  w  .  j  ava2s.c  o m
        if (!Strings.isNullOrEmpty(inputDateTime) && inputDateTime.matches(patTime)) {
            List<String> timeList = Arrays.asList(inputDateTime.split("\\["));
            inputDateTime = timeList.get(0).equals("NOW") ? new LocalDateTime().toString("yyyy-MM-dd HH:mm:ss")
                    : timeList.get(0);
            if (timeList.size() > 1) {
                LocalDateTime dateTime = new LocalDateTime(inputDateTime.replace(" ", "T"));
                Matcher matcher = Pattern.compile(String.format(pat, 4, "y")).matcher(timeList.get(1));
                if (matcher.find())
                    dateTime = updateYear(dateTime, matcher.group());
                matcher = Pattern.compile(String.format(pat, 2, "M")).matcher(timeList.get(1));
                if (matcher.find())
                    dateTime = updateMonth(dateTime, matcher.group());
                matcher = Pattern.compile(String.format(pat, 2, "d")).matcher(timeList.get(1));
                if (matcher.find())
                    dateTime = updateDay(dateTime, matcher.group());
                matcher = Pattern.compile(String.format(pat, 2, "H")).matcher(timeList.get(1));
                if (matcher.find())
                    dateTime = updateHour(dateTime, matcher.group());
                matcher = Pattern.compile(String.format(pat, 2, "m")).matcher(timeList.get(1));
                if (matcher.find())
                    dateTime = updateMinute(dateTime, matcher.group());
                matcher = Pattern.compile(String.format(pat, 2, "s")).matcher(timeList.get(1));
                if (matcher.find())
                    dateTime = updateSecond(dateTime, matcher.group());
                return dateTime.toString();
            }
            return inputDateTime.replace(" ", "T");
        }
        return null;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.dalendev.meteotndata.general.LocalDateTimeAdapter.java

License:Open Source License

public static String marshal(LocalDateTime v) {
    return v.toString();
}

From source file:com.ephemeraldreams.gallyshuttle.ui.MainFragment.java

License:Apache License

/**
 * Calculate time difference in milliseconds between now and next available shuttle arrival time.
 *
 * @param stationId Station id to get times from.
 * @return Duration between now and next arrival time in milliseconds.
 *//*from ww w.j  ava2s  .c o  m*/
private long calculateTimeFromNowToNextArrivalAtStation(int stationId) {
    List<String> times = schedule.getTimes(stationId);
    LocalDateTime now = LocalDateTime.now();
    arrivalTime = null;
    LocalDateTime stationTime;
    for (String time : times) {
        stationTime = DateUtils.parseToLocalDateTime(time);
        Timber.d(stationTime.toString());

        //Workaround midnight exception case where station time was converted to midnight of current day instead of next day.
        if (stationTime.getHourOfDay() == 0 && now.getHourOfDay() != 0) {
            stationTime = stationTime.plusDays(1);
        }
        if (now.isBefore(stationTime)) {
            arrivalTime = stationTime;
            break;
        }
    }
    if (arrivalTime == null) {
        arrivalTimeTextView.setText(getString(R.string.arrival_not_available_message));
        return -1;
    } else {
        arrivalTimeTextView.setText(String.format(getString(R.string.until_arrival_time_message),
                DateUtils.formatTime(arrivalTime)));

        Duration duration = new Duration(now.toDateTime(), arrivalTime.toDateTime());
        long milliseconds = duration.getMillis();

        Timber.d("Now: " + DateUtils.formatTime(now));
        Timber.d("Arrival: " + DateUtils.formatTime(arrivalTime));
        Timber.d("Time difference between now and arrival: "
                + DateUtils.convertMillisecondsToTime(milliseconds));

        return milliseconds;
    }
}

From source file:com.fns.grivet.api.GrivetApiClientIT.java

License:Apache License

@Test
@Disabled("Cannot test w/ H2")
public void testNamedQueryRegistrationAndRetrievalSprocHappyPath() {
    registerTestType();/*from w w  w. j av  a  2s .c om*/
    Resource r = resolver.getResource("classpath:TestSprocQuery.json");
    try {
        String sproc = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        given().contentType("application/json").request().body(sproc).then().expect().statusCode(equalTo(204))
                .when().post("/api/v1/query");
        LocalDateTime now = LocalDateTime.now();
        Response response = given().contentType("application/json").request().then().expect()
                .statusCode(equalTo(200)).when()
                .get("/api/v1/query/sproc.getAttributesCreatedBefore?createdTime=" + now.toString());
        JSONArray result = new JSONArray(response.body().asString());
        Assertions.assertEquals(7, result.length());
        given().contentType("application/json").request().then().expect().statusCode(equalTo(204)).when()
                .delete("/api/v1/query/sproc.getAttributesCreatedBefore");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    deregisterType();
}

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

@Override
@CronTarget(jobName = JobName.UPDATE_SMS_OUTBOUND_WITH_CAMPAIGN_MESSAGE)
public void storeTemplateMessageIntoSmsOutBoundTable() throws JobExecutionException {
    final Collection<SmsCampaign> smsCampaignDataCollection = this.smsCampaignRepository
            .findByCampaignTypeAndTriggerTypeAndStatus(CampaignType.SMS.getValue(),
                    SmsCampaignTriggerType.SCHEDULE.getValue(), SmsCampaignStatus.ACTIVE.getValue());
    if (smsCampaignDataCollection != null) {
        for (SmsCampaign smsCampaign : smsCampaignDataCollection) {
            LocalDateTime tenantDateNow = tenantDateTime();
            LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate();

            logger.info("tenant time " + tenantDateNow.toString() + " trigger time "
                    + nextTriggerDate.toString() + JobName.UPDATE_SMS_OUTBOUND_WITH_CAMPAIGN_MESSAGE.name());
            if (nextTriggerDate.isBefore(tenantDateNow)) {
                insertDirectCampaignIntoSmsOutboundTable(smsCampaign);
                this.updateTriggerDates(smsCampaign.getId());
            }/*from   w w w . ja  v a  2  s .  c om*/
        }
    }
}

From source file:com.gst.infrastructure.dataqueries.service.ReadWriteNonCoreDataServiceImpl.java

License:Apache License

private String validateColumn(final ResultsetColumnHeaderData columnHeader, final String pValue,
        final String dateFormat, final Locale clientApplicationLocale) {

    String paramValue = pValue;/*from w  w w  .  j a  v  a2s  .c om*/
    if (columnHeader.isDateDisplayType() || columnHeader.isDateTimeDisplayType()
            || columnHeader.isIntegerDisplayType() || columnHeader.isDecimalDisplayType()
            || columnHeader.isBooleanDisplayType()) {
        // only trim if string is not empty and is not null.
        // throws a NULL pointer exception if the check below is not applied
        paramValue = StringUtils.isNotEmpty(paramValue) ? paramValue.trim() : paramValue;
    }

    if (StringUtils.isEmpty(paramValue) && columnHeader.isMandatory()) {

        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        final ApiParameterError error = ApiParameterError.parameterError("error.msg.column.mandatory",
                "Mandatory", columnHeader.getColumnName());
        dataValidationErrors.add(error);
        throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
                "Validation errors exist.", dataValidationErrors);
    }

    if (StringUtils.isNotEmpty(paramValue)) {

        if (columnHeader.hasColumnValues()) {
            if (columnHeader.isCodeValueDisplayType()) {

                if (columnHeader.isColumnValueNotAllowed(paramValue)) {
                    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                    final ApiParameterError error = ApiParameterError.parameterError(
                            "error.msg.invalid.columnValue", "Value not found in Allowed Value list",
                            columnHeader.getColumnName(), paramValue);
                    dataValidationErrors.add(error);
                    throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
                            "Validation errors exist.", dataValidationErrors);
                }

                return paramValue;
            } else if (columnHeader.isCodeLookupDisplayType()) {

                final Integer codeLookup = Integer.valueOf(paramValue);
                if (columnHeader.isColumnCodeNotAllowed(codeLookup)) {
                    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                    final ApiParameterError error = ApiParameterError.parameterError(
                            "error.msg.invalid.columnValue", "Value not found in Allowed Value list",
                            columnHeader.getColumnName(), paramValue);
                    dataValidationErrors.add(error);
                    throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
                            "Validation errors exist.", dataValidationErrors);
                }

                return paramValue;
            } else {
                throw new PlatformDataIntegrityException("error.msg.invalid.columnType.",
                        "Code: " + columnHeader.getColumnName() + " - Invalid Type "
                                + columnHeader.getColumnType() + " (neither varchar nor int)");
            }
        }

        if (columnHeader.isDateDisplayType()) {
            final LocalDate tmpDate = JsonParserHelper.convertFrom(paramValue, columnHeader.getColumnName(),
                    dateFormat, clientApplicationLocale);
            if (tmpDate == null) {
                paramValue = null;
            } else {
                paramValue = tmpDate.toString();
            }
        } else if (columnHeader.isDateTimeDisplayType()) {
            final LocalDateTime tmpDateTime = JsonParserHelper.convertDateTimeFrom(paramValue,
                    columnHeader.getColumnName(), dateFormat, clientApplicationLocale);
            if (tmpDateTime == null) {
                paramValue = null;
            } else {
                paramValue = tmpDateTime.toString();
            }
        } else if (columnHeader.isIntegerDisplayType()) {
            final Integer tmpInt = this.helper.convertToInteger(paramValue, columnHeader.getColumnName(),
                    clientApplicationLocale);
            if (tmpInt == null) {
                paramValue = null;
            } else {
                paramValue = tmpInt.toString();
            }
        } else if (columnHeader.isDecimalDisplayType()) {
            final BigDecimal tmpDecimal = this.helper.convertFrom(paramValue, columnHeader.getColumnName(),
                    clientApplicationLocale);
            if (tmpDecimal == null) {
                paramValue = null;
            } else {
                paramValue = tmpDecimal.toString();
            }
        } else if (columnHeader.isBooleanDisplayType()) {

            final Boolean tmpBoolean = BooleanUtils.toBooleanObject(paramValue);
            if (tmpBoolean == null) {
                final ApiParameterError error = ApiParameterError.parameterError(
                        "validation.msg.invalid.boolean.format", "The parameter " + columnHeader.getColumnName()
                                + " has value: " + paramValue + " which is invalid boolean value.",
                        columnHeader.getColumnName(), paramValue);
                final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                dataValidationErrors.add(error);
                throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
                        "Validation errors exist.", dataValidationErrors);
            }
            paramValue = tmpBoolean.toString();
        } else if (columnHeader.isString()) {
            if (paramValue.length() > columnHeader.getColumnLength()) {
                final ApiParameterError error = ApiParameterError.parameterError(
                        "validation.msg.datatable.entry.column.exceeds.maxlength",
                        "The column `" + columnHeader.getColumnName() + "` exceeds its defined max-length ",
                        columnHeader.getColumnName(), paramValue);
                final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                dataValidationErrors.add(error);
                throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
                        "Validation errors exist.", dataValidationErrors);
            }
        }
    }

    return paramValue;
}