Example usage for org.joda.time DateTime getWeekyear

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

Introduction

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

Prototype

public int getWeekyear() 

Source Link

Document

Get the weekyear field value.

Usage

From source file:com.lithium.yoda.IsoWeekYear.java

License:Apache License

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    if (arguments[0] == null || arguments[0].get() == null) {
        return null;
    }//from   w ww .j  a  v a  2  s  .c o m
    long epoch = timestampOi.get(arguments[0].get());
    DateTime dt = new DateTime(epoch, DateTimeZone.UTC);
    return dt.getWeekyear();
}

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

License:Apache License

/**
 * Gets week of year./*from  ww  w.j  a  v  a 2 s .  co m*/
 *
 * @param moment       the moment
 * @param timeCalendar the time calendar
 * @return the week of year
 */
public static YearAndWeek getWeekOfYear(DateTime moment, ITimeCalendar timeCalendar) {
    return new YearAndWeek(moment.getWeekyear(), moment.getWeekOfWeekyear());
}

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

License:Apache License

/**
 * Start time of week./*from w w  w.j a va2  s . com*/
 *
 * @param year         the year
 * @param weekOfYear   the week of year
 * @param timeCalendar the time calendar
 * @return the date time
 */
public static DateTime startTimeOfWeek(int year, int weekOfYear, ITimeCalendar timeCalendar) {
    DateTime current = startTimeOfYear(year).minusWeeks(1);
    while (current.getYear() < year + 2) {
        if (current.getWeekyear() == year && current.getWeekOfWeekyear() == weekOfYear)
            break;
        current = current.plusDays(1);
    }
    return current;
}

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

License:Apache License

/**
 *  ???  .//from  w  ww  . ja  v  a2s . c  o  m
 *
 * @param moment    the moment
 * @param baseMonth the base month
 * @return the year and week
 */
public static YearAndWeek getYearAndWeek(DateTime moment, int baseMonth) {
    return new YearAndWeek(moment.getWeekyear(), moment.getWeekOfWeekyear());
}

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

License:Apache License

/**
 * Instantiates a new Year and week./*  w ww .  j  a v  a 2 s  . com*/
 *
 * @param moment the moment
 */
public YearAndWeek(DateTime moment) {
    this.year = moment.getWeekyear();
    this.weekOfYear = moment.getWeekOfWeekyear();
}

From source file:org.jruby.truffle.core.time.RubyDateFormatter.java

License:LGPL

