Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    public static Calendar getDateAwareCalendar() {
        Calendar calendar = new GregorianCalendar();

        // Check if the 1st of September is in two weeks. If so we need to download full timetable
        // for two weeks beginning from the 1st of September in advance.
        if (calendar.get(Calendar.MONTH) == Calendar.AUGUST && calendar.get(Calendar.DATE) >= 18) {
            calendar.set(Calendar.MONTH, Calendar.SEPTEMBER);
            calendar.set(Calendar.DATE, 1);
        }

        prepareCalendarNoSunday(calendar);
        return calendar;
    }

    private static void prepareCalendarNoSunday(Calendar calendar) {
        if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.SUNDAY) {
            calendar.add(Calendar.DATE, 1);
        }
    }
}