Example usage for java.util Calendar DAY_OF_WEEK_IN_MONTH

List of usage examples for java.util Calendar DAY_OF_WEEK_IN_MONTH

Introduction

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

Prototype

int DAY_OF_WEEK_IN_MONTH

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

Click Source Link

Document

Field number for get and set indicating the ordinal number of the day of the week within the current month.

Usage

From source file:org.openhab.binding.max.internal.message.CMessage.java

private Date parseTimeInfo(byte[] bytes, String suffix) {
    int month = bytes[0] & 0xFF;
    int weekDay = bytes[1] & 0xFF;
    int hour = bytes[2] & 0xFF;
    int utcOffset = new BigInteger(Arrays.copyOfRange(bytes, 0x03, 0x07)).intValue();
    suffix = " (" + suffix + ")";
    properties.put("Utc Offset" + suffix, utcOffset);
    Calendar pCal = Calendar.getInstance();
    pCal.set(Calendar.getInstance().get(Calendar.YEAR), month - 1, 15, hour, 0, 0);
    pCal.set(Calendar.DAY_OF_WEEK, weekDay + 1);
    pCal.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1);
    return pCal.getTime();
}

From source file:org.pentaho.di.trans.steps.script.ScriptAddedFunctions.java

public static Object getDayNumber(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    if (ArgList.length == 2) {
        try {//from   ww w . j  a v  a  2 s .  c  o m
            if (isNull(ArgList[0])) {
                return new Double(Double.NaN);
            } else if (isUndefined(ArgList[0])) {
                return undefinedValue;
            } else {
                java.util.Date dIn = (java.util.Date) ArgList[0];
                String strType = ((String) ArgList[1]).toLowerCase();
                Calendar startDate = Calendar.getInstance();
                startDate.setTime(dIn);
                if (strType.equals("y")) {
                    return new Double(startDate.get(Calendar.DAY_OF_YEAR));
                } else if (strType.equals("m")) {
                    return new Double(startDate.get(Calendar.DAY_OF_MONTH));
                } else if (strType.equals("w")) {
                    return new Double(startDate.get(Calendar.DAY_OF_WEEK));
                } else if (strType.equals("wm")) {
                    return new Double(startDate.get(Calendar.DAY_OF_WEEK_IN_MONTH));
                }
                return new Double(startDate.get(Calendar.DAY_OF_YEAR));
            }
        } catch (Exception e) {
            return null;
            // throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call getDayNumber requires 2 arguments.");
    }
}

From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static Object getDayNumber(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    if (ArgList.length == 2) {
        try {//from  w w  w .  j a  v  a  2s.co  m
            if (isNull(ArgList[0])) {
                return new Double(Double.NaN);
            } else if (isUndefined(ArgList[0])) {
                return Context.getUndefinedValue();
            } else {
                java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
                String strType = Context.toString(ArgList[1]).toLowerCase();
                Calendar startDate = Calendar.getInstance();
                startDate.setTime(dIn);
                if (strType.equals("y")) {
                    return new Double(startDate.get(Calendar.DAY_OF_YEAR));
                } else if (strType.equals("m")) {
                    return new Double(startDate.get(Calendar.DAY_OF_MONTH));
                } else if (strType.equals("w")) {
                    return new Double(startDate.get(Calendar.DAY_OF_WEEK));
                } else if (strType.equals("wm")) {
                    return new Double(startDate.get(Calendar.DAY_OF_WEEK_IN_MONTH));
                }
                return new Double(startDate.get(Calendar.DAY_OF_YEAR));
            }
        } catch (Exception e) {
            return null;
            // throw Context.reportRuntimeError(e.toString());
        }
    } else {
        throw Context.reportRuntimeError("The function call getDayNumber requires 2 arguments.");
    }
}

From source file:org.sakaiproject.util.CalendarUtil.java

/**
* Get the day of the week in month./*from   ww  w  . j  av a 2  s.  c  om*/
* @return the day of week in month.
*/
public int getDayOfWeekInMonth() {
    return m_calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH);

}

From source file:org.sqlite.date.FastDatePrinter.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a {@code List} of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 *//*from   w w  w . ja va 2 s .c  om*/
protected List<Rule> parsePattern() {
    final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    final List<Rule> rules = new ArrayList<Rule>();

    final String[] ERAs = symbols.getEras();
    final String[] months = symbols.getMonths();
    final String[] shortMonths = symbols.getShortMonths();
    final String[] weekdays = symbols.getWeekdays();
    final String[] shortWeekdays = symbols.getShortWeekdays();
    final String[] AmPmStrings = symbols.getAmPmStrings();

    final int length = mPattern.length();
    final int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        final String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        final int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        final char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen == 2) {
                rule = TwoDigitYearField.INSTANCE;
            } else {
                rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'X': // ISO 8601 
            rule = Iso8601_Rule.getRule(tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else if (tokenLen == 2) {
                rule = TimeZoneNumberRule.INSTANCE_ISO_8601;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            final String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:phenoviewer.ReNameJFrame.java

private String replaceTokens(Date date, int counter, String path) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);// w  w  w .j  a v  a  2  s.c  om

    Map<String, Object> tokens = new HashMap<String, Object>();
    tokens.put("ERA", getText(gc.get(Calendar.ERA), "BC", "AD"));
    tokens.put("YEAR", getString(gc.get(Calendar.YEAR), 4, "0"));
    tokens.put("MONTH", getString(gc.get(Calendar.MONTH) + 1, 2, "0"));
    tokens.put("WEEK_OF_YEAR", getString(gc.get(Calendar.WEEK_OF_YEAR), 2, "0"));
    tokens.put("WEEK_OF_MONTH", getString(gc.get(Calendar.WEEK_OF_MONTH), 0, ""));
    tokens.put("DATE", getString(gc.get(Calendar.DATE), 2, "0"));
    tokens.put("DAY_OF_MONTH", getString(gc.get(Calendar.DAY_OF_MONTH), 2, "0"));
    tokens.put("DAY_OF_YEAR", getString(gc.get(Calendar.DAY_OF_YEAR), 3, "0"));
    tokens.put("DAY_OF_WEEK", getString(gc.get(Calendar.DAY_OF_WEEK), 0, ""));
    tokens.put("DAY_OF_WEEK_IN_MONTH", getString(gc.get(Calendar.DAY_OF_WEEK_IN_MONTH), 0, ""));
    tokens.put("AM_PM", getText(gc.get(Calendar.AM_PM), "AM", "PM"));
    tokens.put("HOUR", getString(gc.get(Calendar.HOUR), 2, "0"));
    tokens.put("HOUR_OF_DAY", getString(gc.get(Calendar.HOUR_OF_DAY), 2, "0"));
    tokens.put("MINUTE", getString(gc.get(Calendar.MINUTE), 2, "0"));
    tokens.put("SECOND", getString(gc.get(Calendar.SECOND), 2, "0"));
    tokens.put("MILLISECOND", getString(gc.get(Calendar.MILLISECOND), 3, "0"));
    // tokens.put("ZONE_OFFSET", getString((gc.get(Calendar.ZONE_OFFSET)/(60*60*1000)), 0, ""));
    // tokens.put("DST_OFFSET", getString((gc.get(Calendar.DST_OFFSET)/(60*60*1000)), 0, ""));
    tokens.put("COUNTER", getString(counter, 0, ""));

    return processParams(path, tokens);
}