Search in sources :

Example 1 with DateTimeParseResult

use of org.develnext.jphp.zend.ext.standard.date.DateTimeParseResult in project jphp by jphp-compiler.

the class DateFunctions method date_parse_from_format.

public static Memory date_parse_from_format(Environment env, TraceInfo traceInfo, Memory format, Memory date) {
    try {
        ZoneId zoneId = zoneId(date_default_timezone_get(env, traceInfo));
        DateTimeParseResult result = DateFormat.createParseResultFromFormat(format.toString(), date.toString(), ZonedDateTime.now(zoneId));
        return result.toArrayMemory();
    } catch (DateTimeException | NoSuchElementException | IllegalArgumentException e) {
        return new DateTimeParseResult(null, Collections.emptySet(), null, null).toArrayMemory();
    }
}
Also used : DateTimeException(java.time.DateTimeException) ZoneId(java.time.ZoneId) DateTimeParseResult(org.develnext.jphp.zend.ext.standard.date.DateTimeParseResult) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with DateTimeParseResult

use of org.develnext.jphp.zend.ext.standard.date.DateTimeParseResult in project jphp by jphp-compiler.

the class DateFunctions method __date.

private static Memory __date(Environment env, TraceInfo traceInfo, ZoneId zoneId, String format, long time) {
    ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(time), zoneId);
    DateTimeParseResult parseResult = new DateTimeParseResult(date, Collections.emptySet(), null, null);
    return StringMemory.valueOf(DateFormat.formatForDateFunction(env, parseResult, format));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) DateTimeParseResult(org.develnext.jphp.zend.ext.standard.date.DateTimeParseResult)

Aggregations

DateTimeParseResult (org.develnext.jphp.zend.ext.standard.date.DateTimeParseResult)2 DateTimeException (java.time.DateTimeException)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1 NoSuchElementException (java.util.NoSuchElementException)1