public ByteList formatToByteList(List<Token> compiledPattern, DateTime dt, long nsec) {
    RubyTimeOutputFormatter formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;
    ByteList toAppendTo = new ByteList();

    for (Token token : compiledPattern) {
        String output = null;//  www. j  av  a2  s  .c  o m
        long value = 0;
        FieldType type = TEXT;
        Format format = token.getFormat();

        switch (format) {
        case FORMAT_ENCODING:
            toAppendTo.setEncoding((Encoding) token.getData());
            continue; // go to next token
        case FORMAT_OUTPUT:
            formatter = (RubyTimeOutputFormatter) token.getData();
            continue; // go to next token
        case FORMAT_STRING:
            output = token.getData().toString();
            break;
        case FORMAT_WEEK_LONG:
            // This is GROSS, but Java API's aren't ISO 8601 compliant at all
            int v = (dt.getDayOfWeek() + 1) % 8;
            if (v == 0) {
                v++;
            }
            output = FORMAT_SYMBOLS.getWeekdays()[v];
            break;
        case FORMAT_WEEK_SHORT:
            // This is GROSS, but Java API's aren't ISO 8601 compliant at all
            v = (dt.getDayOfWeek() + 1) % 8;
            if (v == 0) {
                v++;
            }
            output = FORMAT_SYMBOLS.getShortWeekdays()[v];
            break;
        case FORMAT_MONTH_LONG:
            output = FORMAT_SYMBOLS.getMonths()[dt.getMonthOfYear() - 1];
            break;
        case FORMAT_MONTH_SHORT:
            output = FORMAT_SYMBOLS.getShortMonths()[dt.getMonthOfYear() - 1];
            break;
        case FORMAT_DAY:
            type = NUMERIC2;
            value = dt.getDayOfMonth();
            break;
        case FORMAT_DAY_S:
            type = NUMERIC2BLANK;
            value = dt.getDayOfMonth();
            break;
        case FORMAT_HOUR:
            type = NUMERIC2;
            value = dt.getHourOfDay();
            break;
        case FORMAT_HOUR_BLANK:
            type = NUMERIC2BLANK;
            value = dt.getHourOfDay();
            break;
        case FORMAT_HOUR_M:
        case FORMAT_HOUR_S:
            value = dt.getHourOfDay();
            if (value == 0) {
                value = 12;
            } else if (value > 12) {
                value -= 12;
            }

            type = (format == Format.FORMAT_HOUR_M) ? NUMERIC2 : NUMERIC2BLANK;
            break;
        case FORMAT_DAY_YEAR:
            type = NUMERIC3;
            value = dt.getDayOfYear();
            break;
        case FORMAT_MINUTES:
            type = NUMERIC2;
            value = dt.getMinuteOfHour();
            break;
        case FORMAT_MONTH:
            type = NUMERIC2;
            value = dt.getMonthOfYear();
            break;
        case FORMAT_MERIDIAN:
            output = dt.getHourOfDay() < 12 ? "AM" : "PM";
            break;
        case FORMAT_MERIDIAN_LOWER_CASE:
            output = dt.getHourOfDay() < 12 ? "am" : "pm";
            break;
        case FORMAT_SECONDS:
            type = NUMERIC2;
            value = dt.getSecondOfMinute();
            break;
        case FORMAT_WEEK_YEAR_M:
            type = NUMERIC2;
            value = formatWeekYear(dt, Calendar.MONDAY);
            break;
        case FORMAT_WEEK_YEAR_S:
            type = NUMERIC2;
            value = formatWeekYear(dt, Calendar.SUNDAY);
            break;
        case FORMAT_DAY_WEEK:
            type = NUMERIC;
            value = dt.getDayOfWeek() % 7;
            break;
        case FORMAT_DAY_WEEK2:
            type = NUMERIC;
            value = dt.getDayOfWeek();
            break;
        case FORMAT_YEAR_LONG:
            value = year(dt, dt.getYear());
            type = (value >= 0) ? NUMERIC4 : NUMERIC5;
            break;
        case FORMAT_YEAR_SHORT:
            type = NUMERIC2;
            value = year(dt, dt.getYear()) % 100;
            break;
        case FORMAT_COLON_ZONE_OFF:
            // custom logic because this is so weird
            value = dt.getZone().getOffset(dt.getMillis()) / 1000;
            int colons = (Integer) token.getData();
            output = formatZone(colons, (int) value, formatter);
            break;
        case FORMAT_ZONE_ID:
            output = getRubyTimeZoneName(dt);
            break;
        case FORMAT_CENTURY:
            type = NUMERIC;
            value = year(dt, dt.getYear()) / 100;
            break;
        case FORMAT_EPOCH:
            type = NUMERIC;
            value = dt.getMillis() / 1000;
            break;
        case FORMAT_WEEK_WEEKYEAR:
            type = NUMERIC2;
            value = dt.getWeekOfWeekyear();
            break;
        case FORMAT_MILLISEC:
        case FORMAT_NANOSEC:
            int defaultWidth = (format == Format.FORMAT_NANOSEC) ? 9 : 3;
            int width = formatter.getWidth(defaultWidth);

            output = RubyTimeOutputFormatter.formatNumber(dt.getMillisOfSecond(), 3, '0');
            if (width > 3) {
                output += RubyTimeOutputFormatter.formatNumber(nsec, 6, '0');
            }

            if (width < output.length()) {
                output = output.substring(0, width);
            } else {
                // Not enough precision, fill with 0
                while (output.length() < width)
                    output += "0";
            }
            formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; // no more formatting
            break;
        case FORMAT_WEEKYEAR:
            value = year(dt, dt.getWeekyear());
            type = (value >= 0) ? NUMERIC4 : NUMERIC5;
            break;
        case FORMAT_WEEKYEAR_SHORT:
            type = NUMERIC2;
            value = year(dt, dt.getWeekyear()) % 100;
            break;
        case FORMAT_MICROSEC_EPOCH:
            // only available for Date
            type = NUMERIC;
            value = dt.getMillis();
            break;
        case FORMAT_SPECIAL:
            throw new Error("FORMAT_SPECIAL is a special token only for the lexer.");
        }

        try {
            output = formatter.format(output, value, type);
        } catch (IndexOutOfBoundsException ioobe) {
            throw new RaiseException(
                    context.getCoreExceptions().errnoError(Errno.ERANGE.intValue(), "strftime", currentNode));
        }

        // reset formatter
        formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;

        toAppendTo.append(
                output.getBytes(context.getEncodingManager().charsetForEncoding(toAppendTo.getEncoding())));
    }

    return toAppendTo;
}

