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.ehdev.chronos.lib.types.holders.PayPeriodHolder.java

License:Open Source License

/**
 * Will do the calculations for the start and end of the process
 *///w w w  .j a va  2 s. c  o  m
public void generate() {
    //Get the start and end of pay period
    DateTime startOfPP = gJob.getStartOfPayPeriod();
    gDuration = gJob.getDuration();
    DateTime endOfPP = DateTime.now(); //Today

    long duration = endOfPP.getMillis() - startOfPP.getMillis();

    DateTimeZone startZone = startOfPP.getZone();
    DateTimeZone endZone = endOfPP.getZone();

    long offset = endZone.getOffset(endOfPP) - startZone.getOffset(startOfPP);

    int weeks = (int) ((duration + offset) / 1000 / 60 / 60 / 24 / 7);

    /*
    System.out.println("end of pp: " + endOfPP);
    System.out.println("start of pp: " + startOfPP);
    System.out.println("dur: " + duration);
    System.out.println("weeks diff: " + weeks);
    */

    switch (gDuration) {
    case ONE_WEEK:
        //weeks = weeks;
        startOfPP = startOfPP.plusWeeks(weeks);
        endOfPP = startOfPP.plusWeeks(1);
        break;
    case TWO_WEEKS:
        weeks = weeks / 2;
        startOfPP = startOfPP.plusWeeks(weeks * 2);
        endOfPP = startOfPP.plusWeeks(2);
        break;
    case THREE_WEEKS:
        weeks = weeks / 3;
        startOfPP = startOfPP.plusWeeks(weeks * 3);
        endOfPP = startOfPP.plusWeeks(3);
        break;
    case FOUR_WEEKS:
        weeks = weeks / 4;
        startOfPP = startOfPP.plusWeeks(weeks * 4);
        endOfPP = startOfPP.plusWeeks(4);
        break;
    case FULL_MONTH:
        //in this case, endOfPP is equal to now
        startOfPP = DateMidnight.now().toDateTime().withDayOfMonth(1);
        endOfPP = startOfPP.plusMonths(1);

        break;
    case FIRST_FIFTEENTH:
        DateTime now = DateTime.now();
        if (now.getDayOfMonth() >= 15) {
            startOfPP = now.withDayOfMonth(15);
            endOfPP = startOfPP.plusDays(20).withDayOfMonth(1);
        } else {
            startOfPP = now.withDayOfMonth(1);
            endOfPP = now.withDayOfMonth(15);
        }
        break;
    default:
        break;
    }

    if (startOfPP.isAfter(DateTime.now())) {
        startOfPP = startOfPP.minusWeeks(getDays() / 7);
        endOfPP = endOfPP.minusWeeks(getDays() / 7);
    }

    gStartOfPP = startOfPP;
    gEndOfPP = endOfPP;
}

From source file:com.ehdev.chronos.lib.types.holders.PunchTable.java

License:Open Source License

public PunchTable(DateTime start, DateTime end, Job inJob) {
    DateTimeZone startZone = start.getZone();
    DateTimeZone endZone = end.getZone();
    long offset = endZone.getOffset(end) - startZone.getOffset(start);

    int days = (int) ((end.getMillis() - start.getMillis() + offset) / 1000 / 60 / 60 / 24);

    startOfTable = start;//from   w  w w .jav a2 s. c om

    try {
        if (enableLog)
            Log.d(TAG, "Punch Table Size: " + days);
    } catch (Exception e) {
        try {
            if (enableLog)
                Log.d(TAG, "Punch Table Size: " + days);
            if (enableLog)
                Log.d(TAG, e.getMessage());
        } catch (Exception e2) {
            System.out.println("Punch Table Size: " + days);
            System.out.println(e.getMessage());
        }
    }

    if (enableLog)
        Log.d(TAG, "Start of table: " + start);

    createTable(inJob, days, start);
}

From source file:com.ehdev.chronos.lib.types.Note.java

License:Open Source License

