Example usage for org.joda.time DateTime getYear

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

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

From source file:com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition.java

License:Open Source License

public DateTime getDateTimeForNextTransition() {
    final DateTime now = DateTime.now(this.dateTimeZone);
    final DateTime thisYearsTransition = this.getDateTimeForYear(now.getYear());
    if (now.isAfter(thisYearsTransition)) {
        return this.getDateTimeForYear(now.getYear() + 1);
    }/*from  ww w . ja  v  a2s  . c om*/
    return thisYearsTransition;
}

From source file:com.almende.eve.agent.MeetingAgent.java

License:Apache License

/**
 * Merge the busy intervals of all attendees, and the preferred intervals
 *//*from   ww w  .java  2 s.c o m*/
private void mergeTimeConstraints() {
    final ArrayList<Interval> infeasibleIntervals = new ArrayList<Interval>();
    final ArrayList<Weight> preferredIntervals = new ArrayList<Weight>();

    final Activity activity = getActivity();
    if (activity != null) {
        // read and merge the stored busy intervals of all attendees
        for (final Attendee attendee : activity.withConstraints().withAttendees()) {
            final String agent = attendee.getAgent();
            if (attendee.getResponseStatus() != RESPONSE_STATUS.declined) {
                if (new Boolean(true).equals(attendee.getOptional())) {
                    // This attendee is optional.
                    // Add its busy intervals to the soft constraints
                    final List<Interval> attendeeBusy = getAgentBusy(agent);
                    if (attendeeBusy != null) {
                        for (final Interval i : attendeeBusy) {
                            final Weight wi = new Weight(i.getStart(), i.getEnd(),
                                    WEIGHT_BUSY_OPTIONAL_ATTENDEE);

                            preferredIntervals.add(wi);
                        }
                    }
                } else {
                    // this attendee is required.
                    // Add its busy intervals to the hard constraints
                    final List<Interval> attendeeBusy = getAgentBusy(agent);
                    if (attendeeBusy != null) {
                        infeasibleIntervals.addAll(attendeeBusy);
                    }
                }
            }
            // else This attendee declined. Ignore this attendees busy
            // interval
        }

        // read the time preferences and add them to the soft constraints
        final List<Preference> preferences = activity.withConstraints().withTime().withPreferences();
        for (final Preference p : preferences) {
            if (p != null) {
                final Weight wi = new Weight(new DateTime(p.getStart()), new DateTime(p.getEnd()),
                        p.getWeight());

                preferredIntervals.add(wi);
            }
        }
    }

    // add office hours profile to the soft constraints
    // TODO: don't include (hardcoded) office hours here, should be handled
    // by a PersonalAgent
    final DateTime timeMin = DateTime.now();
    final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS);
    final List<Interval> officeHours = IntervalsUtil.getOfficeHours(timeMin, timeMax);
    for (final Interval i : officeHours) {
        final Weight wi = new Weight(i, WEIGHT_OFFICE_HOURS);
        preferredIntervals.add(wi);
    }

    // add delay penalties to the soft constraints
    final DateTime now = DateTime.now();
    final MutableDateTime d = new MutableDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0,
            0, 0, 0);
    for (int i = 0; i <= LOOK_AHEAD_DAYS; i++) {
        final DateTime start = d.toDateTime();
        final DateTime end = start.plusDays(1);
        final Weight wi = new Weight(start, end, WEIGHT_DELAY_PER_DAY * i);
        preferredIntervals.add(wi);
        d.addDays(1);
    }

    // order and store the aggregated lists with intervals
    IntervalsUtil.order(infeasibleIntervals);
    getState().put("infeasible", infeasibleIntervals);
    WeightsUtil.order(preferredIntervals);
    getState().put("preferred", preferredIntervals);
}

From source file:com.anrisoftware.sscontrol.dns.service.DnsServiceImpl.java

License:Open Source License

private int generateSerial(int serial) {
    DateTime date = new DateTime();
    String string = format("%d%d%d%02d", date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), serial);
    return Integer.parseInt(string);
}

From source file:com.axelor.apps.account.service.cfonb.CfonbExportService.java

License:Open Source License

/**
 * Fonction permettant de crer un enregistrement 'metteur' pour un virement des remboursements
 * @param company// w ww  . j  a v a2  s .  co m
 *             Une socit
 * @param dateTime
 *             Une heure
 * @return
 *             Un enregistrement 'emetteur'
 * @throws AxelorException
 */
