Example usage for org.joda.time DateTime getMillis

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

Introduction

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

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:com.aionemu.gameserver.services.QuestService.java

License:Open Source License

private static Timestamp countNextRepeatTime(Player player, QuestTemplate template) {
    DateTime now = DateTime.now();//from  w  ww .  ja  v  a2 s  .  c  o m
    DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 9, 0, 0);
    if (template.isDaily()) {
        if (now.isAfter(repeatDate)) {
            repeatDate = repeatDate.plusHours(24);
        }
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400855, "9"));
    } else {
        int daysToAdd = 7;
        int startDay = 7;
        for (QuestRepeatCycle weekDay : template.getRepeatCycle()) {
            int diff = weekDay.getDay() - repeatDate.getDayOfWeek();
            if (diff > 0 && diff < daysToAdd) {
                daysToAdd = diff;
            }
            if (startDay > weekDay.getDay()) {
                startDay = weekDay.getDay();
            }
        }
        if (startDay == daysToAdd) {
            daysToAdd = 7;
        } else if (daysToAdd == 7 && startDay < 7) {
            daysToAdd = 7 - repeatDate.getDayOfWeek() + startDay;
        }
        repeatDate = repeatDate.plusDays(daysToAdd);
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400857, new DescriptionId(1800667), "9"));
    }
    return new Timestamp(repeatDate.getMillis());
}

From source file:com.alfaariss.oa.util.saml2.SAML2ConditionsWindow.java

License:Open Source License

/**
 * Verifies if the current time is within the supplied time window.
 * <br>/*from   ww  w.j  av a  2  s.c o  m*/
 * The time window is extended with configured offsets.
 * 
 * @param dtNB Not Before condition or NULL if not available.
 * @param dtNOA Not On Or After condition or NULL if not available.
 * @return TRUE if the current datetime is within the window.
 */
public boolean canAccept(DateTime dtNB, DateTime dtNOA) {
    DateTime dtNow = new DateTime();

    if (dtNB != null) {
        DateTime dtNotBefore = dtNB.minus(_lBeforeOffset);
        if (dtNow.getMillis() < dtNotBefore.getMillis()) {
            StringBuffer sbDebug = new StringBuffer("Condition time stamp(s) incorrect; Current time (");
            sbDebug.append(dtNow);
            sbDebug.append(") is before the Not Before time: ");
            sbDebug.append(dtNB);
            _logger.debug(sbDebug.toString());
            return false;
        }
    }

    if (dtNOA != null) {
        DateTime dtNotOnOrAfter = dtNOA.plus(_lAfterOffset);
        if (dtNow.getMillis() >= dtNotOnOrAfter.getMillis()) {
            StringBuffer sbDebug = new StringBuffer("Condition time stamp(s) incorrect; Current time (");
            sbDebug.append(dtNow);
            sbDebug.append(") is on or after the Not On Or After time: ");
            sbDebug.append(dtNOA);
            _logger.debug(sbDebug.toString());
            return false;
        }
    }

    return true;
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceConnectionService.java

License:Open Source License

public synchronized void connect(final String ipAddress, final String deviceIdentification, final IED ied,
        final LogicalDevice logicalDevice) throws ConnectionFailureException {
    LOGGER.info("Trying to find connection in cache for deviceIdentification: {}", deviceIdentification);

    if (this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, logicalDevice)) {
        return;/*  ww  w  .j a va  2s  .  c  om*/
    }
    final InetAddress inetAddress = this.convertIpAddress(ipAddress);
    if (inetAddress == null) {
        return;
    }
    // Connect to obtain ClientAssociation and ServerModel.
    LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}",
            deviceIdentification, ipAddress, this.responseTimeout);
    final DateTime startTime = DateTime.now();

    // Create instance of appropriate event listener.
    Iec61850ClientBaseEventListener eventListener = null;
    try {
        eventListener = Iec61850ClientEventListenerFactory.getInstance().getEventListener(ied,
                deviceIdentification, this.deviceManagementService);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error(
                "ProtocolAdapterException: no Iec61850ClientBaseEventListener instance could be contructed, continue without event listener for deviceIdentification: "
                        + deviceIdentification,
                e);
    }

    // For now, the port numbers are defined in the property file. If in
    // the future a database is added to this component, the port
    // numbers for particular devices should be saved using the
    // database.
    int port = 102;
    if (IED.FLEX_OVL.equals(ied)) {
        port = this.iec61850SsldPortServer;
    } else if (IED.ZOWN_RTU.equals(ied)) {
        port = this.iec61850RtuPortServer;
    }

    // Try to connect and receive the ClientAssociation.
    final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850Client
            .connect(deviceIdentification, inetAddress, eventListener, port);
    final ClientAssociation clientAssociation = iec61850ClientAssociation.getClientAssociation();
    // Set response time-out.
    clientAssociation.setResponseTimeout(this.responseTimeout);
    // Read the ServerModel, either from the device or from a SCL file.
    ServerModel serverModel;
    try {
        serverModel = this.readServerModel(clientAssociation, deviceIdentification);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error("ProtocolAdapterException: unable to read ServerModel for deviceIdentification "
                + deviceIdentification, e);
        throw new ConnectionFailureException(e.getMessage(), e);
    }

    // Cache the connection.
    this.cacheIec61850Connection(deviceIdentification,
            new Iec61850Connection(iec61850ClientAssociation, serverModel));

    final DateTime endTime = DateTime.now();
    LOGGER.info(
            "Connected to device: {}, fetched server model. Start time: {}, end time: {}, total time in milliseconds: {}",
            deviceIdentification, startTime, endTime, endTime.minus(startTime.getMillis()).getMillis());
}

