Example usage for org.joda.time DateTime getDayOfWeek

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

Introduction

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

Prototype

public int getDayOfWeek() 

Source Link

Document

Get the day of week field value.

Usage

From source file:javaapplication1.GenerateTest2DK.java

public static void main(String[] args) throws IOException {
    int episodeNumber = 0;
    BufferedReader buffreader = null;
    try {//from  w w w .  j  a v  a 2s  .  c  o m
        // open the file for reading
        InputStream fis = new FileInputStream("kuasha-episode.txt");

        // if file the available for reading
        if (fis != null) {

            // prepare the file for reading
            InputStreamReader chapterReader = new InputStreamReader(fis);
            buffreader = new BufferedReader(chapterReader);

            String line = null;
            while (true) {
                try {
                    line = buffreader.readLine();

                } catch (Exception e) {

                }

                if (line == null)
                    break;

                songPath.add(line);
                episodeNumber++;
            }

            /*String line;
                    
            // read every line of the file into the line-variable, on line at the time
            do {
               line = buffreader.readLine();
              // do something with the line 
               System.out.println(line);
            } while (line != null);
              */

        }
    } catch (Exception e) {

    } finally {

    }

    String[] monthStr2 = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nove",
            "Dec" };

    String[] monthStr = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December" };

    String[] urlImage = { "http://i.imgur.com/Pks8tmU.jpg", "http://i.imgur.com/UHv8tdw.jpg",
            "http://i.imgur.com/AybMRiN.jpg", "http://i.imgur.com/J7gMxN4.jpg",
            "http://i.imgur.com/8C3N9lN.jpg", "http://i.imgur.com/p5RjLUq.jpg", "http://i.imgur.com/vp97ZQe.jpg"

    };

    List<DateTime> fridays = new ArrayList<>();
    boolean reachedAFriday = false;

    String start = "12/08/2010";
    String end = "01/02/2011";
    DateTimeFormatter pattern = DateTimeFormat.forPattern("dd/mm/yyyy");
    DateTime startDate = new DateTime();//(2018, 06, 22, 0, 0, 0, 0);//pattern.parseDateTime(start); // year-month-day
    DateTime endDate = new DateTime(2010, 1, 1, 0, 0, 0, 0);//pattern.parseDateTime(end);

    int startRange = 0;
    int yearID = 0;
    int albumID = 0;
    int songID = 0;

    String url = "{\"albumList\":[";
    String prevYear = "";

    Random r = new Random();
    int i1 = (r.nextInt(80) + 65);
    while (startDate.isAfter(endDate)) {
        if (songID >= episodeNumber)
            break;
        String dayOfYaer = "" + startDate.getYear();

        if (!prevYear.equals(dayOfYaer)) {
            url += "{\"yearID\":\"" + yearID + "\", \"yearName\":\"" + "YEAR-" + dayOfYaer
                    + "\", \"monthList\":[";
            prevYear = "" + startDate.getYear();
            yearID++;
        }

        String dayOfMonth = "" + monthStr[startDate.getMonthOfYear() - 1];
        url += "{\"albumID\":\"" + albumID + "\", \"albumName\":\"" + "" + dayOfMonth + "\", \"songList\":["; //+"Month-"+startDate.dayOfMonth() +"\"},";
        //System.out.println("fahad -- "+ (startDate.getDayOfMonth()-1));
        if (startRange == 0)
            startRange = songID;
        while ((monthStr[startDate.getMonthOfYear() - 1]).equals(dayOfMonth)) {
            if (songID >= episodeNumber)
                break;
            if (startDate.getDayOfWeek() == DateTimeConstants.MONDAY) {
                fridays.add(startDate);
                reachedAFriday = true;

                String MothWithTwoDigit = String.format("%02d", startDate.getMonthOfYear());
                String dateWithTwoDigit = String.format("%02d", startDate.getDayOfMonth());

                String date = startDate.getYear() + "-" + MothWithTwoDigit + "-" + dateWithTwoDigit;
                String EpisodesName = "Ep-" + dateWithTwoDigit + " " + monthStr2[startDate.getMonthOfYear() - 1]
                        + "," + startDate.getYear();
                if (songID == 0)
                    EpisodesName = "(New)" + EpisodesName;

                path = songPath.get(episodeNumber - songID - 1);//"http://dl.bhoot-fm.com/Bhoot-FM_"+date+"_(Bhoot-FM.com).mp3";
                artist = "Kuasha";
                composer = "ABC-Radio";
                imageUrl = urlImage[r.nextInt(7)];//"http://3.bp.blogspot.com/-nd09lbpK1Mk/U7hkntBHF4I/AAAAAAAAAM8/FFsAfjT9tW8/s1600/bhoot.jpg";

                url += "{\"songID\":\"" + songID + "\", \"title\":\"" + EpisodesName + "\", \"artist\":\""
                        + artist + "\", \"path\":\"" + path + "\", \"albumId\":\"" + albumID
                        + "\", \"composer\":\"" + composer + "\", \"imageUrl\":\"" + imageUrl + "\"},";

                songID++;
            }
            if (reachedAFriday) {
                startDate = startDate.minusWeeks(1);
            } else {
                startDate = startDate.minusDays(1);
            }

            System.out.println("fahad -- " + (startDate.getDayOfMonth() - 1));
        }

        albumID++;
        url = url.substring(0, url.length() - 1) + "], \"songListRange\":\"" + startRange + "-" + (songID - 1)
                + "\"},";

        startRange = 0;

        if (!prevYear.equals("" + startDate.getYear())) {
            url = url.substring(0, url.length() - 1) + "]},";
            //prevYear = dayOfYaer;
        }
    }

    url = url.substring(0, url.length() - 1) + "]}]}";//]}
    System.out.println(url);

    File file = new File("filename_kuasha.txt");

    // if file doesnt exists, then create it
    if (!file.exists()) {
        file.createNewFile();
    }

    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(url);
    bw.close();

    System.out.println("Done");

}

