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.datastax.driver.extras.codecs.joda.DateTimeCodec.java

License:Apache License

@Override
protected ByteBuffer serializeField(DateTime source, int index, ProtocolVersion protocolVersion) {
    if (index == 0) {
        long millis = source.getMillis();
        return bigint().serializeNoBoxing(millis, protocolVersion);
    }/*  w  w  w .j av a 2s  .  c om*/
    if (index == 1) {
        return varchar().serialize(source.getZone().getID(), protocolVersion);
    }
    throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index);
}

From source file:com.dhr.security.LicenseValidation.java

License:Open Source License

Boolean isInvalidLicense(String encryptedLicenseKey, DateTime today) {
    if (UtilValidator.isEmpty(encryptedLicenseKey))
        return invalidLicense;
    String currentMachineMacAddress;
    try {//ww w . j a  v  a2  s .  com
        currentMachineMacAddress = getMachineMacAddress();
    } catch (Exception e) {
        return invalidLicense;
    }
    String decryptedLicenseKey = decryptLicenseKey(encryptedLicenseKey);

    final String[] key = decryptedLicenseKey.split("#");
    if (key.length != 2) {
        return invalidLicense;
    }
    final String licenseKey = key[0];
    final DateTime expiryDate = DateTime.parse(key[1]);
    if (currentMachineMacAddress.equalsIgnoreCase(licenseKey) && today.isBefore(expiryDate.getMillis()))
        return validLicense;
    return invalidLicense;
}

From source file:com.ebay.pulsar.analytics.metricstore.druid.query.validator.DruidGranularityValidator.java

License:MIT License

@Override
public void validate(GranularityAndTimeRange req) {
    BaseGranularity granularity = req.getGranularity();
    if (granularity instanceof InvalidGranularity) {
        throw new InvalidQueryParameterException(ExceptionErrorCode.INVALID_GRANULARITY.getErrorMessage()
                + ((InvalidGranularity) granularity).getKey());
    } else if (granularity instanceof PeriodGranularity) {
        DateRange intervals = req.getIntervals();
        if ("PT1M".equals(((PeriodGranularity) granularity).getPeriod())) {
            DateTime start = intervals.getStart();
            DateTime end = intervals.getEnd();
            long intervalTime = end.getMillis() - start.getMillis();
            if (intervalTime > ONEDAY_MILLIS) {
                throw new InvalidQueryParameterException(
                        ExceptionErrorCode.INVALID_GRANULARITY_INTERVAL.getErrorMessage());
            }/*from w w  w. jav  a 2  s  .com*/
        }
    }
}

From source file:com.ebay.pulsar.analytics.query.request.RealtimeRequest.java

License:MIT License

@Override
public DateRange getQueryDateRange() {
    DateTime start = null;//w w w.j  a  v a  2s . c  o  m
    DateTime end = null;
    DateTime now = new DateTime(PulsarDateTimeFormatter.MST_TIMEZONE);

    // normalize to 0, 10, 20, 30, 40, 50 of each minute
    end = new DateTime((now.getMillis() / 10000) * 10000);
    Integer duration = getDuration();
    if (duration == null) {
        duration = 5 * 60; // default to last 5 minutes
    }
    start = new DateTime(end.getMillis() - duration * 1000);

    DateRange dateRange = new DateRange(start, end);
    return dateRange;
}

From source file:com.edlogics.ElrcApplication.java

License:Open Source License

/**
 * If the application is currently in maintenance as specified by the maintenance date time being set.
 *
 * @return Is the current date time > maintenance date time?
 */// w ww .  j a  v  a  2  s  .c  o m
@Bean
@Scope(WebApplicationContext.SCOPE_REQUEST)
public boolean inMaintenance() {
    DateTime currentDateTime = DateTime.now(DateTimeZone.forID(elrcTimezone));
    return (currentDateTime.getMillis() - maintenanceDateTime().getMillis()) > 0;
}

From source file:com.egt.core.util.STP.java

License:Open Source License

