Example usage for org.joda.time DateTime getDayOfYear

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

Introduction

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

Prototype

public int getDayOfYear() 

Source Link

Document

Get the day of year field value.

Usage

From source file:fr.amap.commons.animation.Timeline.java

public void start() {

    fireStarted();/*  w w w  .j a  v a  2  s. c  o m*/

    DateTime currentTime = new DateTime(startTime);
    int lastDoy = currentTime.getDayOfYear();

    fireTimeChanged(currentTime);
    fireDoyChanged(currentTime);

    while (currentTime.compareTo(endTime) <= 0) {
        currentTime = currentTime.plusMillis((int) (timeStep * 3600 * 1000));

        if (currentTime.compareTo(endTime) > 0) {
            break;
        }

        if (currentTime.getDayOfYear() != lastDoy) {

            lastDoy = currentTime.getDayOfYear();
            fireDoyChanged(currentTime);
        }

        fireTimeChanged(currentTime);
    }

    fireFinished();
}

From source file:gov.usgs.anss.query.filefactory.SacHeaders.java

License:Open Source License

public static SacTimeSeries setEventHeader(SacTimeSeries sac, DateTime eventOrigin, Double eventLat,
        Double eventLon, Double eventDepth, Double eventMag, int sacMagType, int sacEventType) {

    if (eventLat == null) {
        eventLat = -12345.0;/*from   w  w  w .j  a  v a2s . co m*/
    }

    if (eventLon == null) {
        eventLon = -12345.0;
    }

    if (eventDepth == null) {
        eventDepth = -12345.0;
    }

    if (eventMag == null) {
        eventMag = -12345.0;
    }

    // SAC stores year day (nzjday) but not month and day.  
    DateTime start = new DateTime(sac.nzyear, 1, 1, sac.nzhour, sac.nzmin, sac.nzsec, sac.nzmsec,
            DateTimeZone.UTC);
    start = start.withDayOfYear(sac.nzjday);

    double timeDiff = (start.getMillis() - eventOrigin.getMillis()) / 1000.0d;

    sac.nzyear = eventOrigin.getYear();
    sac.nzjday = eventOrigin.getDayOfYear();
    sac.nzhour = eventOrigin.getHourOfDay();
    sac.nzmin = eventOrigin.getMinuteOfHour();
    sac.nzsec = eventOrigin.getSecondOfMinute();
    sac.nzmsec = eventOrigin.getMillisOfSecond();

    sac.b = sac.b + timeDiff;
    sac.e = sac.e + timeDiff;

    sac.iztype = SacTimeSeries.IO;

    sac.evla = eventLat;
    sac.evlo = eventLon;
    sac.evdp = eventDepth;
    sac.mag = eventMag;
    sac.imagtyp = sacMagType;
    sac.ievtyp = sacEventType;

    sac.lcalda = 1;

    return sac;
}

From source file:io.warp10.script.functions.TSELEMENTS.java

License:Apache License

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {

    Object obj = stack.peek();// w w w.  j  a  v  a  2 s .com

    String tz = null;

    if (obj instanceof String) {
        tz = (String) obj;
        stack.pop();
    } else if (!(obj instanceof Long)) {
        throw new WarpScriptException(getName() + " operates on a timestamp or a timestamp + timezone.");
    }

    DateTimeZone dtz = this.tzones.get(tz);

    if (null == dtz) {
        dtz = DateTimeZone.forID(null == tz ? "UTC" : tz);
        this.tzones.put(tz, dtz);
    }

    obj = stack.pop();

    if (!(obj instanceof Long)) {
        throw new WarpScriptException(getName() + " operates on a timestamp or a timestamp + timezone.");
    }

    long ts = (long) obj;

    // Convert ts to milliseconds

    long tsms = ts / Constants.TIME_UNITS_PER_MS;

    DateTime dt = new DateTime(tsms, dtz);

    // Extract components into an array

    List<Long> elements = new ArrayList<Long>();

    elements.add((long) dt.getYear());
    elements.add((long) dt.getMonthOfYear());
    elements.add((long) dt.getDayOfMonth());
    elements.add((long) dt.getHourOfDay());
    elements.add((long) dt.getMinuteOfHour());
    elements.add((long) dt.getSecondOfMinute());
    elements.add(ts % Constants.TIME_UNITS_PER_S);
    elements.add((long) dt.getDayOfYear());
    elements.add((long) dt.getDayOfWeek());
    elements.add((long) dt.getWeekOfWeekyear());

    stack.push(elements);

    return stack;
}

From source file:module.mission.domain.NationalMission.java

License:Open Source License

private boolean matchesDay(final DateTime dateTime1, final DateTime dateTime2) {
    return dateTime1.getYear() == dateTime2.getYear() && dateTime1.getDayOfYear() == dateTime2.getDayOfYear();
}

From source file:net.sourceforge.fenixedu.util.renderer.GanttDiagram.java