From source file:com.alliander.osgp.domain.core.valueobjects.smartmetering.CosemDateTime.java

License:Open Source License

private static int determineDeviation(final DateTime dateTime) {
    return -(dateTime.getZone().getOffset(dateTime.getMillis()) / MILLISECONDS_PER_MINUTE);
}

From source file:com.alliander.osgp.domain.core.valueobjects.smartmetering.CosemDateTime.java

License:Open Source License

private static ClockStatus determineClockStatus(final DateTime dateTime) {
    final Set<ClockStatusBit> statusBits = EnumSet.noneOf(ClockStatusBit.class);
    if (!dateTime.getZone().isStandardOffset(dateTime.getMillis())) {
        statusBits.add(ClockStatusBit.DAYLIGHT_SAVING_ACTIVE);
    }/* www .  j  av  a 2  s .c  o  m*/
    return new ClockStatus(statusBits);
}

From source file:com.alliander.osgp.dto.valueobjects.smartmetering.CosemDateTimeDto.java

License:Open Source License

private static ClockStatusDto determineClockStatus(final DateTime dateTime) {
    final Set<ClockStatusBitDto> statusBits = EnumSet.noneOf(ClockStatusBitDto.class);
    if (!dateTime.getZone().isStandardOffset(dateTime.getMillis())) {
        statusBits.add(ClockStatusBitDto.DAYLIGHT_SAVING_ACTIVE);
    }/*from  w  w  w.j  a  va2s.co  m*/
    return new ClockStatusDto(statusBits);
}

From source file:com.almende.pi5.common.LogLine.java

License:Apache License

/**
 * From profiles.//from   w ww.j  a  va  2 s  . c o m
 *
 * @param id
 *            the id
 * @param current
 *            the current
 * @param expected
 *            the expected
 * @param now
 *            the now
 * @param currentTimeslot
 *            the current timeslot
 * @param contractMode
 *            the contract mode
 * @return the log line
 */
public static LogLine fromProfiles(final String id, final CategoryProfile current,
        final CategoryProfile expected, final DateTime now, final DateTime currentTimeslot,
        final boolean contractMode) {
    final LogLine result = new LogLine();
    result.setId(id);
    result.setNow(now.getMillis());
    result.setTimeslot(currentTimeslot.getMillis());
    result.setCurrent(current.getDemand().getValueAt(now));
    result.setDemand(current.getDemand().getIntegral(currentTimeslot.minusMinutes(15), currentTimeslot));
    result.setExpected(expected.getDemand().getIntegral(currentTimeslot.minusMinutes(15), currentTimeslot));
    result.setMax(expected.getExpectedFlexibilityMaxInWatts().getIntegral(currentTimeslot.minusMinutes(15),
            currentTimeslot));
    result.setMin(expected.getExpectedFlexibilityMinInWatts().getIntegral(currentTimeslot.minusMinutes(15),
            currentTimeslot));
    result.setNextDemand(current.getDemand().getIntegral(currentTimeslot, currentTimeslot.plusMinutes(15)));
    result.setNextMax(expected.getExpectedFlexibilityMaxInWatts().getIntegral(currentTimeslot,
            currentTimeslot.plusMinutes(15)));
    result.setNextMin(expected.getExpectedFlexibilityMinInWatts().getIntegral(currentTimeslot,
            currentTimeslot.plusMinutes(15)));
    if (contractMode) {
        result.setRequest(expected.getDemand().getIntegral(currentTimeslot.minusMinutes(15), currentTimeslot));
        result.setNextRequest(
                expected.getDemand().getIntegral(currentTimeslot, currentTimeslot.plusMinutes(15)));
    }
    return result;
}

From source file:com.amazonaws.util.JodaTime.java

License:Open Source License

private static boolean checkAlternateIso8601DateFormat() throws ParseException {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
    String expected = sdf.format(date);
    String actual = DateUtils.alternateIso8601DateFormat.print(date.getTime());
    if (expected.equals(actual)) {
        Date expectedDate = sdf.parse(expected);
        DateTime actualDateTime = DateUtils.alternateIso8601DateFormat.parseDateTime(actual);
        return expectedDate.getTime() == actualDateTime.getMillis();
    }//from  ww w .  j  a v a2s  .c  o m
    return false;
}

From source file:com.amlcurran.messages.core.data.Time.java

License:Apache License

public static Time fromDateTime(DateTime dateTime) {
    return new Time(dateTime.getMillis());
}

From source file:com.anasoft.os.daofusion.bitemporal.PersistentInterval.java

License:Apache License

private Timestamp asTimeStamp(DateTime time) {
    return new Timestamp(time.getMillis());
}