From source file:javaapplication1.GenerateTest2Dor.java

public static void main(String[] args) throws IOException {
    BufferedReader buffreader = null;
    try {//from   w  ww  .j  av a 2 s.  c om
        // open the file for reading
        InputStream fis = new FileInputStream("Dor.txt");

        // if file the available for reading
        if (fis != null) {

            // prepare the file for reading
            InputStreamReader chapterReader = new InputStreamReader(fis);
            buffreader = new BufferedReader(chapterReader);

            String line = null;
            while (true) {
                try {
                    line = buffreader.readLine();

                } catch (Exception e) {

                }

                if (line == null)
                    break;

                songPath.add(line);

            }

            /*String line;
                    
            // read every line of the file into the line-variable, on line at the time
            do {
               line = buffreader.readLine();
              // do something with the line 
               System.out.println(line);
            } while (line != null);
              */

        }
    } catch (Exception e) {

    } finally {

    }

    String[] monthStr2 = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nove",
            "Dec" };

    String[] monthStr = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December" };

    String[] urlImage = { "http://i.imgur.com/DMmPf5f.jpg", "http://i.imgur.com/8C3N9lN.jpg",
            "http://i.imgur.com/MGQSXb1.jpg", "http://i.imgur.com/nyv8gOD.jpg",
            "http://i.imgur.com/kzr9p5M.jpg", "http://i.imgur.com/nBTPbty.jpg", "http://i.imgur.com/VvLI4sY.jpg"

    };

    List<DateTime> fridays = new ArrayList<>();
    boolean reachedAFriday = false;

    String start = "12/08/2010";
    String end = "01/02/2011";
    DateTimeFormatter pattern = DateTimeFormat.forPattern("dd/mm/yyyy");
    DateTime startDate = new DateTime(2018, 03, 03, 0, 0, 0, 0);//pattern.parseDateTime(start); // year-month-day
    DateTime endDate = new DateTime(2010, 1, 1, 0, 0, 0, 0);//pattern.parseDateTime(end);

    int startRange = 0;
    int yearID = 0;
    int albumID = 0;
    int songID = 0;
    int episodeNumber = 172;
    String url = "{\"albumList\":[";
    String prevYear = "";

    Random r = new Random();
    int i1 = (r.nextInt(80) + 65);
    while (startDate.isAfter(endDate)) {
        if (songID >= episodeNumber)
            break;
        String dayOfYaer = "" + startDate.getYear();

        if (!prevYear.equals(dayOfYaer)) {
            url += "{\"yearID\":\"" + yearID + "\", \"yearName\":\"" + "YEAR-" + dayOfYaer
                    + "\", \"monthList\":[";
            prevYear = "" + startDate.getYear();
            yearID++;
        }

        String dayOfMonth = "" + monthStr[startDate.getMonthOfYear() - 1];
        url += "{\"albumID\":\"" + albumID + "\", \"albumName\":\"" + "" + dayOfMonth + "\", \"songList\":["; //+"Month-"+startDate.dayOfMonth() +"\"},";
        //System.out.println("fahad -- "+ (startDate.getDayOfMonth()-1));
        if (startRange == 0)
            startRange = songID;
        while ((monthStr[startDate.getMonthOfYear() - 1]).equals(dayOfMonth)) {
            if (songID >= episodeNumber)
                break;
            if (startDate.getDayOfWeek() == DateTimeConstants.THURSDAY) {
                fridays.add(startDate);
                reachedAFriday = true;

                String MothWithTwoDigit = String.format("%02d", startDate.getMonthOfYear());
                String dateWithTwoDigit = String.format("%02d", startDate.getDayOfMonth());

                String date = startDate.getYear() + "-" + MothWithTwoDigit + "-" + dateWithTwoDigit;
                String EpisodesName = "Ep-" + dateWithTwoDigit + " " + monthStr2[startDate.getMonthOfYear() - 1]
                        + "," + startDate.getYear();
                if (songID == 0)
                    EpisodesName = "(New)" + EpisodesName;

                path = songPath.get(episodeNumber - songID - 1);//"http://dl.bhoot-fm.com/Bhoot-FM_"+date+"_(Bhoot-FM.com).mp3";
                artist = "Dor";
                composer = "ABC-Radio";
                imageUrl = urlImage[r.nextInt(7)];//"http://3.bp.blogspot.com/-nd09lbpK1Mk/U7hkntBHF4I/AAAAAAAAAM8/FFsAfjT9tW8/s1600/bhoot.jpg";

                url += "{\"songID\":\"" + songID + "\", \"title\":\"" + EpisodesName + "\", \"artist\":\""
                        + artist + "\", \"path\":\"" + path + "\", \"albumId\":\"" + albumID
                        + "\", \"composer\":\"" + composer + "\", \"imageUrl\":\"" + imageUrl + "\"},";

                songID++;
            }
            if (reachedAFriday) {
                startDate = startDate.minusWeeks(1);
            } else {
                startDate = startDate.minusDays(1);
            }

            System.out.println("fahad -- " + (startDate.getDayOfMonth() - 1));
        }

        albumID++;
        url = url.substring(0, url.length() - 1) + "], \"songListRange\":\"" + startRange + "-" + (songID - 1)
                + "\"},";

        startRange = 0;

        if (!prevYear.equals("" + startDate.getYear())) {
            url = url.substring(0, url.length() - 1) + "]},";
            //prevYear = dayOfYaer;
        }
    }

    url = url.substring(0, url.length() - 1) + "]}]}";//]}
    System.out.println(url);

    File file = new File("filename_dor.txt");

    // if file doesnt exists, then create it
    if (!file.exists()) {
        file.createNewFile();
    }

    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(url);
    bw.close();

    System.out.println("Done");

}