License:Open Source License

private void generateYearsViewMonthsViewAndDays() {

    DateTime firstMonthDateTime = getFirstInstant();
    DateTime lastMontDateTime = getLastInstant();

    if (firstMonthDateTime != null && lastMontDateTime != null) {
        while ((firstMonthDateTime.getYear() < lastMontDateTime.getYear())
                || (firstMonthDateTime.getYear() == lastMontDateTime.getYear()
                        && firstMonthDateTime.getDayOfYear() <= lastMontDateTime.getDayOfYear())) {

            getDays().add(firstMonthDateTime);

            YearMonthDay day = firstMonthDateTime.toYearMonthDay().withDayOfMonth(1);
            if (getMonthsView().containsKey(day)) {
                getMonthsView().put(day, getMonthsView().get(day) + 1);
            } else {
                getMonthsView().put(day, 1);
            }/*from w w w .  j  a va  2 s.  c  o  m*/

            if (getYearsView().containsKey(Integer.valueOf(firstMonthDateTime.getYear()))) {
                getYearsView().put(Integer.valueOf(firstMonthDateTime.getYear()),
                        getYearsView().get(Integer.valueOf(firstMonthDateTime.getYear())) + 1);
            } else {
                getYearsView().put(Integer.valueOf(firstMonthDateTime.getYear()), 1);
            }

            firstMonthDateTime = firstMonthDateTime.plusDays(1);
        }
    }
}

From source file:net.tourbook.chart.ChartComponents.java

License:Open Source License