/**
 *
 * @param date      Date/*from   w  ww .  j  av  a 2  s.  com*/
 * @param jobNumber Job Number
 * @param note   Note
 */
public Note(DateTime date, Job jobNumber, String note) {
    gDateTime = date.getMillis();
    noteString = note;
    job = jobNumber;
}

From source file:com.ehdev.chronos.lib.types.Note.java

License:Open Source License

public void setTime(DateTime date) {
    gDateTime = date.getMillis();
}

From source file:com.ehdev.chronos.lib.types.Punch.java

License:Open Source License

public Punch(Job iJob, Task iPunchTask, DateTime iTime) {
    job = iJob;
    punchTask = iPunchTask;
    time = iTime.getMillis();
    timeZone = iTime.getZone();
}

From source file:com.ehdev.chronos.lib.types.Punch.java

License:Open Source License

/**
 * Sets the time of the punch/*w ww. jav a 2s  . c om*/
 *
 * @param inputTime Set time for the punch
 */
public void setTime(DateTime inputTime) {
    time = inputTime.getMillis();
    timeZone = inputTime.getZone();
}

From source file:com.enonic.cms.business.portal.livetrace.Duration.java

License:Open Source License

void setStopTime(DateTime stopTime) {
    Preconditions.checkNotNull(stopTime);
    this.stopTime = stopTime;
    this.executionTimeInMilliseconds = stopTime.getMillis() - startTime.getMillis();
    this.dateTimeDuration = new Period(startTime, stopTime);
    this.executionTimeAsHRFormat = hoursMinutesMillis.print(dateTimeDuration);
}

From source file:com.enonic.cms.core.portal.datasource.handler.util.GetCalendarHandler.java

License:Open Source License

@Override
protected Document handle(final DataSourceRequest req, final GetCalendarParams params) throws Exception {
    final DateTime now = this.timeService.getNowAsDateTime();

    if (params.year == null) {
        params.year = now.getYear();// w w  w  . java 2s .co m
    }

    if (params.month == null) {
        params.month = now.getMonthOfYear();
    }

    final Locale locale = new Locale(params.language, params.country);
    return getCalendar(now.getMillis(), params.relative, params.year, params.month, params.count,
            params.includeWeeks, params.includeDays, locale);
}

From source file:com.enonic.cms.core.portal.livetrace.Duration.java

License:Open Source License

void setStopTime(DateTime stopTime) {
    Preconditions.checkNotNull(startTime);
    Preconditions.checkNotNull(stopTime);
    this.stopTime = stopTime;
    this.setDurationInMilliseconds(stopTime.getMillis() - startTime.getMillis());
}

From source file:com.enonic.cms.domain.content.index.translator.ContentQueryTranslator.java

License:Open Source License

protected void applyContentPublishedAtFilter(SelectBuilder hqlQuery, DateTime dateTime) {
    if (dateTime != null) {
        DateTime dateTimeRoundedDownToNearestMinute = dateTime.minuteOfHour().roundFloorCopy();

        if ((this.dialect != null) && this.dialect.isInlineTimestampForSpeed()) {
            hqlQuery.addFilter("AND", "x.contentPublishFrom <= "
                    + this.dialect.formatTimestamp(dateTimeRoundedDownToNearestMinute.getMillis()));
            hqlQuery.addFilter("AND", "(x.contentPublishTo IS null OR x.contentPublishTo > "
                    + this.dialect.formatTimestamp(dateTimeRoundedDownToNearestMinute.getMillis()) + ")");
        } else {/*from w  w w.  j a va 2  s  . c om*/
            hqlQuery.addFilter("AND", "x.contentPublishFrom <= :publishFromDate");
            hqlQuery.addFilter("AND", "(x.contentPublishTo IS null OR x.contentPublishTo > :publishToDate)");
            parameters.put("publishFromDate", dateTimeRoundedDownToNearestMinute.toDate());
            parameters.put("publishToDate", dateTimeRoundedDownToNearestMinute.toDate());
        }
    }
}