List of usage examples for org.joda.time DateTime parse
@FromString public static DateTime parse(String str)
From source file:access.database.DatabaseAccessor.java
License:Apache License
/** * Updates the Expiration date for the Lease. * /*from w w w.j a v a2 s .co m*/ * @param leaseId * The Id of the lease to update. * @param expirationDate * The new Expiration date. ISO8601 String. */ public void updateLeaseExpirationDate(String leaseId, String expirationDate) { LeaseEntity record = leaseDao.findOneLeaseById(leaseId); if (record != null) { record.getLease().setExpiresOn(DateTime.parse(expirationDate)); } leaseDao.save(record); }
From source file:annis.adapter.DateTimeAdapter.java
License:Apache License
@Override public DateTime unmarshal(String v) throws Exception { return DateTime.parse(v); }
From source file:annis.security.User.java
License:Apache License
/** * Constructs a represention from the contents of an an ANNIS * user file. /* ww w .j a va 2 s .co m*/ * @param name * @param props */ public User(String name, Properties props) { this.name = name; this.passwordHash = props.getProperty("password"); String groupsRaw = props.getProperty("groups", ""); for (String g : Splitter.on(",").trimResults().omitEmptyStrings().split(groupsRaw)) { this.groups.add(g); } // add manual permissions String permsRaw = props.getProperty("permissions", ""); for (String g : Splitter.on(",").trimResults().omitEmptyStrings().split(permsRaw)) { this.permissions.add(g); } String dateRaw = props.getProperty("expires"); if (dateRaw != null) { try { expires = DateTime.parse(dateRaw); } catch (IllegalArgumentException ex) { expires = null; } } }
From source file:br.com.moonjava.flight.util.FormatDateTime.java
License:Apache License
public static DateTime parseToDateTime(String value) { try {/*from w w w . j ava 2 s .c om*/ Date date = new SimpleDateFormat("MM/dd/yyyy hh:mm aa").parse(value); String format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(date); return DateTime.parse(format); } catch (ParseException e) { try { Date date = new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(value); String format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(date); return DateTime.parse(format); } catch (ParseException e1) { throw new RuntimeException(e); } } }
From source file:br.com.moonjava.flight.util.FormatDateTimeDesk.java
License:Apache License
public static DateTime parseToDateTime(String value, String country) { try {// www . j a v a 2s .co m Date date = null; if (country.equals("US")) { date = new SimpleDateFormat("MM/dd/yyyy hh:mm aa").parse(value); } else { date = new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(value); } String format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(date); return DateTime.parse(format); } catch (ParseException e) { throw new RuntimeException(e); } }
From source file:ch.rasc.portaldemos.scheduler.ISO8601DateTimeDeserializer.java
License:Apache License
@Override public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { return DateTime.parse(jp.getText()); }
From source file:coffeepot.bean.wr.writer.customHandler.DateTimeHandler.java
License:Apache License
@Override public DateTime parse(String text) throws HandlerParseException { if (text == null || text.isEmpty()) { return null; }/*from w w w. j a va 2 s .c o m*/ try { return DateTime.parse(text); } catch (Exception ex) { throw new HandlerParseException(ex.getMessage()); } }
From source file:com.almende.eve.transport.tokens.TokenStore.java
License:Apache License
/** * Creates the.//from ww w . j a v a 2 s . c om * * @return the token ret */ public TokenRet create() { TokenRet result; if (tokens.size() == 0 || tokens.get(last.toString()) == null || last.plus(3600000).isBeforeNow()) { final DateTime now = DateTime.now(); final String token = new UUID().toString(); result = new TokenRet(token, now); tokens.put(now.toString(), token); last = now; if (tokens.size() > SIZE + 2) { DateTime oldest = last; for (final String time : tokens.keySet()) { try { if (DateTime.parse(time).isBefore(oldest)) { oldest = DateTime.parse(time); } } catch (final Exception e) { LOG.log(Level.WARNING, "Failed in eviction of tokens:", e); } } tokens.remove(oldest.toString()); } } else { result = new TokenRet(tokens.get(last.toString()), last); } return result; }
From source file:com.almende.timecontrol.time.TriggerPattern.java
License:Apache License
/** * @param measure/*from ww w . ja va2 s . c o m*/ * @return * * @see CronScheduleBuilder#cronSchedule(String) * @see DateTimeIteratorFactory#createDateTimeIterable(String, * ReadableDateTime, DateTimeZone, boolean) */ public static final Observable<Instant> parseInstantOrIntervalOrRule(final String json) { try { // example: "0/20 * * * * ?" final CronTrigger trigger = TriggerBuilder.newTrigger() .withSchedule(CronScheduleBuilder.cronSchedule(json)).build(); return Observable.create(new Observable.OnSubscribe<Instant>() { @Override public void call(final Subscriber<? super Instant> sub) { Date current = trigger.getStartTime(); while (current != null) { sub.onNext(Instant.valueOf(current.getTime())); current = trigger.getFireTimeAfter(current); } } }); } catch (final Exception e) { try { final boolean strict = false; // String ical = // "DTSTART;TZID=US-Eastern:19970902T090000\r\n"+"RRULE:FREQ=DAILY;" // + "UNTIL=20130430T083000Z;" // + "INTERVAL=1;"; // FIXME parse DTSTART (see // http://www.kanzaki.com/docs/ical/rrule.html) final DateTimeZone zone = DateTimeZone.forID(dtStartZonePattern.matcher(json).group()); final DateTime start = DateTime.parse(dtStartTimePattern.matcher(json).group()).withZone(zone); // convert DateTime to Instant return Observable.from(DateTimeIteratorFactory.createDateTimeIterable(json, start, zone, strict)) .map(new Func1<DateTime, Instant>() { @Override public Instant call(final DateTime dt) { return Instant.valueOf(dt); } }); } catch (final Exception e1) { return Observable.just(Instant.valueOf(json)); } } }
From source file:com.almende.util.tokens.TokenStore.java
License:Apache License
/** * Creates the.//from w w w.ja v a2 s. c om * * @return the token ret */ public static TokenRet create() { synchronized (tokens) { TokenRet result; if (tokens.size() == 0 || tokens.get(last.toString(), String.class) == null || last.plus(3600000).isBeforeNow()) { final DateTime now = DateTime.now(); final String token = new UUID().toString(); result = new TokenRet(token, now); tokens.put(now.toString(), token); last = now; if (tokens.size() > SIZE + 2) { DateTime oldest = last; for (final String time : tokens.keySet()) { try { if (time.equals(State.KEY_AGENT_TYPE)) { continue; } if (DateTime.parse(time).isBefore(oldest)) { oldest = DateTime.parse(time); } } catch (final Exception e) { LOG.log(Level.WARNING, "Failed in eviction of tokens:", e); } } tokens.remove(oldest.toString()); } } else { result = new TokenRet(tokens.get(last.toString(), String.class), last); } return result; } }