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:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java

License:Open Source License

private List<Interval> getDayOfWeekIntervals() {
    final List<Interval> intervals = new ArrayList<>();

    DateTime startDate = getInterval().getStart();
    int nthDayOfWeek = getNthDayOfWeek(startDate);
    int dayOfWeek = startDate.getDayOfWeek();

    DateTime endDate = getInterval().getEnd();

    DateTime start = startDate;/*from w  ww .  ja  va  2  s .c o  m*/
    while (start.isBefore(endDate) || start.isEqual(endDate)) {
        intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime())));
        start = start.plusMonths(getRepeatsEvery());
        start = getNextNthdayOfWeek(start, nthDayOfWeek, dayOfWeek);
    }

    return intervals;
}

From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java

License:Open Source License

private int getNthDayOfWeek(DateTime when) {
    DateTime checkpoint = when;
    int whenDayOfWeek = checkpoint.getDayOfWeek();
    int month = checkpoint.getMonthOfYear();
    checkpoint = checkpoint.withDayOfMonth(1);
    checkpoint = checkpoint.withDayOfWeek(whenDayOfWeek);
    checkpoint = checkpoint.plusWeeks(month - checkpoint.getDayOfMonth());
    int i = 0;/*w w w. j  av a2 s .co m*/
    while (checkpoint.getMonthOfYear() == month && !checkpoint.isEqual(when)) {
        checkpoint = checkpoint.plusWeeks(1);
        i++;
    }
    return i;
}

From source file:org.fenixedu.spaces.domain.occupation.config.WeeklyConfig.java

License:Open Source License

@Override
public List<Interval> getIntervals() {
    final List<Interval> intervals = new ArrayList<>();
    DateTime start = getInterval().getStart();
    DateTime end = getInterval().getEnd();

    // adjust start date to correct day of the week
    int firstDayOfWeekIndex = daysOfWeek.indexOf(start.getDayOfWeek());
    if (firstDayOfWeekIndex == -1) {
        firstDayOfWeekIndex = 0;//w w  w .java  2  s  .  c  om
    }

    DateTime checkpoint = start.withDayOfWeek(daysOfWeek.get(firstDayOfWeekIndex));
    if (checkpoint.isBefore(start)) {
        checkpoint.plusWeeks(1);
    }

    int i = firstDayOfWeekIndex;

    while (checkpoint.isBefore(end) || checkpoint.isEqual(end)) {
        intervals.add(new Interval(checkpoint.withFields(getStartTime()), checkpoint.withFields(getEndTime())));
        if (i == daysOfWeek.size() - 1) {
            i = 0;
            checkpoint = checkpoint.plusWeeks(getRepeatsEvery());
        } else {
            i++;
        }
        checkpoint = checkpoint.withDayOfWeek(daysOfWeek.get(i));
    }
    return intervals;
}

From source file:org.isisaddons.app.kitchensink.dom.date.DateObject.java

License:Apache License

public String validateSomeJodaDateTimeWithValidation(final org.joda.time.DateTime i) {
    return i.getDayOfWeek() == DateTimeConstants.MONDAY ? "Can't enter Monday (don't like Mondays)" : null;
}

From source file:org.itechkenya.leavemanager.api.DateTimeUtil.java

License:Open Source License

/**
 * @param datetime the DateTime to evaluate.
 * //from w  ww.  j  ava2s  . c om
 * @return true if the given dateTime falls on a Sunday.
 */
public static boolean isSunday(DateTime datetime) {
    return datetime.getDayOfWeek() == DateTimeConstants.SUNDAY;
}

From source file:org.itechkenya.leavemanager.api.DateTimeUtil.java

License:Open Source License

/**
 * @param dateTime the datetime to evaluate.
 * /*from   ww w . j  a v  a 2  s.c o  m*/
 * @return true if the given DateTime falls on a weekend.
 */
public static boolean isWeekend(DateTime dateTime) {
    return dateTime.getDayOfWeek() == DateTimeConstants.SATURDAY
            || dateTime.getDayOfWeek() == DateTimeConstants.SUNDAY;
}

From source file:org.jlucrum.realtime.generators.TickGenerator.java

License:Open Source License