From source file:org.jruby.util.RubyDateFormatter.java

License:LGPL

public ByteList formatToByteList(List<Token> compiledPattern, DateTime dt, long nsec, IRubyObject sub_millis) {
    RubyTimeOutputFormatter formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;
    ByteList toAppendTo = new ByteList();

    for (Token token : compiledPattern) {
        String output = null;//from  w ww. j  av a  2  s.  c  o  m
        long value = 0;
        FieldType type = TEXT;
        Format format = token.getFormat();

        switch (format) {
        case FORMAT_ENCODING:
            toAppendTo.setEncoding((Encoding) token.getData());
            continue; // go to next token
        case FORMAT_OUTPUT:
            formatter = (RubyTimeOutputFormatter) token.getData();
            continue; // go to next token
        case FORMAT_STRING:
            output = token.getData().toString();
            break;
        case FORMAT_WEEK_LONG:
            // This is GROSS, but Java API's aren't ISO 8601 compliant at all
            int v = (dt.getDayOfWeek() + 1) % 8;
            if (v == 0) {
                v++;
            }
            output = FORMAT_SYMBOLS.getWeekdays()[v];
            break;
        case FORMAT_WEEK_SHORT:
            // This is GROSS, but Java API's aren't ISO 8601 compliant at all
            v = (dt.getDayOfWeek() + 1) % 8;
            if (v == 0) {
                v++;
            }
            output = FORMAT_SYMBOLS.getShortWeekdays()[v];
            break;
        case FORMAT_MONTH_LONG:
            output = FORMAT_SYMBOLS.getMonths()[dt.getMonthOfYear() - 1];
            break;
        case FORMAT_MONTH_SHORT:
            output = FORMAT_SYMBOLS.getShortMonths()[dt.getMonthOfYear() - 1];
            break;
        case FORMAT_DAY:
            type = NUMERIC2;
            value = dt.getDayOfMonth();
            break;
        case FORMAT_DAY_S:
            type = NUMERIC2BLANK;
            value = dt.getDayOfMonth();
            break;
        case FORMAT_HOUR:
            type = NUMERIC2;
            value = dt.getHourOfDay();
            break;
        case FORMAT_HOUR_BLANK:
            type = NUMERIC2BLANK;
            value = dt.getHourOfDay();
            break;
        case FORMAT_HOUR_M:
        case FORMAT_HOUR_S:
            value = dt.getHourOfDay();
            if (value == 0) {
                value = 12;
            } else if (value > 12) {
                value -= 12;
            }

            type = (format == Format.FORMAT_HOUR_M) ? NUMERIC2 : NUMERIC2BLANK;
            break;
        case FORMAT_DAY_YEAR:
            type = NUMERIC3;
            value = dt.getDayOfYear();
            break;
        case FORMAT_MINUTES:
            type = NUMERIC2;
            value = dt.getMinuteOfHour();
            break;
        case FORMAT_MONTH:
            type = NUMERIC2;
            value = dt.getMonthOfYear();
            break;
        case FORMAT_MERIDIAN:
            output = dt.getHourOfDay() < 12 ? "AM" : "PM";
            break;
        case FORMAT_MERIDIAN_LOWER_CASE:
            output = dt.getHourOfDay() < 12 ? "am" : "pm";
            break;
        case FORMAT_SECONDS:
            type = NUMERIC2;
            value = dt.getSecondOfMinute();
            break;
        case FORMAT_WEEK_YEAR_M:
            type = NUMERIC2;
            value = formatWeekYear(dt, java.util.Calendar.MONDAY);
            break;
        case FORMAT_WEEK_YEAR_S:
            type = NUMERIC2;
            value = formatWeekYear(dt, java.util.Calendar.SUNDAY);
            break;
        case FORMAT_DAY_WEEK:
            type = NUMERIC;
            value = dt.getDayOfWeek() % 7;
            break;
        case FORMAT_DAY_WEEK2:
            type = NUMERIC;
            value = dt.getDayOfWeek();
            break;
        case FORMAT_YEAR_LONG:
            value = year(dt, dt.getYear());
            type = (value >= 0) ? NUMERIC4 : NUMERIC5;
            break;
        case FORMAT_YEAR_SHORT:
            type = NUMERIC2;
            value = year(dt, dt.getYear()) % 100;
            break;
        case FORMAT_COLON_ZONE_OFF:
            // custom logic because this is so weird
            value = dt.getZone().getOffset(dt.getMillis()) / 1000;
            int colons = (Integer) token.getData();
            output = formatZone(colons, (int) value, formatter);
            break;
        case FORMAT_ZONE_ID:
            output = dt.getZone().getShortName(dt.getMillis());
            break;
        case FORMAT_CENTURY:
            type = NUMERIC;
            value = year(dt, dt.getYear()) / 100;
            break;
        case FORMAT_EPOCH:
            type = NUMERIC;
            value = dt.getMillis() / 1000;
            break;
        case FORMAT_WEEK_WEEKYEAR:
            type = NUMERIC2;
            value = dt.getWeekOfWeekyear();
            break;
        case FORMAT_MILLISEC:
        case FORMAT_NANOSEC:
            int defaultWidth = (format == Format.FORMAT_NANOSEC) ? 9 : 3;
            int width = formatter.getWidth(defaultWidth);

            output = RubyTimeOutputFormatter.formatNumber(dt.getMillisOfSecond(), 3, '0');
            if (width > 3) {
                if (sub_millis == null || sub_millis.isNil()) { // Time
                    output += RubyTimeOutputFormatter.formatNumber(nsec, 6, '0');
                } else { // Date, DateTime
                    int prec = width - 3;
                    IRubyObject power = context.runtime.newFixnum(10).callMethod("**",
                            context.runtime.newFixnum(prec));
                    IRubyObject truncated = sub_millis.callMethod(context, "numerator").callMethod(context, "*",
                            power);
                    truncated = truncated.callMethod(context, "/",
                            sub_millis.callMethod(context, "denominator"));
                    long decimals = truncated.convertToInteger().getLongValue();
                    output += RubyTimeOutputFormatter.formatNumber(decimals, prec, '0');
                }
            }

            if (width < output.length()) {
                output = output.substring(0, width);
            } else {
                // Not enough precision, fill with 0
                while (output.length() < width)
                    output += "0";
            }
            formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; // no more formatting
            break;
        case FORMAT_WEEKYEAR:
            value = year(dt, dt.getWeekyear());
            type = (value >= 0) ? NUMERIC4 : NUMERIC5;
            break;
        case FORMAT_WEEKYEAR_SHORT:
            type = NUMERIC2;
            value = year(dt, dt.getWeekyear()) % 100;
            break;
        case FORMAT_MICROSEC_EPOCH:
            // only available for Date
            type = NUMERIC;
            value = dt.getMillis();
            break;
        case FORMAT_SPECIAL:
            throw new Error("FORMAT_SPECIAL is a special token only for the lexer.");
        }

        output = formatter.format(output, value, type);
        // reset formatter
        formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;

        toAppendTo.append(output
                .getBytes(context.runtime.getEncodingService().charsetForEncoding(toAppendTo.getEncoding())));
    }

    return toAppendTo;
}

From source file:TimeDate.Date.java

public Date() {
    DateTime datr = new DateTime();
    ano = datr.getYear();//from w w w.j  a v  a 2s.co  m
    mes = datr.getMonthOfYear();
    dia = datr.getDayOfMonth();
    diasdoano = datr.getDayOfYear();
    semanasdoano = datr.getWeekyear();
    locale = new Langs.Locale();
}