From source file:javaapplication1.GenerateTest2JibonerGolpo.java

public static void main(String[] args) throws IOException {
    int episodeNumber = 0;
    BufferedReader buffreader = null;
    try {//from w  w  w.java  2s . c  o  m
        // open the file for reading
        InputStream fis = new FileInputStream("api_jibon/Jiboner_Golpo.txt");

        // if file the available for reading
        if (fis != null) {

            // prepare the file for reading
            InputStreamReader chapterReader = new InputStreamReader(fis);
            buffreader = new BufferedReader(chapterReader);

            String line = null;
            while (true) {
                try {
                    line = buffreader.readLine();

                } catch (Exception e) {

                }

                if (line == null)
                    break;
                songPath.add(line);
                episodeNumber++;

            }

            /*String line;
                    
            // read every line of the file into the line-variable, on line at the time
            do {
               line = buffreader.readLine();
              // do something with the line 
               System.out.println(line);
            } while (line != null);
              */

        }
    } catch (Exception e) {

    } finally {

    }

    String[] monthStr2 = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nove",
            "Dec" };

    String[] monthStr = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December" };

    String[] urlImage = { "https://i.imgur.com/VAwVL2V.jpg", "https://i.imgur.com/bvWyY1t.jpg",
            "https://i.imgur.com/VAwVL2V.jpg", "https://i.imgur.com/bvWyY1t.jpg",
            "https://i.imgur.com/VAwVL2V.jpg", "https://i.imgur.com/bvWyY1t.jpg",
            "https://i.imgur.com/VAwVL2V.jpg"

    };

    List<DateTime> fridays = new ArrayList<>();
    boolean reachedAFriday = false;

    String start = "12/08/2010";
    String end = "01/02/2011";
    DateTimeFormatter pattern = DateTimeFormat.forPattern("dd/mm/yyyy");
    DateTime startDate = new DateTime();//(2018, 06, 16, 0, 0, 0, 0);//pattern.parseDateTime(start); // year-month-day
    DateTime endDate = new DateTime(2010, 1, 1, 0, 0, 0, 0);//pattern.parseDateTime(end);

    int startRange = 0;
    int yearID = 0;
    int albumID = 0;
    int songID = 0;

    String url = "{\"albumList\":[";
    String prevYear = "";

    Random r = new Random();
    int i1 = (r.nextInt(80) + 65);
    while (startDate.isAfter(endDate)) {
        if (songID >= episodeNumber)
            break;
        String dayOfYaer = "" + startDate.getYear();

        if (!prevYear.equals(dayOfYaer)) {
            url += "{\"yearID\":\"" + yearID + "\", \"yearName\":\"" + "YEAR-" + dayOfYaer
                    + "\", \"monthList\":[";
            prevYear = "" + startDate.getYear();
            yearID++;
        }

        String dayOfMonth = "" + monthStr[startDate.getMonthOfYear() - 1];
        url += "{\"albumID\":\"" + albumID + "\", \"albumName\":\"" + "" + dayOfMonth + "\", \"songList\":["; //+"Month-"+startDate.dayOfMonth() +"\"},";
        //System.out.println("fahad -- "+ (startDate.getDayOfMonth()-1));
        if (startRange == 0)
            startRange = songID;
        while ((monthStr[startDate.getMonthOfYear() - 1]).equals(dayOfMonth)) {
            if (songID >= episodeNumber)
                break;
            if (startDate.getDayOfWeek() == DateTimeConstants.WEDNESDAY) {
                fridays.add(startDate);
                reachedAFriday = true;

                String MothWithTwoDigit = String.format("%02d", startDate.getMonthOfYear());
                String dateWithTwoDigit = String.format("%02d", startDate.getDayOfMonth());

                String date = startDate.getYear() + "-" + MothWithTwoDigit + "-" + dateWithTwoDigit;
                String EpisodesName = "Ep-" + dateWithTwoDigit + " " + monthStr2[startDate.getMonthOfYear() - 1]
                        + "," + startDate.getYear();
                if (songID == 0)
                    EpisodesName = "(New)" + EpisodesName;

                path = songPath.get(episodeNumber - songID - 1);//"http://dl.bhoot-fm.com/Bhoot-FM_"+date+"_(Bhoot-FM.com).mp3";

                String performaerName = "";
                if (path != null) {
                    System.out.println("" + path);

                    String splitedName[] = path.split("-");

                    performaerName = splitedName[splitedName.length - 1].substring(0,
                            splitedName[splitedName.length - 1].length() - 17);
                    EpisodesName = EpisodesName + "-" + performaerName;
                }

                artist = "Jiboner Golpo";
                composer = "ABC-Radio";
                imageUrl = urlImage[r.nextInt(7)];//"http://3.bp.blogspot.com/-nd09lbpK1Mk/U7hkntBHF4I/AAAAAAAAAM8/FFsAfjT9tW8/s1600/bhoot.jpg";

                url += "{\"songID\":\"" + songID + "\", \"title\":\"" + EpisodesName + "\", \"artist\":\""
                        + artist + "\", \"path\":\"" + path + "\", \"albumId\":\"" + albumID
                        + "\", \"composer\":\"" + composer + "\", \"imageUrl\":\"" + imageUrl + "\"},";

                songID++;
            }
            if (reachedAFriday) {
                startDate = startDate.minusWeeks(1);
            } else {
                startDate = startDate.minusDays(1);
            }

            System.out.println("fahad -- " + (startDate.getDayOfMonth() - 1));
        }

        albumID++;
        url = url.substring(0, url.length() - 1) + "], \"songListRange\":\"" + startRange + "-" + (songID - 1)
                + "\"},";

        startRange = 0;

        if (!prevYear.equals("" + startDate.getYear())) {
            url = url.substring(0, url.length() - 1) + "]},";
            //prevYear = dayOfYaer;
        }
    }

    url = url.substring(0, url.length() - 1) + "]}]}";//]}
    System.out.println(url);

    File file = new File("api_jibon/filename_jiboner_golpo.json");

    // if file doesnt exists, then create it
    if (!file.exists()) {
        file.createNewFile();
    }

    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(url);
    bw.close();

    System.out.println("Done");

}

