package pax.TrainsSchedule.Util;

import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class Util {

    public static String todayStr() {
        Calendar calendar = Calendar.getInstance();
        String sb = String.valueOf(calendar.get(Calendar.YEAR)) +
                "-" +
                (calendar.get(Calendar.MONTH) + 1) +
                "-" +
                calendar.get(Calendar.DAY_OF_MONTH);
        return sb;
    }

    public static String tomorrowStr() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, 1);

        String sb = String.valueOf(calendar.get(Calendar.YEAR)) +
                "-" +
                (calendar.get(Calendar.MONTH) + 1) +
                "-" +
                calendar.get(Calendar.DAY_OF_MONTH);
        return sb;
    }

    public static String todayDayOfWeek() {
        Calendar calendar = Calendar.getInstance();
        return "" + calendar.get(Calendar.DAY_OF_WEEK);
    }

    public static String tomorrowDayOfWeek() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        return "" + calendar.get(Calendar.DAY_OF_WEEK);
    }

    public static boolean notEmpty(Object o) {
        if (o == null) return false;
        return !(o instanceof String && ((String) o).isEmpty());

    }

    public static String getDateRepresentation(long date) {

        GregorianCalendar cur = new GregorianCalendar();
        GregorianCalendar c = new GregorianCalendar();
        c.setTimeInMillis(date);
        if (c.get(Calendar.YEAR) == cur.get(Calendar.YEAR) &&
                c.get(Calendar.MONTH) == cur.get(Calendar.MONTH) &&
                c.get(Calendar.DAY_OF_MONTH) == cur.get(Calendar.DAY_OF_MONTH)) {
            return Multilanguage.onToday;
        }

        cur.add(Calendar.DAY_OF_MONTH, 1);
        if (c.get(Calendar.YEAR) == cur.get(Calendar.YEAR) &&
                c.get(Calendar.MONTH) == cur.get(Calendar.MONTH) &&
                c.get(Calendar.DAY_OF_MONTH) == cur.get(Calendar.DAY_OF_MONTH)) {
            return Multilanguage.onTomorrow;
        }

        Date dDate = new Date(date);

        DateFormatSymbols RU_SYMBOLS = new DateFormatSymbols(new Locale("ru"));
        String[] RU_MONTHS = {"января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"};

        RU_SYMBOLS.setMonths(RU_MONTHS);

        SimpleDateFormat df = new SimpleDateFormat("dd MMMM", RU_SYMBOLS);
        return "На " + df.format(dDate);

    }

    public static String getDateRepresentation(int year, int month, int day) {
        GregorianCalendar c = new GregorianCalendar();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month);
        c.set(Calendar.DAY_OF_MONTH, day);

        return getDateRepresentation(c.getTimeInMillis());
    }

    public static String getDateForSearch(long date) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        return df.format(new Date(date));
    }

    public static int getDayOfWeek(String date) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
        Calendar c = Calendar.getInstance();
        try {
            c.setTime(format.parse(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return c.get(Calendar.DAY_OF_WEEK);
    }

    public static int getDayOfWeek(long date) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date);
        return c.get(Calendar.DAY_OF_WEEK);
    }
}

@@ -2358,281 +2358,8 @@
 e);%0A
-%0A        DateFormatSymbols RU_SYMBOLS = new DateFormatSymbols(new Locale(%22ru%22));%0A        String%5B%5D RU_MONTHS = %7B%22%D1%8F%D0%BD%D0%B2%D0%B0%D1%80%D1%8F%22, %22%D1%84%D0%B5%D0%B2%D1%80%D0%B0%D0%BB%D1%8F%22, %22%D0%BC%D0%B0%D1%80%D1%82%D0%B0%22, %22%D0%B0%D0%BF%D1%80%D0%B5%D0%BB%D1%8F%22, %22%D0%BC%D0%B0%D1%8F%22, %22%D0%B8%D1%8E%D0%BD%D1%8F%22, %22%D0%B8%D1%8E%D0%BB%D1%8F%22, %22%D0%B0%D0%B2%D0%B3%D1%83%D1%81%D1%82%D0%B0%22, %22%D1%81%D0%B5%D0%BD%D1%82%D1%8F%D0%B1%D1%80%D1%8F%22, %22%D0%BE%D0%BA%D1%82%D1%8F%D0%B1%D1%80%D1%8F%22, %22%D0%BD%D0%BE%D1%8F%D0%B1%D1%80%D1%8F%22, %22%D0%B4%D0%B5%D0%BA%D0%B0%D0%B1%D1%80%D1%8F%22%7D;%0A%0A        RU_SYMBOLS.setMonths(RU_MONTHS);%0A%0A
     
@@ -2420,39 +2420,65 @@
 M%22, 
-RU_SYMBOLS);%0A        return %22%D0%9D%D0%B0
+Locale.getDefault());%0A        return Multilanguage.on + %22
  %22 +
@@ -2496,17 +2496,16 @@
 dDate);%0A
-%0A
     %7D%0A%0A 

Update Util.java