public static Object getObjeto(String string, EnumTipoDatoPar tipo) {
    String cadena = StringUtils.trimToNull(string);
    if (cadena == null) {
        return null;
    }/*from  w w w. java2s .  c  o  m*/
    Object objeto = null;
    switch (tipo) {
    case ALFANUMERICO:
        objeto = new String(string);
        break;
    case NUMERICO:
        try {
            objeto = new BigDecimal(cadena);
        } catch (NumberFormatException e) {
            objeto = null;
        }
        break;
    case FECHA_HORA:
        int year = 0;
        int monthOfYear = 0;
        int dayOfMonth = 0;
        int hourOfDay = 0;
        int minuteOfHour = 0;
        int secondOfMinute = 0;
        try {
            String xm = "";
            String xs = "";
            int len = cadena.length();
            switch (len) {
            case 22:
                xm = cadena.substring(20);
            case 19:
                if (xm.equals("")) {
                    xs = cadena.substring(17, 19);
                }
                if (xs.equalsIgnoreCase("AM") || xs.equalsIgnoreCase("PM")) {
                    xm = xs;
                } else {
                    secondOfMinute = Integer.parseInt(cadena.substring(17, 19));
                }
            case 16:
                minuteOfHour = Integer.parseInt(cadena.substring(14, 16));
                hourOfDay = Integer.parseInt(cadena.substring(11, 13));
                if (xm.equalsIgnoreCase("AM") && hourOfDay == 12) {
                    hourOfDay = 0;
                }
                if (xm.equalsIgnoreCase("PM") && hourOfDay <= 11) {
                    hourOfDay += 12;
                }
            case 10:
                year = Integer.parseInt(cadena.substring(6, 10));
                monthOfYear = Integer.parseInt(cadena.substring(3, 5));
                dayOfMonth = Integer.parseInt(cadena.substring(0, 2));
                break;
            }
            DateTime dateTime = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour,
                    secondOfMinute, 0);
            objeto = new Timestamp(dateTime.getMillis());
        } catch (RuntimeException e) {
            objeto = null;
        }
        break;
    case ENTERO:
        try {
            objeto = new Integer(new BigDecimal(cadena).intValue());
        } catch (NumberFormatException e) {
            objeto = null;
        }
        break;
    case ENTERO_GRANDE:
        try {
            objeto = new Long(new BigDecimal(cadena).longValue());
        } catch (NumberFormatException e) {
            objeto = null;
        }
        break;
    default:
        objeto = null;
        break;
    }
    return objeto;
}

From source file:com.ehdev.chronos.lib.Chronos.java

License:Open Source License

public static DateTime getDateFromStartOfPayPeriod(DateTime StartOfPP, DateTime date) {

    DateTime newDate;//from   ww w .j a v a2 s. c om
    DateTimeZone startZone = StartOfPP.getZone();
    DateTimeZone endZone = date.getZone();
    long dateTime = date.getMillis() - StartOfPP.getMillis();

    long offset = endZone.getOffset(date) - startZone.getOffset(StartOfPP);
    //System.out.println("offset: " + offset);
    dateTime += offset;

    //System.out.println("millis diff: " + (dateTime) );
    int days = (int) (dateTime / 1000 / 60 / 60 / 24);
    newDate = StartOfPP.plusDays(days);
    //System.out.println("Days to add: " + days);

    return newDate;
}

From source file:com.ehdev.chronos.lib.Chronos.java

License:Open Source License

public Note getNoteByDay(DateTime date) {

    Note retValue = new Note(date, null, "");
    try {/*from   w  w  w  .jav a  2 s  . c o m*/
        // instantiate the DAO to handle Account with String id
        Dao<Note, String> noteDAO = getNoteDao();
        Dao<Job, String> jobDAO = getJobDao();
        Job thisJob = getAllJobs().get(0);

        DateTime newDate = getDateFromStartOfPayPeriod(thisJob, date);

        QueryBuilder<Note, String> queryBuilder = noteDAO.queryBuilder();
        queryBuilder.where().eq(Note.DATE_FIELD, newDate.getMillis());
        PreparedQuery<Note> preparedQuery = queryBuilder.prepare();

        retValue = noteDAO.queryForFirst(preparedQuery);
        if (retValue != null) {
            jobDAO.update(retValue.getJob());
        } else {
            retValue = new Note(newDate, thisJob, "");
        }

    } catch (SQLException e) {
        if (enableLog)
            Log.e(TAG, e.getMessage());
    } catch (Exception e) {
        if (enableLog)
            Log.e(TAG, e.getMessage());
    }
    return retValue;
}

