Example usage for org.joda.time DateTime parse

List of usage examples for org.joda.time DateTime parse

Introduction

In this page you can find the example usage for org.joda.time DateTime parse.

Prototype

@FromString
public static DateTime parse(String str) 

Source Link

Document

Parses a DateTime from the specified string.

Usage

From source file:stormy.pythian.model.instance.TextFeature.java

License:Apache License

@Override
public DateFeature toDate() {
    if (value == null) {
        return new DateFeature(null);
    }// w  ww .  j av  a 2 s  .  co m

    try {
        return new DateFeature(DateTime.parse(value).toDate());
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedOperationException(
                "Text feature '" + value + "' can't be converted to date feature", iae);
    }
}

From source file:TVShowTimelineMaker.util.JodaTimeUtil.java

public DateTime readTimeString(String timeString, Chronology inType) {
    DateTime parse = DateTime.parse(timeString);
    return parse.withChronology(inType);
}

From source file:ufjf.GetVideosUFJF.java

public static final Date getDate(String sujeito) throws UnsupportedEncodingException {
    final String DCTERMS = "<dcterms:date>";

    String gsonQodra = requisicaoUFJF(sujeito, DCTERMS);

    String valores[] = gsonQodra.split("values\":");

    DateTime d = DateTime.parse(valores[1].replace("[", "").replaceAll("\"", "").replaceAll("<", "")
            .replaceAll(">", "").replaceAll("}", "").replaceAll("]]", ""));

    Calendar c = Calendar.getInstance();

    Calendar calendar = Calendar.getInstance();
    calendar.set(d.getYear(), d.getMonthOfYear() - 1, d.getDayOfMonth());
    return calendar.getTime();
}

From source file:uk.ac.susx.tag.method51.core.params.codec.concrete.DateTimeCodec.java

License:Apache License

@Override
public DateTime decode(Object value) throws DecodeException {
    if (value instanceof Number) {
        try {//from w  ww.j  a  va2  s  .c o  m
            return new DateTime(((Number) value).longValue());
        } catch (Exception e) {
            throw new DecodeException(e);
        }
    }

    if (value instanceof String) {
        try {
            return DateTime.parse((String) value);
        } catch (Exception e) {
            throw new DecodeException(e);
        }
    }

    throw new DecodeException("Expected number or string, but found " + value.getClass());
}

From source file:uk.co.bubblebearapps.contactsintegration.DateTimeDeserializer.java

License:Open Source License

@Override
public DateTime deserialize(final JsonElement element, final Type type, final JsonDeserializationContext jdc)
        throws JsonParseException

{

    String json = element.getAsString();
    if (json == null || TextUtils.isEmpty(json)) {
        throw new JsonParseException("element was null or empty");
    } else {/*from  w w  w  .  j  a va2 s.c  o m*/
        return DateTime.parse(json);
    }
}

From source file:uk.co.q3c.v7.base.useropt.DefaultUserOption.java

License:Apache License

@Override
public DateTime getOptionAsDateTime(String optionGroup, String option, DateTime defaultValue) {
    String optionValue = userOptionStore.getOptionValue(optionGroup, option);
    if (optionValue == null) {
        return defaultValue;
    } else {//from  ww  w .j  ava2s.c o  m
        try {
            return DateTime.parse(optionValue);
        } catch (Exception e) {
            log.warn("Invalid option value {} for " + optionGroup + "." + option, optionValue);
            return defaultValue;
        }
    }
}

From source file:xcom_server.PacketVerificationService.java

private void StartVerifyingThread(final String srcIP) {
    System.out.println("Starting Verifying thread. IP: " + srcIP);
    new Thread(new Runnable() {

        @Override/*from   w  w w.  j  av a2s  .c o  m*/
        public void run() {
            Packet foundInboundPacket;
            synchronizedPackets.put(srcIP, false);

            while (true) {
                try {
                    foundInboundPacket = null;
                    if (outbound_packets.get(srcIP).size() != 0) {
                        Packet p = outbound_packets.get(srcIP).get(0);
                        //for(Packet inP : inbound_packets.get(srcIP).toArray(new Packet[inbound_packets.get(srcIP).size()]))
                        CopyOnWriteArrayList<Packet> temp = inbound_packets.get(srcIP);
                        if (temp == null) {
                            //System.out.println("SrcIP not found!: "+srcIP);
                            continue;
                        }
                        Object[] objs = (Object[]) temp.toArray();
                        for (Object obj : objs) {
                            Packet inP = (Packet) obj;
                            if (p.hash.equals(inP.hash)) {
                                foundInboundPacket = inP;
                                break;
                            }
                        }
                        if (foundInboundPacket == null) {
                            if (DateTime.parse(p.timespan).isBefore(DateTime.now().minusSeconds(30))) {
                                if (synchronizedPackets.get(srcIP)) {
                                    System.out.println("Lost Packet Outbound: " + p.hash);
                                    lost_packets_outbound.add(p);
                                    AddRowSafeThread(p, false);
                                    outbound_packets.get(srcIP).remove(p);
                                } else {
                                    outbound_packets.get(srcIP).remove(p);
                                }
                            }
                        } else {
                            synchronizedPackets.put(srcIP, true);
                            //System.out.println("Found Packet Outbound: "+ p.hash);
                            inbound_packets.get(srcIP).remove(foundInboundPacket);
                            outbound_packets.get(srcIP).remove(p);
                        }
                    } else {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(PacketVerificationService.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        }
                    }
                } catch (Exception ex) {
                    System.out.println("SrcIP: " + srcIP);
                    throw ex;
                }
            }
        }
    }).start();
}

From source file:xcom_server.PacketVerificationService.java

private void StartLostPacketThread(final String srcIP) {
    new Thread(new Runnable() {

        @Override//from ww w  .  j a  va 2 s.  c  o  m
        public void run() {
            while (true) {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(PacketVerificationService.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (!synchronizedPackets.get(srcIP))
                    continue;
                DateTime nowDT = DateTime.now();
                CopyOnWriteArrayList<Packet> temp = inbound_packets.get(srcIP);
                if (temp == null)
                    continue;
                Object[] objs = (Object[]) temp.toArray();
                for (Object obj : objs)//inbound_packets.get(srcIP).toArray(new Packet[inbound_packets.get(srcIP).size()]))
                {
                    Packet p = (Packet) obj;
                    DateTime dt = DateTime.parse(p.timespan);
                    if (dt.plus(40000).isBefore(nowDT)) {
                        System.out.println("Lost Packet Inbound: " + p.ipPacket.desIP + " " + p.hash);
                        lost_packets_inbound.add(p);
                        AddRowSafeThread(p, true);
                        inbound_packets.get(srcIP).remove(p);
                    }
                }
            }
        }
    }).start();
}