Example usage for java.util Calendar DAY_OF_WEEK

List of usage examples for java.util Calendar DAY_OF_WEEK

Introduction

In this page you can find the example usage for java.util Calendar DAY_OF_WEEK.

Prototype

int DAY_OF_WEEK

To view the source code for java.util Calendar DAY_OF_WEEK.

Click Source Link

Document

Field number for get and set indicating the day of the week.

Usage

From source file:com.clustercontrol.jobmanagement.factory.JobPlanSchedule.java

/**
 * ????????????????????/*from   ww w  .  ja  v  a 2  s  . c  o m*/
 * @return ???????true ???????false
 */
private boolean isFireDayOfWeek() {
    Calendar calendar = HinemosTime.getCalendarInstance();
    calendar.set(year, month - 1, day);
    if (calendar.get(Calendar.DAY_OF_WEEK) == weekCalendar) {
        return true;
    } else {
        return false;
    }
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ????/*from ww  w .  ja v  a 2  s  .co m*/
 * @param date ??
 * @return 
 */
public static int getDayOfWeek(Date date) {
    if (date == null)
        return -1;
    Calendar calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(date);
    return calendar.get(Calendar.DAY_OF_WEEK);
}

From source file:com.liusoft.dlog4j.velocity.DLOG_VelocityTool.java

/**
 * (_catalog_and_calendar.vm)/*from  w ww .  j av a2  s. c o m*/
 * 
 * @param year
 * @param month
 * @return
 */
public int[][] calendar(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    int firstDateInWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;
    int dateOfMonth = getMonthDateCount(cal);
    int base = dateOfMonth + firstDateInWeek;
    int row = base / 7;
    row += ((base % 7) > 0) ? 1 : 0;
    int[][] cals = new int[row][7];
    int iCol = firstDateInWeek, iRow = 0;
    for (int i = 1; i <= dateOfMonth; i++) {
        cals[iRow][iCol] = i;
        if (iCol == 6) {
            iCol = 0;
            iRow++;
        } else
            iCol++;
    }
    return cals;
}

From source file:com.rockagen.commons.util.CommUtil.java

/**
 * Get the current day of the week<br>
 *
 * @param date Date/*from  ww  w  .  ja v  a2s  . com*/
 * @return current day of week String. e.g:SUNDAY,MONDAY...
 */
public static String getCurrentDayOfWeekS(Date date) {
    Calendar cal = getCalendar(date);

    int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
    if (w < 0)
        w = 0;
    return WEEK_DAYS[w];
}

From source file:com.layer.atlas.Atlas.java

/** @return if Today: time. If Yesterday: "Yesterday", if within one week: day of week, otherwise: dateFormat.format() */
public static String formatTimeShort(Date dateTime, DateFormat timeFormat, DateFormat dateFormat) {

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from  w  w  w  . j a  va 2s  .com*/
    cal.set(Calendar.SECOND, 0);
    long todayMidnight = cal.getTimeInMillis();
    long yesterMidnight = todayMidnight - Tools.TIME_HOURS_24;
    long weekAgoMidnight = todayMidnight - Tools.TIME_HOURS_24 * 7;

    String timeText = null;
    if (dateTime.getTime() > todayMidnight) {
        timeText = timeFormat.format(dateTime.getTime());
    } else if (dateTime.getTime() > yesterMidnight) {
        timeText = "Yesterday";
    } else if (dateTime.getTime() > weekAgoMidnight) {
        cal.setTime(dateTime);
        timeText = Tools.TIME_WEEKDAYS_NAMES[cal.get(Calendar.DAY_OF_WEEK) - 1];
    } else {
        timeText = dateFormat.format(dateTime);
    }
    return timeText;
}

From source file:net.lightbody.bmp.proxy.jetty.http.HttpFields.java

/** Format HTTP date
 * "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or 
 * "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
 *//*  w  ww .j a v a 2  s  .c  om*/
public static void formatDate(StringBuffer buf, Calendar calendar, boolean cookie) {
    // "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
    // "EEE, dd-MMM-yy HH:mm:ss 'GMT'",     cookie

    int day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
    int day_of_month = calendar.get(Calendar.DAY_OF_MONTH);
    int month = calendar.get(Calendar.MONTH);
    int year = calendar.get(Calendar.YEAR);
    int century = year / 100;
    year = year % 100;

    long tm = (calendar instanceof HttpCal) ? (((HttpCal) calendar).getTimeInMillis())
            : calendar.getTime().getTime();
    int epoch = (int) ((tm / 1000) % (60 * 60 * 24));
    int seconds = epoch % 60;
    epoch = epoch / 60;
    int minutes = epoch % 60;
    int hours = epoch / 60;

    buf.append(DAYS[day_of_week]);
    buf.append(',');
    buf.append(' ');
    StringUtil.append2digits(buf, day_of_month);

    if (cookie) {
        buf.append('-');
        buf.append(MONTHS[month]);
        buf.append('-');
        StringUtil.append2digits(buf, year);
    } else {
        buf.append(' ');
        buf.append(MONTHS[month]);
        buf.append(' ');
        StringUtil.append2digits(buf, century);
        StringUtil.append2digits(buf, year);
    }
    buf.append(' ');
    StringUtil.append2digits(buf, hours);
    buf.append(':');
    StringUtil.append2digits(buf, minutes);
    buf.append(':');
    StringUtil.append2digits(buf, seconds);
    buf.append(" GMT");
}

From source file:com.mirth.connect.model.ServerConfiguration.java

@Override
public void migrate3_3_0(DonkeyElement element) {
    DonkeyElement librariesElement = element.addChildElement("codeTemplateLibraries");
    DonkeyElement libraryElement = librariesElement.addChildElement("codeTemplateLibrary");
    libraryElement.setAttribute("version", "3.3.0");
    libraryElement.addChildElement("id", UUID.randomUUID().toString());
    libraryElement.addChildElement("name", "Library 1");
    libraryElement.addChildElement("revision", "1");
    try {/*ww w.  ja va  2  s. c o m*/
        libraryElement
                .addChildElementFromXml(ObjectXMLSerializer.getInstance().serialize(Calendar.getInstance()))
                .setNodeName("lastModified");
    } catch (DonkeyElementException e) {
        throw new SerializerException("Failed to migrate code template library last modified date.", e);
    }
    libraryElement.addChildElement("description",
            "This library was added upon migration to version 3.3.0. It includes all pre-existing\ncode templates, and is set to be included on all pre-existing and new channels.\n\nYou should create your own new libraries and assign code templates to them as you\nsee fit. You should also link libraries to specific channels, so that you're not\nnecessarily including all code templates on all channels all the time.");
    libraryElement.addChildElement("includeNewChannels", "true");
    libraryElement.addChildElement("enabledChannelIds");
    libraryElement.addChildElement("disabledChannelIds");
    try {
        libraryElement.addChildElementFromXml(element.removeChild("codeTemplates").toXml());
    } catch (DonkeyElementException e) {
        throw new SerializerException("Failed to migrate code templates.", e);
    }

    boolean enabled = true;
    String time = "";
    String interval = "";
    String dayOfWeek = "";
    String dayOfMonth = "1";

    DonkeyElement properties = null;
    DonkeyElement pluginProperties = element.getChildElement("pluginProperties");
    if (pluginProperties != null) {
        for (DonkeyElement childElement : pluginProperties.getChildElements()) {
            String entryKey = childElement.getChildElement("string").getTextContent();
            if (entryKey.equals("Data Pruner")) {
                properties = childElement.getChildElement("properties");

                for (DonkeyElement property : properties.getChildElements()) {
                    String propertyName = property.getAttributes().item(0).getTextContent();

                    if (propertyName.equals("dayOfWeek")) {
                        dayOfWeek = property.getTextContent();
                    } else if (propertyName.equals("dayOfMonth")) {
                        dayOfMonth = property.getTextContent();
                    } else if (propertyName.equals("interval")) {
                        interval = property.getTextContent();
                    } else if (propertyName.equals("time")) {
                        time = property.getTextContent();
                    }
                }
            }
        }

        enabled = !interval.equals("disabled");
        String pollingType = "INTERVAL";
        String pollingHour = "12";
        String pollingMinute = "0";
        boolean weekly = !StringUtils.equals(interval, "monthly");
        boolean[] activeDays = new boolean[] { true, true, true, true, true, true, true, true };

        if (enabled && !StringUtils.equals(interval, "hourly")) {
            SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa");
            DateFormatter timeFormatter = new DateFormatter(timeDateFormat);
            Date timeDate = null;

            try {
                timeDate = (Date) timeFormatter.stringToValue(time);
                Calendar timeCalendar = Calendar.getInstance();
                timeCalendar.setTime(timeDate);

                pollingType = "TIME";
                pollingHour = String.valueOf(timeCalendar.get(Calendar.HOUR_OF_DAY));
                pollingMinute = String.valueOf(timeCalendar.get(Calendar.MINUTE));

                if (StringUtils.equals(interval, "weekly")) {
                    SimpleDateFormat dayDateFormat = new SimpleDateFormat("EEEEEEEE");
                    DateFormatter dayFormatter = new DateFormatter(dayDateFormat);

                    Date dayDate = (Date) dayFormatter.stringToValue(dayOfWeek);
                    Calendar dayCalendar = Calendar.getInstance();
                    dayCalendar.setTime(dayDate);

                    activeDays = new boolean[] { false, false, false, false, false, false, false, false };
                    activeDays[dayCalendar.get(Calendar.DAY_OF_WEEK)] = true;
                }
            } catch (Exception e) {
            }
        }

        try {
            DonkeyElement pollingProperties = new DonkeyElement(
                    "<com.mirth.connect.donkey.model.channel.PollConnectorProperties/>");
            pollingProperties.setAttribute("version", "3.3.0");
            pollingProperties.addChildElementIfNotExists("pollingType", pollingType);
            pollingProperties.addChildElementIfNotExists("pollOnStart", "false");
            pollingProperties.addChildElementIfNotExists("pollingFrequency", "3600000");
            pollingProperties.addChildElementIfNotExists("pollingHour", pollingHour);
            pollingProperties.addChildElementIfNotExists("pollingMinute", pollingMinute);
            pollingProperties.addChildElementIfNotExists("cronJobs");

            DonkeyElement advancedProperties = pollingProperties
                    .addChildElementIfNotExists("pollConnectorPropertiesAdvanced");
            advancedProperties.addChildElementIfNotExists("weekly", weekly ? "true" : "false");

            DonkeyElement inactiveDays = advancedProperties.addChildElementIfNotExists("inactiveDays");
            if (inactiveDays != null) {
                for (int index = 0; index < 8; ++index) {
                    inactiveDays.addChildElement("boolean", activeDays[index] ? "false" : "true");
                }
            }

            advancedProperties.addChildElementIfNotExists("dayOfMonth", dayOfMonth);
            advancedProperties.addChildElementIfNotExists("allDay", "true");
            advancedProperties.addChildElementIfNotExists("startingHour", "8");
            advancedProperties.addChildElementIfNotExists("startingMinute", "0");
            advancedProperties.addChildElementIfNotExists("endingHour", "17");
            advancedProperties.addChildElementIfNotExists("endingMinute", "0");

            DonkeyElement prunerProperty = properties.addChildElementFromXml(
                    ObjectXMLSerializer.getInstance().serialize(pollingProperties.toXml()));
            prunerProperty.setAttribute("name", "pollingProperties");

            DonkeyElement enabledProperty = properties.addChildElement("property", Boolean.toString(enabled));
            enabledProperty.setAttribute("name", "enabled");
        } catch (Exception e) {
            throw new SerializerException("Failed to migrate Data Pruner properties.", e);
        }
    }
}

From source file:de.micromata.genome.util.types.DateUtils.java

/**
 * Ensure workday.//w w w.j  a v  a  2s . co  m
 *
 * @param cal the cal
 */
protected static void ensureWorkday(Calendar cal) {
    int dow = cal.get(Calendar.DAY_OF_WEEK);
    while (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) {
        cal.add(Calendar.DAY_OF_YEAR, 1);
        dow = cal.get(Calendar.DAY_OF_WEEK);
    }
}

From source file:com.discovery.darchrow.date.DateUtil.java

/**
 *  <code>week</code>.//from   w w  w .jav  a 2  s  .  c  o  m
 * 
 * <pre>
 *   2015-7-29 14:08
 * 
 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY)
 * return 2015-01-02 00:00:00.000
 * 
 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY)
 * return 2015-01-05 00:00:00.000
 * </pre>
 * 
 * @param date
 *            
 * @param week
 *             1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY},
 *            {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY}
 * @return the first week of specify date year
 * @see Calendar#SUNDAY
 * @see Calendar#MONDAY
 * @see Calendar#TUESDAY
 * @see Calendar#WEDNESDAY
 * @see Calendar#THURSDAY
 * @see Calendar#FRIDAY
 * @see Calendar#SATURDAY
 * @since 1.3.0
 */
public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) {
    Calendar calendar = toCalendar(date);
    calendar.clear();
    calendar.set(Calendar.YEAR, getYear(date));
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
    calendar.set(Calendar.DAY_OF_WEEK, week);

    //DAY_OF_WEEK_IN_MONTH ? DAY_OF_WEEK ???
    // WEEK_OF_MONTH  WEEK_OF_YEAR ??? ? getFirstDayOfWeek()  getMinimalDaysInFirstWeek()

    //DAY_OF_MONTH 1  7  DAY_OF_WEEK_IN_MONTH 1
    //8  14  DAY_OF_WEEK_IN_MONTH 2?
    //DAY_OF_WEEK_IN_MONTH 0  DAY_OF_WEEK_IN_MONTH 1 ?
    //?? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1
    //?????
    // 31  DAY_OF_WEEK_IN_MONTH -1  DAY_OF_WEEK_IN_MONTH 5  DAY_OF_WEEK_IN_MONTH 4 ??
    return CalendarUtil.toDate(calendar);
}

From source file:com.aurel.track.dbase.jobs.EmailReminderJob.java

/**
 * Whether reminder e-mail is due/* ww w  . j  a va  2s  .c  om*/
 * @param personBean
 * @return
 */
private static boolean isRemindDue(TPersonBean personBean) {
    List<Integer> reminderDays = personBean.getReminderDays();
    if (reminderDays == null || reminderDays.isEmpty()) {
        return false;
    }
    Calendar calToday = new GregorianCalendar();
    calToday.setTime(new Date());
    int noOfDay = calToday.get(Calendar.DAY_OF_WEEK);
    for (Integer reminderDay : reminderDays) {
        if (reminderDay == noOfDay) {
            //break;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Reminder is due for person " + personBean.getName());
            }
            return true;
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Reminder is not due for person " + personBean.getName());
    }
    return false;
}