package ru.taximaxim.pgsqlblocks.utils;

import org.apache.log4j.Logger;

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

public final class DateUtils {

    private static final Logger LOG = Logger.getLogger(DateUtils.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssX");

    private static final SimpleDateFormat dateFormatWithoutTimeZone = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Date dateFromString(String dateString) {
        if (dateString == null || dateString.isEmpty()) {
            return null;
        }
        Date result = null;
        try {
            result = dateFormat.parse(dateString);
        } catch (ParseException exception) {
            LOG.error(exception.getMessage(), exception);
        }
        return result;
    }

    public static String dateToString(Date date) {
        if (date == null) {
            return "";
        }
        return dateFormatWithoutTimeZone.format(date);
    }

    public static String dateToStringWithTz(Date date) {
        if (date == null) {
            return "";
        }
        return dateFormat.format(date);
    }

    public static int compareDates(Date d1, Date d2) {
        if (d1 == null) {
            return d2 == null ? 0 : -1;
        } else {
            return d2 == null ? 1 : d1.compareTo(d2);
        }
    }
}

@@ -269,39 +269,32 @@
 );%0A%0A    private 
-static 
 final SimpleDate
@@ -355,25 +355,24 @@
 H:mm:ssX%22);%0A
-%0A
     private 
@@ -367,31 +367,24 @@
     private 
-static 
 final Simple
@@ -480,21 +480,27 @@
 public s
-tatic
+ynchronized
  Date da
@@ -866,37 +866,43 @@
  %7D%0A%0A    public s
-tatic
+ynchronized
  String dateToSt
@@ -1054,21 +1054,27 @@
 public s
-tatic
+ynchronized
  String 

Synchronize DateFormat usages due to it being thread unsafe (Sonar S2885)