private boolean timeout() {
    DateTimeZone timeZone = null;/*from ww  w . ja  v a2  s . c om*/
    DateTime time = null;
    long startTickerTime = 0;
    long endTickerTime = 0;
    boolean toContinue = false;

    timeZone = DateTimeZone.forID(config.timeZone);

    startTickerTime = config.start_hour * 60 + config.start_minute;
    endTickerTime = config.end_hour * 60 + config.end_minute;

    try {
        time = new DateTime(timeZone);

        System.out.printf("Timezone:%s and week:%d - %d", timeZone.toString(), time.getDayOfWeek(),
                DateTimeConstants.SATURDAY);
        if (DateTimeConstants.SATURDAY == time.getDayOfWeek()) {
            long toSleep = 24 * 60 - time.getMinuteOfDay() + 24 * 60;
            System.out.printf("TickGenerator sleeps until Monday, because it is Saturday\n");
            Thread.sleep(toSleep * 60 * 1000);
            toContinue = true;
        } else if (DateTimeConstants.SUNDAY == time.getDayOfWeek()) {
            long toSleep = 24 * 60 - time.getMinuteOfDay();
            System.out.printf("TickGenerator sleeps until Monday, because it is Sunday\n");
            Thread.sleep(toSleep * 60 * 1000);
            toContinue = true;
        }

        if (time.getMinuteOfDay() < startTickerTime) {
            long minutesToSleep = Math.abs(time.getMinuteOfDay() - startTickerTime);
            System.out.printf("Sleeping (%d) minutes ... Starting 1 at:%d:%d\n", minutesToSleep,
                    config.start_hour, config.start_minute);
            Thread.sleep(minutesToSleep * 60 * 1000);
            toContinue = true;

        } else if (time.getMinuteOfDay() > endTickerTime) {
            long minutesToSleep = 24 * 60 - time.getMinuteOfDay();
            minutesToSleep += startTickerTime;
            System.out.printf("Sleeping (%d) minutes ... Starting 2 at:%d:%d\n", minutesToSleep,
                    config.start_hour, config.start_minute);
            Thread.sleep(minutesToSleep * 60 * 1000);
            toContinue = true;
        }

    } catch (InterruptedException ex) {
        Logger.getLogger(TickGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }

    return toContinue;
}

From source file:org.jmxtrans.embedded.samples.graphite.CocktailAppMetricsSimulator.java

License:Open Source License

public void generateLoad(GraphiteDataInjector graphiteDataInjector) throws Exception {

    TimeSeries rawIntegratedTimeSeries = new TimeSeries("sales.integrated.raw");
    TimeSeries rawTimeSeries = new TimeSeries("sales.raw");

    DateTime now = new DateTime();
    DateTime end = now.plusDays(3);//from  w  w  w.  jav a  2s .  co  m

    DateTime date = now.minusDays(15);
    DateTime twoDaysAfterBegin = date.plusDays(2);
    double serverFairness = 1.05;

    int integratedValue = 0;

    MathContext mathContext = new MathContext(1, RoundingMode.CEILING);

    int randomFactor = 0;

    while (date.isBefore(end)) {
        if (rawIntegratedTimeSeries.getItemCount() % 120 == 0) {
            randomFactor = 10 + random.nextInt(2);
        }
        int weekGrowthFactor = 6 - (now.getWeekOfWeekyear() - date.getWeekOfWeekyear());
        int value = new BigDecimal(randomFactor) // random factor
                .multiply(new BigDecimal(10)) // go to cents of USD
                .multiply(new BigDecimal(weekGrowthFactor))
                .multiply(new BigDecimal(hourlyDistribution[date.getHourOfDay()]))
                .multiply(new BigDecimal(weeklyDistribution[date.getDayOfWeek()]))
                .divide(new BigDecimal(20), mathContext).intValue(); // split hourly value in minutes

        integratedValue += value;
        for (int i1 = 0; i1 < 3; i1++) {
            Second period = new Second(date.toDate());
            rawTimeSeries.add(period, value);
            rawIntegratedTimeSeries.add(period, integratedValue);
            date = date.plusSeconds(30);
        }
    }

    rawIntegratedTimeSeries = MovingAverage.createMovingAverage(rawIntegratedTimeSeries,
            rawIntegratedTimeSeries.getKey().toString(), 60 * 7, 0);
    rawTimeSeries = MovingAverage.createMovingAverage(rawTimeSeries, rawTimeSeries.getKey().toString(), 60 * 7,
            0);

    // SALES - REVENUE

    TimeSeries salesRevenueInCentsCounter = new TimeSeries("sales.revenueInCentsCounter");
    TimeSeries salesRevenueInCentsCounterSrv1 = new TimeSeries("srv1.sales.revenueInCentsCounter");
    TimeSeries salesRevenueInCentsCounterSrv2 = new TimeSeries("srv2.sales.revenueInCentsCounter");
    int resetValue2ToZeroOffset = 0; // reset value 2 after 3 days of metrics
    for (int i = 0; i < rawIntegratedTimeSeries.getItemCount(); i++) {
        TimeSeriesDataItem dataItem = rawIntegratedTimeSeries.getDataItem(i);
        int value = dataItem.getValue().intValue();
        // value1 is 5% higher to value2 due to a 'weirdness' in the load balancing
        int value1 = Math.min((int) (value * serverFairness / 2), value);

        {
            // simulate srv2 restart
            DateTime currentDate = new DateTime(dataItem.getPeriod().getStart());
            boolean shouldResetValue2 = resetValue2ToZeroOffset == 0
                    && currentDate.getDayOfYear() == twoDaysAfterBegin.getDayOfYear();
            if (shouldResetValue2) {
                resetValue2ToZeroOffset = value - value1;
                System.out.println("reset value2 of " + resetValue2ToZeroOffset + " at " + currentDate);
            }
        }

        int value2 = value - value1 - resetValue2ToZeroOffset;
        salesRevenueInCentsCounter.add(dataItem.getPeriod(), value);
        salesRevenueInCentsCounterSrv1.add(dataItem.getPeriod(), value1);
        salesRevenueInCentsCounterSrv2.add(dataItem.getPeriod(), value2);
    }
    graphiteDataInjector.exportMetrics(salesRevenueInCentsCounter, salesRevenueInCentsCounterSrv1,
            salesRevenueInCentsCounterSrv2);

    // SALES - ITEMS
    TimeSeries salesItemsCounter = new TimeSeries("sales.itemsCounter");
    TimeSeries salesItemsCounterSrv1 = new TimeSeries("srv1.sales.itemsCounter");
    TimeSeries salesItemsCounterSrv2 = new TimeSeries("srv2.sales.itemsCounter");

    for (int i = 0; i < rawIntegratedTimeSeries.getItemCount(); i++) {
        RegularTimePeriod period = salesRevenueInCentsCounter.getDataItem(i).getPeriod();
        int ordersPriceInCents1 = salesRevenueInCentsCounterSrv1.getDataItem(i).getValue().intValue();
        int ordersPriceInCents2 = salesRevenueInCentsCounterSrv2.getDataItem(i).getValue().intValue();

        int value1 = ordersPriceInCents1 / 600;
        int value2 = ordersPriceInCents2 / 600;

        salesItemsCounter.add(period, value1 + value2);
        salesItemsCounterSrv1.add(period, value1);
        salesItemsCounterSrv2.add(period, value2);

    }

    graphiteDataInjector.exportMetrics(salesItemsCounter, salesItemsCounterSrv1, salesItemsCounterSrv2);

    // WEBSITE - VISITORS
    TimeSeries newVisitorsCounterSrv1 = new TimeSeries("srv1.website.visitors.newVisitorsCounter");
    TimeSeries newVisitorsCounterSrv2 = new TimeSeries("srv1.website.visitors.newVisitorsCounter");

    TimeSeries activeVisitorsGaugeSrv1 = new TimeSeries("srv1.website.visitors.activeGauge");
    TimeSeries activeVisitorsGaugeSrv2 = new TimeSeries("srv2.website.visitors.activeGauge");
    int integratedValue1 = 0;
    int integratedValue2 = 0;
    float activeVisitorsFactor = 1;
    for (int i = 0; i < rawTimeSeries.getItemCount(); i++) {

        TimeSeriesDataItem dataItem = rawTimeSeries.getDataItem(i);
        RegularTimePeriod period = dataItem.getPeriod();
        int value = dataItem.getValue().intValue() / 20;
        integratedValue += value;

        int value1 = Math.min((int) (value * serverFairness / 2), value);
        integratedValue1 += value1;

        int value2 = value - value1;
        integratedValue2 += value2;

        newVisitorsCounterSrv1.add(period, integratedValue1);
        newVisitorsCounterSrv2.add(period, integratedValue2);

        if (i % 120 == 0) {
            activeVisitorsFactor = (10 + random.nextInt(3)) / 10;
        }

        activeVisitorsGaugeSrv1.add(period, Math.floor(value1 * activeVisitorsFactor));
        activeVisitorsGaugeSrv2.add(period, Math.floor(value2 * activeVisitorsFactor));
    }

    graphiteDataInjector.exportMetrics(newVisitorsCounterSrv1, newVisitorsCounterSrv2, activeVisitorsGaugeSrv1,
            activeVisitorsGaugeSrv2);

}

From source file:org.jmxtrans.samples.graphite.GraphiteDataInjector.java

License:Open Source License

public void generateLoad() throws Exception {
    System.out.println("Inject data on Graphite server " + this.graphiteHost);

    TimeSeries timeSeries = new TimeSeries("shopping-cart.raw");

    DateTime now = new DateTime();
    DateTime end = now.plusDays(1);//w w  w .j a  v a  2 s.c om

    DateTime date = now.minusDays(15);
    DateTime twoDaysAfterBegin = date.plusDays(2);

    int integratedValue = 0;

    MathContext mathContext = new MathContext(1, RoundingMode.CEILING);

    int randomFactor = 0;

    while (date.isBefore(end)) {
        if (timeSeries.getItemCount() % 120 == 0) {
            randomFactor = 10 + random.nextInt(2);
        }
        int weekGrowthFactor = 6 - (now.getWeekOfWeekyear() - date.getWeekOfWeekyear());
        int value = new BigDecimal(randomFactor) // random factor
                .multiply(new BigDecimal(10)) // go to cents of USD
                .multiply(new BigDecimal(weekGrowthFactor))
                .multiply(new BigDecimal(hourlyDistribution[date.getHourOfDay()]))
                .multiply(new BigDecimal(weeklyDistribution[date.getDayOfWeek()]))
                .divide(new BigDecimal(20), mathContext).intValue(); // split hourly value in minutes

        integratedValue += value;
        for (int i1 = 0; i1 < 3; i1++) {
            timeSeries.add(new Minute(date.toDate()), integratedValue);
            date = date.plusMinutes(1);
        }
    }

    TimeSeries ordersPriceInCentsTimeSeries = MovingAverage.createMovingAverage(timeSeries,
            "shopping-cart.OrdersPriceInCents", 60 * 7, 0);

    TimeSeries ordersPriceInCentsSrv1TimeSeries = new TimeSeries("srv1.shopping-cart.OrdersPriceInCents");
    TimeSeries ordersPriceInCentsSrv2TimeSeries = new TimeSeries("srv2.shopping-cart.OrdersPriceInCents");
    int resetValue2ToZeroOffset = 0; // reset value 2 after 3 days of metrics
    for (int i = 0; i < ordersPriceInCentsTimeSeries.getItemCount(); i++) {
        TimeSeriesDataItem dataItem = ordersPriceInCentsTimeSeries.getDataItem(i);
        int value = dataItem.getValue().intValue();
        // value1 is 5% higher to value2 due to a 'weirdness' in the load balancing
        int value1 = Math.min((int) (value * 1.05 / 2), value);

        {
            // simulate srv2 restart
            DateTime currentDate = new DateTime(dataItem.getPeriod().getStart());
            boolean shouldResetValue2 = resetValue2ToZeroOffset == 0
                    && currentDate.getDayOfYear() == twoDaysAfterBegin.getDayOfYear();
            if (shouldResetValue2) {
                resetValue2ToZeroOffset = value - value1;
                System.out.println("reset value2 of " + resetValue2ToZeroOffset + " at " + currentDate);
            }
        }

        int value2 = value - value1 - resetValue2ToZeroOffset;
        // System.out.println("value=" + value + ", value1=" + value1 + ", value2=" + value2);
        ordersPriceInCentsSrv1TimeSeries.add(dataItem.getPeriod(), value1);
        ordersPriceInCentsSrv2TimeSeries.add(dataItem.getPeriod(), value2);
    }

    TimeSeries orderItemsCountTimeSeries = new TimeSeries("shopping-cart.OrderItemsCount");
    TimeSeries orderItemsCountSrv1TimeSeries = new TimeSeries("srv1.shopping-cart.OrderItemsCount");
    TimeSeries orderItemsCountSrv2TimeSeries = new TimeSeries("srv2.shopping-cart.OrderItemsCount");

    for (int i = 0; i < ordersPriceInCentsTimeSeries.getItemCount(); i++) {
        RegularTimePeriod period = ordersPriceInCentsTimeSeries.getDataItem(i).getPeriod();
        int ordersPriceInCents1 = ordersPriceInCentsSrv1TimeSeries.getDataItem(i).getValue().intValue();
        int ordersPriceInCents2 = ordersPriceInCentsSrv2TimeSeries.getDataItem(i).getValue().intValue();

        int value1 = ordersPriceInCents1 / 600;
        int value2 = ordersPriceInCents2 / 600;

        orderItemsCountTimeSeries.add(period, value1 + value2);
        orderItemsCountSrv1TimeSeries.add(period, value1);
        orderItemsCountSrv2TimeSeries.add(period, value2);

    }

    exportMetrics(ordersPriceInCentsTimeSeries, ordersPriceInCentsSrv1TimeSeries,
            ordersPriceInCentsSrv2TimeSeries, ordersPriceInCentsTimeSeries, orderItemsCountTimeSeries,
            orderItemsCountSrv1TimeSeries, orderItemsCountSrv2TimeSeries);

    TimeSeries activeSrv1Visitors = new TimeSeries("srv1.visitors.currentActive");
    TimeSeries activeSrv2Visitors = new TimeSeries("srv1.visitors.currentActive");

}

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  a  va  2 s.co  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;
}