private void createDrawingData_X_History(final GraphDrawingData graphDrawingData,
        final double graphDefaultUnitD) {

    final ChartDataXSerie xData = graphDrawingData.getXData();
    final double scaleX = graphDrawingData.getScaleX();

    final long graphMaxValue = (long) xData.getOriginalMaxValue();
    final long graphDefaultUnit = (long) graphDefaultUnitD;

    // get start time without mills
    final DateTime tourStartTime = xData.getStartDateTime().minus(xData.getStartDateTime().getMillisOfSecond());
    final DateTime tourEndTime = tourStartTime.plus(graphMaxValue * 1000);

    long unitStart = tourStartTime.getMillis();
    long unitEnd = graphMaxValue;
    long firstUnitYear = tourStartTime.getYear();
    long lastUnitYear = tourEndTime.getYear();

    long roundedYearUnit = 0;
    long majorRoundedYearUnit = 0;
    final double dev1Year = scaleX * YEAR_IN_SECONDS;
    final double dev1Month = scaleX * MONTH_IN_SECONDS;

    //      System.out.println(UI.timeStampNano() + " \t");
    //      System.out.println(UI.timeStampNano() + " createDrawingData_X_History\t" + " start: " + tourStartTime);
    //      // TODO remove SYSTEM.OUT.PRINTLN

    final double devTitleVisibleUnit = _devAllMonthLabelWidth * 1.2;

    final boolean isYearRounded = dev1Year < _devYearLabelWidth * 4;
    if (isYearRounded) {

        /*/*from   w w  w  .  j  a  v  a 2 s . com*/
         * adjust years to the rounded values
         */

        final double unitYears = (double) graphDefaultUnit / YEAR_IN_SECONDS;

        roundedYearUnit = Util.roundSimpleNumberUnits((long) unitYears);
        majorRoundedYearUnit = Util.getMajorSimpleNumberValue(roundedYearUnit);

        final long firstHistoryYear = tourStartTime.getYear();

        // decrease min value when it does not fit to unit borders
        final long yearMinRemainder = firstHistoryYear % roundedYearUnit;
        final long yearMinValue = firstHistoryYear - yearMinRemainder;

        final long yearMaxValue = lastUnitYear - (lastUnitYear % roundedYearUnit) + roundedYearUnit;

        unitStart = new DateTime((int) yearMinValue, 1, 1, 0, 0, 0, 0).getMillis();
        unitEnd = new DateTime((int) yearMaxValue, 12, 31, 23, 59, 59, 999).getMillis();
        firstUnitYear = yearMinValue;
        lastUnitYear = yearMaxValue;
    }

    /*
     * check if history units must be created, this is done only once for a tour to optimize it
     */
    if (unitStart != _historyUnitStart || unitEnd != _historyUnitDuration) {

        _historyUnitStart = unitStart;
        _historyUnitDuration = unitEnd;

        createHistoryUnits((int) firstUnitYear, (int) lastUnitYear);
    }

    graphDrawingData.setXUnitTextPos(GraphDrawingData.X_UNIT_TEXT_POS_CENTER);
    graphDrawingData.setIsXUnitOverlapChecked(true);
    graphDrawingData.setIsCheckUnitBorderOverlap(false);

    final HistoryTitle historyTitle = new HistoryTitle();
    xData.setHistoryTitle(historyTitle);

    // hide default unit
    xData.setUnitLabel(UI.EMPTY_STRING);

    final double devGraphXOffset = componentGraph.getXXDevViewPortLeftBorder();
    final int devVisibleWidth = getDevVisibleChartWidth();

    final long graphLeftBorder = (long) (devGraphXOffset / scaleX);
    final long graphRightBorder = (long) ((devGraphXOffset + devVisibleWidth) / scaleX);

    final ArrayList<ChartUnit> xUnits = graphDrawingData.getXUnits();
    final ArrayList<ChartUnit> xUnitTitles = new ArrayList<ChartUnit>();

    final ArrayList<Long> titleValueStart = historyTitle.graphStart = new ArrayList<Long>();
    final ArrayList<Long> titleValueEnd = historyTitle.graphEnd = new ArrayList<Long>();
    final ArrayList<String> titleText = historyTitle.titleText = new ArrayList<String>();

    final boolean isTimeSerieWithTimeZoneAdjustment = xData.isTimeSerieWithTimeZoneAdjustment();

    //      DateTime graphTime = tourStartTime.plus(graphLeftBorder * 1000);
    //      if (isTimeSerieWithTimeZoneAdjustment) {
    //         if (graphTime.getMillis() > UI.beforeCET) {
    //            graphTime = graphTime.minus(UI.BERLIN_HISTORY_ADJUSTMENT * 1000);
    //         }
    //      }
    //
    ////      final int graphSecondsOfDay = graphTime.getSecondOfDay();
    ////      final DateTime graphNextDay = graphTime.plus((DAY_IN_SECONDS - graphSecondsOfDay) * 1000);
    //
    //      System.out.println(UI.timeStampNano());
    //      System.out.println(UI.timeStampNano() + " tourStartTime " + tourStartTime);
    //      System.out.println(UI.timeStampNano() + " graphTime     " + graphTime);
    ////      System.out.println(UI.timeStampNano() + " graphNextDay  " + graphNextDay);
    //      System.out.println(UI.timeStampNano());
    //      // TODO remove SYSTEM.OUT.PRINTLN

    if (isYearRounded) {

        /*
         * create units for rounded years
         */

        //         System.out.println(UI.timeStampNano() + "\trounded years\t");
        //         // TODO remove SYSTEM.OUT.PRINTLN

        graphDrawingData.setXUnitTextPos(GraphDrawingData.X_UNIT_TEXT_POS_LEFT);

        int historyYearIndex = 0;

        /*
         * start unit at the first day of the first year at 0:00:00, this is necessary that the
         * unit is positioned exactly
         */
        final int startDOY = tourStartTime.getDayOfYear();
        final int startDaySeconds = tourStartTime.secondOfDay().get();

        final int startYear = tourStartTime.getYear();

        int yearIndex = 0;
        long graphYearOffset = 0;
        while (startYear > _historyYears[yearIndex]) {
            graphYearOffset += _historyDOY[yearIndex++] * DAY_IN_SECONDS;
        }

        long graphValue = -startDOY * DAY_IN_SECONDS - startDaySeconds - graphYearOffset;

        // loop: years
        while (graphValue <= graphMaxValue) {

            long graphUnit = 0;

            for (int unitIndex = 0; unitIndex < roundedYearUnit; unitIndex++) {

                final int unitYearIndex = historyYearIndex + unitIndex;

                // graph unit = rounded years
                graphUnit += _historyDOY[unitYearIndex] * DAY_IN_SECONDS;
            }

            if (graphValue < graphLeftBorder - graphUnit //
            //
            // ensure it's 366 days
                    - DAY_IN_SECONDS) {

                // advance to the next unit
                graphValue += graphUnit;
                historyYearIndex += roundedYearUnit;

                continue;
            }

            if (graphValue > graphRightBorder) {
                break;
            }

            /*
             * draw year tick
             */
            final int yearValue = _historyYears[historyYearIndex];

            final boolean isMajorValue = yearValue % majorRoundedYearUnit == 0;

            xUnits.add(new ChartUnit(graphValue + DAY_IN_SECONDS, UI.EMPTY_STRING, isMajorValue));

            /*
             * draw title
             */
            titleValueStart.add(graphValue);
            titleValueEnd.add(graphValue + graphUnit - 1);
            titleText.add(Integer.toString(yearValue));

            // advance to the next rounded unit
            graphValue += graphUnit;
            historyYearIndex += roundedYearUnit;
        }

    } else if (dev1Year < _devAllMonthLabelWidth * 12) {

        /*
         * create units for year/month
         */

        //         System.out.println(UI.timeStampNano() + "\tyear/month\t");
        //         // TODO remove SYSTEM.OUT.PRINTLN

        graphDrawingData.setTitleTextPos(GraphDrawingData.X_UNIT_TEXT_POS_CENTER);
        graphDrawingData.setXUnitTextPos(GraphDrawingData.X_UNIT_TEXT_POS_CENTER);

        int historyYearIndex = 0;

        // start unit at the first day of the first year at 0:00:00
        final int startDOY = tourStartTime.getDayOfYear();
        final int startSeconds = tourStartTime.secondOfDay().get();
        long graphValue = -startDOY * DAY_IN_SECONDS - startSeconds;

        // loop: years
        while (graphValue <= graphMaxValue) {

            // graph unit = 1 year
            final long graphUnit = _historyDOY[historyYearIndex] * DAY_IN_SECONDS;

            if (graphValue < graphLeftBorder - graphUnit //
            //
            // ensure it's 366 days
                    - DAY_IN_SECONDS) {

                // advance to the next unit
                graphValue += graphUnit;
                historyYearIndex++;

                continue;
            }

            if (graphValue > graphRightBorder) {
                break;
            }

            final int devUnitWidth = (int) (scaleX * graphUnit);
            final int[] historyMonthDays = _historyMonths[historyYearIndex];

            /*
             * draw year tick
             */
            xUnits.add(new ChartUnit(graphValue + DAY_IN_SECONDS, UI.EMPTY_STRING, true));

            /*
             * draw year title
             */
            {
                final String yearLabel = Integer.toString(_historyYears[historyYearIndex]);

                /*
                 * get number of repeated year labels within a year unit
                 */
                int repeatedMonths = 1;

                while (true) {
                    if (devUnitWidth / repeatedMonths < devTitleVisibleUnit) {
                        break;
                    }
                    repeatedMonths++;
                }

                // ensure array size is big enough (*2)
                final int[] monthStarts = new int[repeatedMonths * 2];
                final int[] monthEnds = new int[repeatedMonths * 2];
                final int monthRepeats = 12 / repeatedMonths;

                int yearMonthDOY = 0;
                int repeatIndex = 0;

                for (int monthIndex = 0; monthIndex < 12; monthIndex++) {

                    final int monthDays = historyMonthDays[monthIndex];

                    if (monthIndex % monthRepeats == 0) {

                        if (repeatIndex > 0) {
                            monthEnds[repeatIndex - 1] = yearMonthDOY;
                        }

                        monthStarts[repeatIndex] = yearMonthDOY;

                        repeatIndex++;
                    }

                    yearMonthDOY += monthDays;
                }
                monthEnds[repeatIndex - 1] = yearMonthDOY;

                for (int repeatIndex2 = 0; repeatIndex2 < monthStarts.length; repeatIndex2++) {

                    final int monthStart = monthStarts[repeatIndex2];
                    final int monthEnd = monthEnds[repeatIndex2];

                    // skip invalid entries
                    if (monthStart == 0 && monthEnd == 0) {
                        break;
                    }

                    titleValueStart.add(graphValue + monthStart * DAY_IN_SECONDS + DAY_IN_SECONDS);
                    titleValueEnd.add(graphValue + monthEnd * DAY_IN_SECONDS + DAY_IN_SECONDS);

                    titleText.add(yearLabel);
                }
            }

            /*
             * draw x-axis units
             */

            if (devUnitWidth >= _devAllMonthLabelWidth * 1.2) {

                createHistoryMonthUnits_Months(xUnits, historyMonthDays, graphValue, 1, 12, true);

            } else if (devUnitWidth >= _devAllMonthLabelWidth * 1) {

                createHistoryMonthUnits_Months(xUnits, historyMonthDays, graphValue, 3, 0, false);

            } else if (devUnitWidth >= _devAllMonthLabelWidth * 0.7) {

                createHistoryMonthUnits_Months(xUnits, historyMonthDays, graphValue, 6, 0, false);
            }

            // advance to the next unit
            graphValue += graphUnit;
            historyYearIndex++;
        }

    } else if (dev1Month < _devAllMonthLabelWidth * 30) {

        /*
         * create units for month/day
         */

        //         System.out.println(UI.timeStampNano() + "\tmonth/day");
        //         // TODO remove SYSTEM.OUT.PRINTLN

        graphDrawingData.setTitleTextPos(GraphDrawingData.X_UNIT_TEXT_POS_CENTER);

        int historyYearIndex = 0;

        // start unit at the first day of the first year at 0:00:00
        final int startDOY = tourStartTime.getDayOfYear();
        final int startSeconds = tourStartTime.secondOfDay().get();
        long graphValue = -startDOY * DAY_IN_SECONDS - startSeconds;

        monthLoop:

        // loop: months
        while (graphValue <= graphMaxValue) {

            final int[] yearMonths = _historyMonths[historyYearIndex];

            for (int monthIndex = 0; monthIndex < yearMonths.length; monthIndex++) {

                final int monthDays = yearMonths[monthIndex];

                // graph unit = 1 month
                final long graphUnit = monthDays * DAY_IN_SECONDS;

                if (graphValue < graphLeftBorder - graphUnit) {

                    // advance to the next month unit
                    graphValue += graphUnit;

                    continue;
                }

                if (graphValue > graphRightBorder) {
                    break monthLoop;
                }

                /*
                 * draw month tick
                 */
                xUnits.add(new ChartUnit(graphValue + DAY_IN_SECONDS, UI.EMPTY_STRING, true));

                /*
                 * create title units
                 */
                {
                    final String monthTitle = _monthLabels[monthIndex] + UI.SPACE2
                            + Integer.toString(_historyYears[historyYearIndex]);

                    // get number of repeated labels within one graph unit
                    int repeatedDays = 1;
                    final int devUnitWidth = (int) (scaleX * graphUnit);

                    while (true) {
                        if (devUnitWidth / repeatedDays < devTitleVisibleUnit) {
                            break;
                        }
                        repeatedDays++;
                    }

                    // ensure array size is big enough (*2)
                    final int[] dayStarts = new int[repeatedDays * 2];
                    final int[] dayEnds = new int[repeatedDays * 2];
                    final int repeatedDayUnit = monthDays / repeatedDays;

                    int dayStartEnd = 0;
                    int repeatIndex = 0;

                    for (int dayIndex = 0; dayIndex < monthDays; dayIndex++) {

                        if (dayIndex % repeatedDayUnit == 0) {

                            if (repeatIndex > 0) {
                                dayEnds[repeatIndex - 1] = dayStartEnd;
                            }

                            dayStarts[repeatIndex] = dayStartEnd;

                            repeatIndex++;
                        }

                        dayStartEnd += 1;
                    }
                    dayEnds[repeatIndex - 1] = dayStartEnd;

                    for (int repeatIndex2 = 0; repeatIndex2 < dayStarts.length; repeatIndex2++) {

                        final int dayStart = dayStarts[repeatIndex2];
                        final int dayEnd = dayEnds[repeatIndex2];

                        // skip invalid entries
                        if (dayStart == 0 && dayEnd == 0) {
                            break;
                        }

                        titleValueStart.add(graphValue + dayStart * DAY_IN_SECONDS + DAY_IN_SECONDS);
                        titleValueEnd.add(graphValue + dayEnd * DAY_IN_SECONDS + DAY_IN_SECONDS);
                        titleText.add(monthTitle);
                    }
                }

                /*
                 * draw x-axis units: day number in month
                 */
                final double unitDays = (double) graphDefaultUnit / DAY_IN_SECONDS;

                final int roundedDayUnit = Util.roundSimpleNumberUnits((long) unitDays);

                if (roundedDayUnit == 1) {
                    graphDrawingData.setXUnitTextPos(GraphDrawingData.X_UNIT_TEXT_POS_CENTER);
                } else {
                    graphDrawingData.setXUnitTextPos(GraphDrawingData.X_UNIT_TEXT_POS_LEFT);
                }

                int dayNo = roundedDayUnit;
                while (dayNo <= monthDays) {

                    xUnits.add(new ChartUnit(//
                            graphValue + (dayNo * DAY_IN_SECONDS), Integer.toString(dayNo), false));

                    dayNo += roundedDayUnit;
                }

                // advance to the next month unit
                graphValue += graphUnit;
            }

            historyYearIndex++;
        }

    } else {

        /*
         * create units for day/seconds
         */

        //         System.out.println(UI.timeStampNano() + " day/seconds");
        //         // TODO remove SYSTEM.OUT.PRINTLN

        graphDrawingData.setTitleTextPos(GraphDrawingData.X_UNIT_TEXT_POS_CENTER);
        graphDrawingData.setXUnitTextPos(GraphDrawingData.X_UNIT_TEXT_POS_LEFT);

        final long graphUnit = Util.roundTime24h(graphDefaultUnit);
        final long majorUnit = Util.getMajorTimeValue24(graphUnit);

        final int startSeconds = tourStartTime.secondOfDay().get();
        final long startUnitOffset = startSeconds % graphUnit;

        // decrease min value when it does not fit to unit borders, !!! VERY IMPORTANT !!!
        final long graphValueStart = graphLeftBorder - graphLeftBorder % graphUnit;

        final long graphMaxVisibleValue = graphRightBorder + graphUnit;
        long graphValue = graphValueStart;

        /*
         * create x-axis units
         */
        while (graphValue <= graphMaxVisibleValue) {

            // create unit value/label
            final long unitValueAdjusted = graphValue - startUnitOffset;
            final long unitValueStart = unitValueAdjusted + startSeconds;

            final long unitValue = unitValueStart % DAY_IN_SECONDS;

            final String unitLabel = net.tourbook.chart.Util.format_hh_mm_ss_Optional(unitValue);

            final boolean isMajorValue = unitValue % majorUnit == 0;

            xUnits.add(new ChartUnit(unitValueAdjusted, unitLabel, isMajorValue));

            graphValue += graphUnit;
        }

        /*
         * create dummy units before and after the real units that the title is displayed also
         * at the border, title is displayed between major units
         */
        final int numberOfSmallUnits = (int) (majorUnit / graphUnit);
        long titleUnitStart = (long) xUnits.get(0).value;

        for (int unitIndex = numberOfSmallUnits; unitIndex > 0; unitIndex--) {

            final long unitValueAdjusted = titleUnitStart - (graphUnit * unitIndex);

            final long unitValue = (unitValueAdjusted + startSeconds) % DAY_IN_SECONDS;
            final boolean isMajorValue = unitValue % majorUnit == 0;

            final String unitLabel = net.tourbook.chart.Util.format_hh_mm_ss_Optional(unitValue);

            xUnitTitles.add(new ChartUnit(unitValueAdjusted, unitLabel, isMajorValue));
        }

        xUnitTitles.addAll(xUnits);

        titleUnitStart = (long) xUnitTitles.get(xUnitTitles.size() - 1).value;

        for (int unitIndex = 1; unitIndex < numberOfSmallUnits * 1; unitIndex++) {

            final long unitValueAdjusted = titleUnitStart + (graphUnit * unitIndex);

            final long unitValue = (unitValueAdjusted + startSeconds) % DAY_IN_SECONDS;
            final boolean isMajorValue = unitValue % majorUnit == 0;

            final String unitLabel = net.tourbook.chart.Util.format_hh_mm_ss_Optional(unitValue);

            xUnitTitles.add(new ChartUnit(unitValueAdjusted, unitLabel, isMajorValue));
        }

        /*
         * create title units
         */
        long prevGraphUnitValue = Long.MIN_VALUE;

        for (int unitIndex = 0; unitIndex < xUnitTitles.size(); unitIndex++) {

            final ChartUnit chartUnit = xUnitTitles.get(unitIndex);
            if (chartUnit.isMajorValue) {

                final long currentGraphUnitValue = (long) chartUnit.value;

                if (prevGraphUnitValue != Long.MIN_VALUE) {

                    titleValueStart.add(prevGraphUnitValue);
                    titleValueEnd.add(currentGraphUnitValue - 1);

                    long graphDay = tourStartTime.getMillis() + prevGraphUnitValue * 1000;

                    if (isTimeSerieWithTimeZoneAdjustment) {

                        if (graphDay > UI.beforeCET) {
                            graphDay -= UI.BERLIN_HISTORY_ADJUSTMENT * 1000;
                        }
                    }

                    final String dayTitle = _dtFormatter.print(graphDay);

                    titleText.add(dayTitle);
                }

                prevGraphUnitValue = currentGraphUnitValue;
            }
        }
    }

    //      System.out.println(UI.timeStampNano() + " \t");
    //
    //      for (final ChartUnit xUnit : xUnits) {
    //         System.out.println(UI.timeStampNano() + " \t" + xUnit);
    //         // TODO remove SYSTEM.OUT.PRINTLN
    //      }
    //
    //
    //      for (final ChartUnit xUnit : xUnitTitles) {
    //         System.out.println(UI.timeStampNano() + " \t" + xUnit);
    //         // TODO remove SYSTEM.OUT.PRINTLN
    //      }
    //
    //      for (int unitIndex = 0; unitIndex < titleText.size(); unitIndex++) {
    //
    //         System.out.println(UI.timeStampNano()
    //               + ("\t" + titleText.get(unitIndex))
    //               + ("\t" + (long) ((long) (titleValueStart.get(unitIndex) * scaleX) - devGraphXOffset))
    //               + ("\t" + (long) ((long) (titleValueEnd.get(unitIndex) * scaleX) - devGraphXOffset))
    //               + ("\t" + titleValueStart.get(unitIndex))
    //               + ("\t" + titleValueEnd.get(unitIndex))
    //         //
    //               );
    //         // TODO remove SYSTEM.OUT.PRINTLN
    //      }
}

