package com.nmakademija.nmaakademija.utils;


import android.support.annotation.Nullable;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateUtils {

    private static final String DATE_FORMAT_PATTERN_TZ = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    private static final String TIME_FORMAT_PATTERN = "HH:mm";

    private static final ThreadLocal<SimpleDateFormat> TIME_FORMAT = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(TIME_FORMAT_PATTERN, Locale.US);
        }
    };

    private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(DATE_FORMAT_PATTERN_TZ, Locale.US);
        }
    };

    static {
        DATE_FORMAT.get().setTimeZone(TimeZone.getTimeZone("UTC"));
        TIME_FORMAT.get().setTimeZone(TimeZone.getDefault());
    }

    @Nullable
    public static Date parseTZDate(String pattern) {
        try {
            return DATE_FORMAT.get().parse(pattern);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Nullable
    public static String formatTime(@Nullable Date date) {
        if (date == null) {
            return null;
        }

        return TIME_FORMAT.get().format(date);
    }


}

@@ -584,38 +584,61 @@
 ) %7B%0A            
-return
+SimpleDateFormat dateFormat =
  new SimpleDateF
@@ -668,32 +668,122 @@
 RN, Locale.US);%0A
+            dateFormat.setTimeZone(TimeZone.getDefault());%0A            return dateFormat;%0A
         %7D%0A    %7D;
@@ -973,22 +973,45 @@
         
-return
+SimpleDateFormat dateFormat =
  new Sim
@@ -1072,56 +1072,22 @@
     
-%7D%0A
     
-%7D;%0A%0A    static %7B%0A        DATE_FORMAT.get()
+dateFormat
 .set
@@ -1137,67 +1137,47 @@
     
-TIME_FORMAT.get().setTimeZone(TimeZone.getDefault());%0A    %7D
+    return dateFormat;%0A        %7D%0A    %7D;
 %0A%0A  
@@ -1611,11 +1611,10 @@
 %0A    %7D%0A%0A
-%0A
 %7D%0A

move setTimeZone to initialValue