
package org.datazup.utils;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Locale;


/**
 * Created by ninel on 11/25/16.
 */

public class DateTimeUtils {

    public static DateTime resolve(Object obj){
        if (obj instanceof DateTime){
            return (DateTime)obj;
        }
        else if (obj instanceof Long)
            return resolve((Long)obj);
        else if (obj instanceof String){
            try {
                DateTime dt = resolve((String) obj, "EEE MMM dd HH:mm:ss Z yyyy");

                return dt;
            }catch (Exception e){
                try {
                    DateTime dt1 = resolve((String) obj);
                    return dt1;
                }catch (Exception e1){

                }
            }
        }
        return null;
    }

    public static DateTime resolve(Long timestamp){
        return new DateTime(timestamp);
    }

    public static DateTime resolve(String datetime){
        return new DateTime(datetime);
    }

    public static DateTime resolve(String datetime, String format){
        DateTimeFormatter fmt = DateTimeFormat.forPattern(format).withLocale(Locale.ENGLISH);
        DateTime dt = fmt.parseDateTime(datetime).toDateTime(DateTimeZone.UTC);
        return dt;
    }
}

@@ -686,24 +686,25 @@
 ception e)%7B%0A
+%0A
             
@@ -702,35 +702,219 @@
              try
- 
 %7B%0A
+                    DateTime dt = resolve((String)obj, %22yyyy-MM-dd hh:mm:ss.sss%22);%0A                    return  dt;%0A                %7Dcatch (Exception e1)%7B%0A%0A                    try %7B%0A    
                 
@@ -967,32 +967,36 @@
                 
+    
 return dt1;%0A    
@@ -999,32 +999,36 @@
                 
+  
+  
 %7Dcatch (Exceptio
@@ -1022,33 +1022,33 @@
 tch (Exception e
-1
+2
 )%7B%0A%0A            
@@ -1043,33 +1043,56 @@
                 
+   
-%7D
+ %7D%0A                %7D%0A
 %0A            %7D%0A 

update datetime format utils