private String createSenderReimbursementCFONB(DateTime dateTime, BankDetails bankDetails)
        throws AxelorException {

    DateFormat ddmmFormat = new SimpleDateFormat("ddMM");
    String date = ddmmFormat.format(dateTime.toDate());
    date += String.format("%s", StringTool.truncLeft(String.format("%s", dateTime.getYear()), 1));

    // Rcupration des valeurs
    String a = this.cfonbConfig.getSenderRecordCodeExportCFONB(); // Code enregistrement
    String b1 = this.cfonbConfig.getTransferOperationCodeExportCFONB(); // Code opration
    String b2 = ""; // Zone rserve
    String b3 = this.cfonbConfig.getSenderNumExportCFONB(); // Numro d'metteur
    String c1One = ""; // Code CCD
    String c1Two = ""; // Zone rserve
    String c1Three = date; // Date d'chance
    String c2 = this.cfonbConfig.getSenderNameCodeExportCFONB(); // Nom/Raison sociale du donneur d'ordre
    String d1One = ""; // Rfrence de la remise
    String d1Two = ""; // Zone rserve
    String d2One = ""; // Zone rserve
    String d2Two = "E"; // Code monnaie
    String d2Three = ""; // Zone rserve
    String d3 = bankDetails.getSortCode(); // Code guichet de la banque du donneur d'ordre
    String d4 = bankDetails.getAccountNbr(); // Numro de compte du donneur dordre
    String e = ""; // Identifiant du donneur d'ordre
    String f = ""; // Zone rserve
    String g1 = bankDetails.getBankCode(); // Code tablissement de la banque du donneur d'ordre
    String g2 = ""; // Zone rserve

    // Tronquage / remplissage  droite (chaine de caractre)
    b2 = StringTool.fillStringRight(b2, ' ', 8);
    b3 = StringTool.fillStringRight(b3, ' ', 6);
    c1One = StringTool.fillStringRight(c1One, ' ', 1);
    c1Two = StringTool.fillStringRight(c1Two, ' ', 6);
    c2 = StringTool.fillStringRight(c2, ' ', 24);
    d1One = StringTool.fillStringRight(d1One, ' ', 7);
    d1Two = StringTool.fillStringRight(d1Two, ' ', 17);
    d2One = StringTool.fillStringRight(d2One, ' ', 2);
    d2Three = StringTool.fillStringRight(d2Three, ' ', 5);
    d4 = StringTool.fillStringRight(d4, ' ', 11);
    e = StringTool.fillStringRight(e, ' ', 16);
    f = StringTool.fillStringRight(f, ' ', 31);
    g2 = StringTool.fillStringRight(g2, ' ', 6);

    // Tronquage / remplissage  gauche (nombre)
    a = StringTool.fillStringLeft(a, '0', 2);
    b1 = StringTool.fillStringLeft(b1, '0', 2);
    c1Three = StringTool.fillStringLeft(c1Three, '0', 5);
    d3 = StringTool.fillStringLeft(d3, '0', 5);
    g1 = StringTool.fillStringLeft(g1, '0', 5);

    // Vrification AN / N / A
    cfonbToolService.testDigital(a, 0);
    cfonbToolService.testDigital(b1, 0);
    cfonbToolService.testDigital(d3, 0);
    cfonbToolService.testDigital(g1, 0);

    // cration de l'enregistrement
    return a + b1 + b2 + b3 + c1One + c1Two + c1Three + c2 + d1One + d1Two + d2One + d2Two + d2Three + d3 + d4
            + e + f + g1 + g2;
}

From source file:com.barchart.feed.ddf.message.enums.DDF_TradeDay.java

License:BSD License

/**
 * recover full trade date from DDF day code and todays date
 * //from w ww .j  a v a2 s . c  o  m
 * expressed in UTC zone
 * 
 * year, month, day : should be treated as local market trade date.
 *
 * @param tradeDay the trade day
 * @param todayDate the today date
 * @return the time value
 */
public static TimeValue tradeDateFrom(final DDF_TradeDay tradeDay, final DateTime todayDate) {

    // trading day of month reported by the feed
    final int tradingDayNum = tradeDay.day;

    // current day of month
    final int currentDayNum = todayDate.getDayOfMonth();

    // positive for same month if trading date is in the future
    // unless day enum is not a day in the month ???
    final int difference = tradingDayNum - currentDayNum;

    final boolean isSmall = Math.abs(difference) <= HOLIDAY_THESHOLD;
    final boolean isLarge = !isSmall;

    //

    final boolean isSameMonthSameDay = (difference == 0);

    final boolean isSameMonthPastDay = difference < 0 & isSmall;
    final boolean isSameMonthNextDay = difference > 0 & isSmall;

    final boolean isPastMonthPastDay = difference > 0 & isLarge;
    final boolean isNextMonthNextDay = difference < 0 & isLarge;

    //

    DateTime generated;

    try {
        if (isSameMonthSameDay) {
            generated = todayDate;
        } else if (isSameMonthPastDay) {
            generated = todayDate.withDayOfMonth(tradingDayNum);
        } else if (isSameMonthNextDay) {
            generated = todayDate.withDayOfMonth(tradingDayNum);
        } else if (isPastMonthPastDay) {
            generated = todayDate.minusMonths(1).withDayOfMonth(tradingDayNum);
        } else if (isNextMonthNextDay) {
            generated = todayDate.plusMonths(1).withDayOfMonth(tradingDayNum);
        } else {
            logger.error("should not happen");
            generated = todayDate;
        }
    } catch (final Exception e) {
        generated = todayDate;
    }

    final DateTime result = new DateTime(//
            generated.getYear(), //
            generated.getMonthOfYear(), //
            generated.getDayOfMonth(), //
            0, 0, 0, 0, ZONE_UTC);

    final long millisUTC = result.getMillis();

    return ValueBuilder.newTime(millisUTC);

}