From source file:kr.debop4j.core.tools.DateTool.java

License:Apache License

/**
 * Gets start of week.//  w  w w  .ja  v a  2s.c om
 *
 * @param moment the moment
 * @return the start of week
 */
public static DateTime getStartOfWeek(final DateTime moment) {
    int add = DateTimeConstants.MONDAY - moment.getDayOfWeek();
    if (add > 0)
        add -= 7;
    return moment.withTimeAtStartOfDay().plusDays(add);
}

From source file:kr.debop4j.timeperiod.TimeCalendar.java

License:Apache License

@Override
public DayOfWeek getDayOfWeek(DateTime time) {
    return DayOfWeek.valueOf(time.getDayOfWeek());
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Gets start of week.//from  www. j  a va2  s.com
 *
 * @param time           the time
 * @param firstDayOfWeek the first day of week
 * @return the start of week
 */
public static DateTime getStartOfWeek(DateTime time, DayOfWeek firstDayOfWeek) {
    DateTime current = time.withTimeAtStartOfDay();
    while (current.getDayOfWeek() != firstDayOfWeek.getValue()) {
        current = current.minusDays(1);
    }
    return current;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 *  ??? ?  ? ?? .//ww  w .j a v a 2 s.co  m
 *
 * @param moment  ??
 */
public static DateTime nextDayOfWeek(DateTime moment) {
    return nextDayOfWeek(moment, DayOfWeek.valueOf(moment.getDayOfWeek()));
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * ? ?  ??  ?? .//  www . jav a  2 s .  c  om
 *
 * @param moment     ??
 * @param dayOfWeek ? ?
 */
public static DateTime nextDayOfWeek(final DateTime moment, final DayOfWeek dayOfWeek) {
    final int dow = dayOfWeek.getValue();
    DateTime next = moment.plusDays(1);

    while (next.getDayOfWeek() != dow) {
        next = next.plusDays(1);
    }
    return next;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 *  ??? ? ? ?? .//from ww w.  j  av a 2  s .c  o m
 *
 * @param moment  ??
 */
public static DateTime previousDayOfWeek(DateTime moment) {
    return previousDayOfWeek(moment, DayOfWeek.valueOf(moment.getDayOfWeek()));
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 *  ?? ??  ??  ?? .//from  ww  w. j  a  v  a 2s  .c o m
 *
 * @param moment     ??
 * @param dayOfWeek ? ?
 */
public static DateTime previousDayOfWeek(DateTime moment, DayOfWeek dayOfWeek) {
    int dow = dayOfWeek.getValue();
    DateTime prev = moment.minusDays(1);

    while (prev.getDayOfWeek() != dow) {
        prev = prev.minusDays(1);
    }
    return prev;
}