From source file:net.tourbook.ui.views.tourCatalog.YearStatisticView.java

License:Open Source License

/**
 * show statistic for several years//from w ww  .java 2s. com
 *
 * @param isShowLatestYear
 *            shows the latest year and the years before
 */
private void updateYearChart(final boolean isShowLatestYear) {

    if (_currentRefItem == null) {
        return;
    }

    _pageBook.showPage(_pageChart);

    final Object[] yearItems = _currentRefItem.getFetchedChildrenAsArray();

    // get the last year when it's forced
    if (isShowLatestYear && yearItems != null && yearItems.length > 0) {

        final Object item = yearItems[yearItems.length - 1];

        if (item instanceof TVICatalogYearItem) {
            _lastYear = ((TVICatalogYearItem) item).year;
        }
    }

    _allTours.clear();
    _DOYValues.clear();
    _tourSpeed.clear();

    final int firstYear = getFirstYear();

    // loop: all years
    for (final Object yearItemObj : yearItems) {
        if (yearItemObj instanceof TVICatalogYearItem) {

            final TVICatalogYearItem yearItem = (TVICatalogYearItem) yearItemObj;

            // check if the year can be displayed
            final int yearItemYear = yearItem.year;
            if (yearItemYear >= firstYear && yearItemYear <= _lastYear) {

                // loop: all tours
                final Object[] tourItems = yearItem.getFetchedChildrenAsArray();
                for (final Object tourItemObj : tourItems) {
                    if (tourItemObj instanceof TVICatalogComparedTour) {

                        final TVICatalogComparedTour tourItem = (TVICatalogComparedTour) tourItemObj;

                        final DateTime dt = new DateTime(tourItem.getTourDate());

                        _DOYValues.add(getYearDOYs(dt.getYear()) + dt.getDayOfYear() - 1);
                        _tourSpeed.add((int) (tourItem.getTourSpeed() * 10 / UI.UNIT_VALUE_DISTANCE));
                        _allTours.add(tourItem);
                    }
                }
            }
        }
    }

    final ChartDataModel chartModel = new ChartDataModel(ChartDataModel.CHART_TYPE_BAR);

    final ChartDataXSerie xData = new ChartDataXSerie(ArrayListToArray.toInt(_DOYValues));
    xData.setAxisUnit(ChartDataXSerie.AXIS_UNIT_DAY);
    xData.setChartSegments(createChartSegments());
    chartModel.setXData(xData);

    // set the bar low/high data
    final ChartDataYSerie yData = new ChartDataYSerie(ChartDataModel.CHART_TYPE_BAR,
            ArrayListToArray.toInt(_tourSpeed));
    yData.setValueDivisor(10);
    TourManager.setGraphColor(_prefStore, yData, GraphColorProvider.PREF_GRAPH_SPEED);

    /*
     * set/restore min/max values
     */
    final TVICatalogRefTourItem refItem = _currentRefItem;
    final int minValue = yData.getVisibleMinValue();
    final int maxValue = yData.getVisibleMaxValue();

    final int dataMinValue = minValue - (minValue / 10);
    final int dataMaxValue = maxValue + (maxValue / 20);

    if (_isSynchMaxValue) {

        if (refItem.yearMapMinValue == Integer.MIN_VALUE) {

            // min/max values have not yet been saved

            /*
             * set the min value 10% below the computed so that the lowest value is not at the
             * bottom
             */
            yData.setVisibleMinValue(dataMinValue);
            yData.setVisibleMaxValue(dataMaxValue);

            refItem.yearMapMinValue = dataMinValue;
            refItem.yearMapMaxValue = dataMaxValue;

        } else {

            /*
             * restore min/max values, but make sure min/max values for the current graph are
             * visible and not outside of the chart
             */

            refItem.yearMapMinValue = Math.min(refItem.yearMapMinValue, dataMinValue);
            refItem.yearMapMaxValue = Math.max(refItem.yearMapMaxValue, dataMaxValue);

            yData.setVisibleMinValue(refItem.yearMapMinValue);
            yData.setVisibleMaxValue(refItem.yearMapMaxValue);
        }

    } else {
        yData.setVisibleMinValue(dataMinValue);
        yData.setVisibleMaxValue(dataMaxValue);
    }

    yData.setYTitle(Messages.tourCatalog_view_label_year_chart_title);
    yData.setUnitLabel(UI.UNIT_LABEL_SPEED);

    chartModel.addYData(yData);

    // set tool tip info
    chartModel.setCustomData(ChartDataModel.BAR_TOOLTIP_INFO_PROVIDER, new IChartInfoProvider() {
        @Override
        public ChartToolTipInfo getToolTipInfo(final int serieIndex, final int valueIndex) {
            return createToolTipInfo(valueIndex);
        }
    });

    // set grid size
    _yearChart.setGridDistance(_prefStore.getInt(ITourbookPreferences.GRAPH_GRID_HORIZONTAL_DISTANCE),
            _prefStore.getInt(ITourbookPreferences.GRAPH_GRID_VERTICAL_DISTANCE));

    // show the data in the chart
    _yearChart.updateChart(chartModel, false, true);

    /*
     * update start year combo box
     */
    _cboLastYear.removeAll();
    _comboYears.clear();

    for (int year = firstYear - 1; year <= _lastYear + _numberOfYears; year++) {
        _cboLastYear.add(Integer.toString(year));
        _comboYears.add(year);
    }

    _cboLastYear.select(_numberOfYears - 0);
}