From source file:com.barchart.feed.ddf.message.provider.BaseEOD.java

License:BSD License

protected final void encodeDay(final ByteBuffer buffer) {

    final DateTime date = new DateTime(getTradeDay().tradeDate().asMillisUTC(), DateTimeZone.UTC);

    encodeInt(date.getMonthOfYear(), buffer, 2);
    buffer.put(SLASH);//  w w w  .ja v a2 s .  co  m
    encodeInt(date.getDayOfMonth(), buffer, 2);
    buffer.put(SLASH);
    encodeInt(date.getYear(), buffer, 4);
    buffer.put(COMMA);

}

From source file:com.barchart.feed.ddf.symbol.enums.DDF_ExpireYear.java

License:BSD License

/**
 * From date time.//  w w w  .  j  a  v a  2s  . c om
 *
 * @param dateTime the date time
 * @return the dD f_ expire year
 */
public static final DDF_ExpireYear fromDateTime(final DateTime dateTime) {
    final int year = dateTime.getYear();
    final int yearOfDecade = year % 10;
    // NOTE: assumes ascii values
    final char code = (char) (yearOfDecade + '0');
    return fromCode(code);
}

From source file:com.boha.golfkids.util.NewGolfGroupUtil.java

private static Date getDateOfBirth(int age) {

    DateTime dt = new DateTime();
    dt = dt.minusYears(age);/* ww w .  j a va 2  s .  com*/
    Random rand = new Random(System.currentTimeMillis());
    int mth = rand.nextInt(dt.getMonthOfYear());
    int day = rand.nextInt(28);
    if (mth == 0) {
        mth = 1;
    }
    if (day == 0) {
        day = 1;
    }
    DateTime x = new DateTime(dt.getYear(), mth, day, 0, 0);
    return new Date(x.getMillis());
}

From source file:com.bskyb.cg.environments.message.AuditdMessageFormat.java

License:Apache License

@Override
public Message parse(byte[] inMessage) throws ParseException {
    Message message = new LogMessage();
    String textMessage = new String(inMessage);

    StringTokenizer st = new StringTokenizer(textMessage, delimiter);
    String msgType = (String) st.nextElement();
    String timeStamp = (String) st.nextElement();
    DateTime longDate = null;
    try {/*  www .j  a  v a2s  .c  o  m*/
        longDate = parseDate(timeStamp);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (longDate == null) {
        return message;
    }
    String year = new Integer(longDate.getYear()).toString();
    String month = String.format("%02d", new Integer(longDate.getMonthOfYear()));
    String day = String.format("%02d", new Integer(longDate.getDayOfMonth()));

    String hostName = (String) st.nextElement();

    long epochTime = longDate.getMillis();

    UUID uuid = TimeUUIDUtils.getTimeUUID(epochTime);

    String filename = year + "-" + month + "-" + day + "_" + hostName + "_" + msgType + "_" + uuid.toString()
            + "_" + new Long(epochTime).toString();

    String messageText = (String) st.nextElement();
    message.setKey(filename);
    message.setMessage(messageText.getBytes());

    return message;

}

From source file:com.bytestemplar.subgeniuswatchface.BT_SubgeniusWatchface.java

License:Apache License

private String getXDayCountdown() {
    DateTime today = DateTime.now();
    //DateTime today = new DateTime( 1998, 7, 6, 4, 20, 32, 0 );
    DateTime xday = new DateTime(today.getYear(), 7, 5, 7, 0, 0, 0);

    if (today.isAfter(xday)) {
        xday = new DateTime(today.getYear() + 1, 7, 5, 7, 0, 0, 0);
    }//from  w w  w.j  av  a  2 s  .  c  om

    Duration dur = new Duration(today, xday);

    StringBuilder sb = new StringBuilder();

    if (dur.getStandardDays() > 0) {
        sb.append(dur.getStandardDays());
        sb.append(" Day");
        if (dur.getStandardDays() > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    long hours = dur.getStandardHours() % 24;
    if (hours > 0) {
        sb.append(hours);
        sb.append(" Hour");
        if (hours > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    long mins = dur.getStandardMinutes() % 60;
    if (mins > 0) {
        sb.append(mins);
        sb.append(" Minute");
        if (mins > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    long secs = dur.getStandardSeconds() % 60;
    if (secs > 0) {
        sb.append(secs);
        sb.append(" Second");
        if (secs > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    sb.append("Until X-Day!");

    return sb.toString();
}