From source file:com.ehdev.chronos.lib.Chronos.java

License:Open Source License

public List<Punch> getPunchesByJobAndDate(Job jobId, DateTime date) {
    List<Punch> punches = new LinkedList<Punch>();

    // instantiate the DAO to handle Account with String id
    try {//w w  w .  ja  v a 2  s . co m
        Dao<Punch, String> punchDao = getPunchDao();
        Dao<Task, String> taskDAO = getTaskDao();
        Dao<Job, String> jobDAO = getJobDao();

        //Period prd = new Period(jobId.getStartOfPayPeriod(), date);
        //Duration dur = new Duration(jobId.getStartOfPayPeriod(), date);
        DateTime startOfDay = date;
        //if(jobId.getStartOfPayPeriod().isBefore(date))
        //    startOfDay = jobId.getStartOfPayPeriod().plusDays(prd.toStandardDays().get(DurationFieldType.days()));
        //else
        //    startOfDay = jobId.getStartOfPayPeriod().minusDays(prd.toStandardDays().get(DurationFieldType.days()));
        //DateTime startOfDay = jobId.getStartOfPayPeriod().plusDays(displacementInDays);

        DateTime endOfDay = startOfDay.plusDays(1);

        if (enableLog)
            Log.d(TAG, "Start of Day: " + startOfDay.getMillis());
        if (enableLog)
            Log.d(TAG, "End of Day: " + endOfDay.getMillis());

        QueryBuilder<Punch, String> queryBuilder = punchDao.queryBuilder();
        queryBuilder.where().eq(Job.JOB_FIELD_NAME, jobId.getID()).and().between(Punch.TIME_OF_PUNCH,
                startOfDay.getMillis(), endOfDay.getMillis());

        PreparedQuery<Punch> preparedQuery = queryBuilder.prepare();

        punches = punchDao.query(preparedQuery);
        if (enableLog)
            Log.d(TAG, "Punches for this day: " + punches.size());
        for (Punch work : punches) {
            taskDAO.refresh(work.getTask());
            jobDAO.refresh(work.getTask().getJob());
            jobDAO.refresh(work.getJob());
            //if(enableLog) Log.d(TAG, "in loop Pay Rate: " + work.getJob().getPayRate());

        }
        Collections.sort(punches);

    } catch (SQLException e) {
        e.printStackTrace();
        Log.e(TAG, e.getMessage());
    }

    //Log.d(TAG, "Number of punches: " + punches.size());
    return punches;
}

From source file:com.ehdev.chronos.lib.Chronos.java

License:Open Source License

public PunchTable getAllPunchesForPayPeriodByJob(Job jobId, DateTime startDate, DateTime endDate) {

    PunchTable punches = null;//  w w  w  . ja  v  a  2s .c om
    try {

        // instantiate the DAO to handle Account with String id
        Dao<Punch, String> punchDao = getPunchDao();
        Dao<Task, String> taskDAO = getTaskDao();
        Dao<Job, String> jobDAO = getJobDao();

        punches = new PunchTable(startDate, endDate, jobId);

        if (enableLog)
            Log.d(TAG, "Chronos Start of Pay Period: " + startDate.getMillis());
        if (enableLog)
            Log.d(TAG, "Chronos End of Pay Period: " + endDate.getMillis());

        QueryBuilder<Punch, String> queryBuilder = punchDao.queryBuilder();
        queryBuilder.where().eq(Job.JOB_FIELD_NAME, jobId.getID()).and().between(Punch.TIME_OF_PUNCH,
                startDate.getMillis(), endDate.getMillis());

        PreparedQuery<Punch> preparedQuery = queryBuilder.prepare();

        List<Punch> retValue = punchDao.query(preparedQuery);
        if (enableLog)
            Log.d(TAG, "Punches for this pay period: " + retValue.size());
        for (Punch work : retValue) {
            taskDAO.refresh(work.getTask());
            jobDAO.refresh(work.getTask().getJob());
            jobDAO.refresh(work.getJob());
            punches.insert(work);
        }

    } catch (SQLException e) {
        if (enableLog)
            Log.e(TAG, e.getMessage());
    }
    return punches;
}