From source file:org.apache.phoenix.expression.function.DayOfYearFunction.java

License:Apache License

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    Expression arg = getChildren().get(0);
    if (!arg.evaluate(tuple, ptr)) {
        return false;
    }// ww w.  j ava 2s. c  o  m
    if (ptr.getLength() == 0) {
        return true;
    }
    long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder());
    DateTime jodaDT = new DateTime(dateTime);
    int day = jodaDT.getDayOfYear();
    PDataType returnDataType = getDataType();
    byte[] byteValue = new byte[returnDataType.getByteSize()];
    returnDataType.getCodec().encodeInt(day, byteValue, 0);
    ptr.set(byteValue);
    return true;
}

From source file:org.artifactory.security.jobs.PasswordExpireNotificationJob.java

License:Open Source License

/**
 * Produces unique (per user) email body
 *
 * @param userName          user name// w  w w.j  ava2  s.  c om
 * @param passwordCreated   the date when password was created
 * @param plainText         whether email should be send in plain text or html
 *
 * @return email body
 */
public String getMailBody(String userName, Long passwordCreated, boolean plainText) {
    DateTime created = new DateTime(passwordCreated);
    CentralConfigService centralConfigService = ContextHelper.get().beanForType(CentralConfigService.class);
    int expiresIn = centralConfigService.getMutableDescriptor().getSecurity().getPasswordSettings()
            .getExpirationPolicy().getPasswordMaxAge();
    DateTime now = DateTime.now();
    int daysLeft = created.plusDays(expiresIn).minusDays(now.getDayOfYear()).getDayOfYear();
    if ((daysLeft == 365 || daysLeft == 366) && created.plusDays(expiresIn).dayOfYear().get() != daysLeft)
        daysLeft = 0;
    DateTime dueDate = now.plusDays(daysLeft);

    if (daysLeft == 0) {
        if (!plainText)
            return String.format(
                    "<!DOCTYPE html>" + "<html>" + "<body>" + "<p>" + "Dear %s,<br><br>"
                            + "Your Artifactory password is about to expire today (%s).<br>"
                            + "Please change your password before it expires, "
                            + "Once expired you will not be able to  access the<br>"
                            + "Artifactory UI or REST API using that password until it will be changed.<br><br>"
                            + "Password can be changed in <a href=\"" + getProfilePageUrl()
                            + "\">your profile page</a> " + "or by your system administrator.<br><br>" + "</p>"
                            + "</body>" + "</html>",
                    userName.toUpperCase(), dueDate.toString("MMMMM dd, YYYY"));
        return String.format("Dear %s,\n" + "\n" + "Your Artifactory password is about to expire today (%s).\n"
                + "Please change your password before it expires. Once expired you will not be able to  access the\n"
                + "Artifactory UI or REST API using that password until it will be changed.\n" + "\n"
                + "Password can be changed in your page [1] or by your system administrator.\n\n" + "[1] "
                + getProfilePageUrl(), userName.toUpperCase(), dueDate.toString("MMMMM dd, YYYY"));
    } else {
        if (!plainText)
            return String.format("<!DOCTYPE html>" + "<html>" + "<body>" + "<p>" + "Dear %s,<br><br>"
                    + "Your Artifactory password is about to expire in %d " + (daysLeft == 1 ? "day" : "days")
                    + " (%s).<br>" + "Please change your password before it expires, "
                    + "Once expired you will not be able to  access the<br>"
                    + "Artifactory UI or REST API using that password until it will be changed.<br><br>"
                    + "Password can be changed in <a href=\"" + getProfilePageUrl()
                    + "\">your profile page</a> " + "or by your system administrator.<br><br>" + "</p>"
                    + "</body>" + "</html>", userName.toUpperCase(), daysLeft,
                    dueDate.toString("MMMMM dd, YYYY"));
        return String.format("Dear %s,\n" + "\n" + "Your Artifactory password is about to expire in %d "
                + (daysLeft == 1 ? "day" : "days") + " (%s).\n"
                + "Please change your password before it expires. Once expired you will not be able to  access the\n"
                + "Artifactory UI or REST API using that password until it will be changed.\n" + "\n"
                + "Password can be changed in your page [1] or by your system administrator.\n\n" + "[1] "
                + getProfilePageUrl(), userName.toUpperCase(), daysLeft, dueDate.toString("MMMMM dd, YYYY"));
    }
}

From source file:org.artifactory.security.SecurityServiceImpl.java

License:Open Source License

private Integer getDaysLeftUntilPasswordExpires(Long userPasswordCreationTime) {
    Integer daysLeft;/*  w  w  w. ja v a  2s. c  o m*/
    DateTime created = new DateTime(userPasswordCreationTime.longValue());
    int expiresIn = getPasswordExpirationDays();
    DateTime now = DateTime.now();
    daysLeft = created.plusDays(expiresIn).minusDays(now.getDayOfYear()).getDayOfYear();
    if ((daysLeft == 365 || daysLeft == 366) && created.plusDays(expiresIn).dayOfYear().get() != daysLeft) {
        daysLeft = 0;
    }
    return daysLeft;
}