Example usage for org.joda.time LocalDateTime toDateTime

List of usage examples for org.joda.time LocalDateTime toDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime toDateTime.

Prototype

public DateTime toDateTime(DateTimeZone zone) 

Source Link

Document

Converts this object to a DateTime using the specified zone.

Usage

From source file:com.tasomaniac.muzei.tvshows.util.TimeTools.java

License:Apache License

/**
 * Calculates the current release date time. Adjusts for time zone effects on release time, e.g.
 * delays between time zones (e.g. in the United States) and DST. Adjusts for user-defined
 * offset./*from  www  . ja  v  a  2 s. co  m*/
 *
 * @param time See {@link #getShowReleaseTime(int)}.
 * @return The date is today or on the next day matching the given week day.
 */
public static Date getShowReleaseDateTime(@NonNull Context context, @NonNull LocalTime time, int weekDay,
        @Nullable String timeZone, @Nullable String country) {
    // determine show time zone (falls back to America/New_York)
    DateTimeZone showTimeZone = getDateTimeZone(timeZone);

    // create current date in show time zone, set local show release time
    LocalDateTime localDateTime = new LocalDate(showTimeZone).toLocalDateTime(time);

    // adjust day of week so datetime is today or within the next week
    // for daily shows (weekDay == 0) just use the current day
    if (weekDay >= 1 && weekDay <= 7) {
        // joda tries to preserve week
        // so if we want a week day earlier in the week, advance by 7 days first
        if (weekDay < localDateTime.getDayOfWeek()) {
            localDateTime = localDateTime.plusWeeks(1);
        }
        localDateTime = localDateTime.withDayOfWeek(weekDay);
    }

    localDateTime = handleHourPastMidnight(country, localDateTime);
    localDateTime = handleDstGap(showTimeZone, localDateTime);

    DateTime dateTime = localDateTime.toDateTime(showTimeZone);

    // handle time zone effects on release time for US shows (only if device is set to US zone)
    String localTimeZone = TimeZone.getDefault().getID();
    if (localTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) {
        dateTime = applyUnitedStatesCorrections(country, localTimeZone, dateTime);
    }

    return dateTime.toDate();
}

From source file:com.temenos.interaction.media.odata.xml.atom.AtomEntityEntryFormatWriter.java

License:Open Source License

protected void writeEntry(StreamWriter writer, String entityName, Entity entity, Collection<Link> entityLinks,
        Map<Transition, RESTResource> embeddedResources, String baseUri, String absoluteId, String updated) {
    assert (entityName != null);

    // entity name could be different between entity resource and underlying entity 
    // e.g., for Errors entity, entity resource would have the request entity name 
    String entityMetadataName = entity != null ? entity.getName() : entityName;

    EntityMetadata entityMetadata = metadata.getEntityMetadata(entityMetadataName);
    String modelName = metadata.getModelName();
    writer.writeId(absoluteId);//from w ww . ja  va 2 s .c  o  m
    OAtomEntity oae = getAtomInfo(entity);

    writer.writeTitle(oae.getAtomEntityTitle());
    String summary = oae.getAtomEntitySummary();
    if (!summary.isEmpty()) {
        writer.writeSummary(summary);
    }

    LocalDateTime updatedTime = oae.getAtomEntityUpdated();
    if (updatedTime != null) {
        updated = InternalUtil.toString(updatedTime.toDateTime(DateTimeZone.UTC));
    }

    writer.writeUpdated(updated);
    writer.writeAuthor(oae.getAtomEntityAuthor());

    if (entityLinks != null) {
        for (Link link : entityLinks) {
            String type = (link.getTransition().getTarget() instanceof CollectionResourceState)
                    ? atom_feed_content_type
                    : atom_entry_content_type;
            String href = link.getRelativeHref(baseUri);
            String rel = link.getRel();
            writer.startLink(href, rel);

            if ("self".equals(link.getRel())) {
                ResourceState target = link.getTransition().getTarget();
                writer.writeAttribute("profile", target.getRel());
            }

            if (!"self".equals(link.getRel()) && !"edit".equals(link.getRel())) {
                writer.writeAttribute("type", type);
            }
            writer.writeAttribute("title", link.getTitle());
            if (embeddedResources != null && embeddedResources.get(link.getTransition()) != null) {
                String embeddedAbsoluteId = link.getHref();
                writeLinkInline(writer, metadata, link, embeddedResources.get(link.getTransition()),
                        link.getHref(), baseUri, embeddedAbsoluteId, updated);
            }
            String linkId = link.getLinkId();
            if (linkId != null && linkId.length() > 0) {
                writer.writeAttribute("id", linkId);
            }
            writer.endLink();
        }
    }

    writer.writeCategory(modelName + Metadata.MODEL_SUFFIX + "." + entityName, scheme);
    writer.flush();

    writer.startContent(MediaType.APPLICATION_XML);

    writer.startElement(new QName(m, "properties", "m"));
    if (entity != null) {
        writeProperties(writer, entityMetadata, entity.getProperties(), modelName);
    }
    writer.endElement();

    writer.endContent();
}

From source file:com.temenos.interaction.media.odata.xml.atom.AtomEntryFormatWriter.java

License:Open Source License

public String writeEntry(XMLWriter2 writer, OEntity oe, List<OProperty<?>> entityProperties,
        List<OLink> entityLinks, String baseUri, String updated, EdmEntitySet ees, boolean isResponse,
        Collection<Link> linkId) {

    String relid = null;/*ww w  .j a v a  2  s.  c  o  m*/
    String absid = null;
    if (isResponse) {
        relid = InternalUtil.getEntityRelId(oe);
        //Odata 4j creates IDs with an L suffix on Edm.Int types, quotes on Edm.String types - remove to conform to interaction links
        List<String> keys = oe.getEntityType().getKeys();
        if (keys.size() > 0) {
            EdmProperty keyProperty = oe.getEntityType().findDeclaredProperty(keys.get(0));
            if (keyProperty.getType().getFullyQualifiedTypeName().startsWith("Edm.Int")
                    && relid.endsWith("L)")) {
                relid = relid.substring(0, relid.length() - 2) + ")";
            }
        }
        absid = (!baseUri.endsWith("/") ? baseUri + "/" : baseUri) + relid;
        writeElement(writer, "id", absid);
    }

    OAtomEntity oae = getAtomInfo(oe);

    writeElement(writer, "title", oae.getAtomEntityTitle(), "type", "text");
    String summary = oae.getAtomEntitySummary();
    if (summary != null) {
        writeElement(writer, "summary", summary, "type", "text");
    }

    LocalDateTime updatedTime = oae.getAtomEntityUpdated();
    if (updatedTime != null) {
        updated = InternalUtil.toString(updatedTime.toDateTime(DateTimeZone.UTC));
    }
    writeElement(writer, "updated", updated);

    writer.startElement("author");
    writeElement(writer, "name", oae.getAtomEntityAuthor());
    writer.endElement("author");

    if (entityLinks != null) {
        if (isResponse) {
            // the producer has populated the link collection, we just write what he gave us.
            for (OLink link : entityLinks) {
                String type = (link.isCollection()) ? atom_feed_content_type : atom_entry_content_type;
                String href = link.getHref();
                if (link.isInline()) {
                    writer.startElement("link");
                    writer.writeAttribute("rel", link.getRelation());
                    if (!"self".equals(link.getRelation()) && !"edit".equals(link.getRelation())) {
                        writer.writeAttribute("type", type);
                    }
                    writer.writeAttribute("title", link.getTitle());
                    writer.writeAttribute("href", href);
                    // write the inlined entities inside the link element
                    writeLinkInline(writer, link, href, baseUri, updated, isResponse);
                    writer.endElement("link");
                } else {
                    writeLink(writer, link, type, href, linkId);
                }
            }
        } else {
            // for requests we include only the provided links
            // Note: It seems that OLinks for responses are only built using the
            // title and OLinks for requests have the additional info in them
            // alread.  I'm leaving that inconsistency in place for now but this
            // else and its preceding if could probably be unified.
            for (OLink olink : entityLinks) {
                String type = olink.isCollection() ? atom_feed_content_type : atom_entry_content_type;

                writer.startElement("link");
                writer.writeAttribute("rel", olink.getRelation());
                writer.writeAttribute("type", type);
                writer.writeAttribute("title", olink.getTitle());
                writer.writeAttribute("href", olink.getHref());
                if (olink.isInline()) {
                    // write the inlined entities inside the link element
                    writeLinkInline(writer, olink, olink.getHref(), baseUri, updated, isResponse);
                }
                writer.endElement("link");
            }
        }
    } // else entityLinks null

    writeElement(writer, "category", null,
            // oe is null for creates
            "term", oe == null ? ees.getType().getFullyQualifiedTypeName()
                    : oe.getEntityType().getFullyQualifiedTypeName(),
            "scheme", scheme);

    boolean hasStream = false;
    if (oe != null) {
        OAtomStreamEntity stream = oe.findExtension(OAtomStreamEntity.class);
        if (stream != null) {
            hasStream = true;
            writer.startElement("content");
            writer.writeAttribute("type", stream.getAtomEntityType());
            writer.writeAttribute("src", baseUri + stream.getAtomEntitySource());
            writer.endElement("content");
        }
    }

    if (!hasStream) {
        writer.startElement("content");
        writer.writeAttribute("type", MediaType.APPLICATION_XML);
    }

    writer.startElement(new QName2(m, "properties", "m"));
    writeProperties(writer, entityProperties);
    writer.endElement("properties");

    if (!hasStream) {
        writer.endElement("content");
    }
    return absid;
}

From source file:de.appsolve.padelcampus.controller.bookings.BookingsController.java

private void validateBookingCancellation(Booking booking) throws Exception {
    if (booking == null) {
        throw new Exception(msg.get("InvalidBooking"));
    }/*from w w w .  j a  va2  s  . c  om*/
    if (booking.getCancelled()) {
        throw new Exception(msg.get("BookingAlreadyCancelled"));
    }
    if (booking.getOffer() == null) {
        throw new Exception(msg.get("BookingCannotBeCancelled"));
    }
    LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE);
    LocalDateTime bookingTime = new LocalDateTime().withDate(booking.getBookingDate().getYear(),
            booking.getBookingDate().getMonthOfYear(), booking.getBookingDate().getDayOfMonth()).withTime(
                    booking.getBookingTime().getHourOfDay(), booking.getBookingTime().getMinuteOfHour(), 0, 0);
    if (now.isAfter(bookingTime)) {
        throw new Exception(msg.get("BookingCancellationDeadlineMissed"));
    }

    Duration duration = new Duration(now.toDateTime(DateTimeZone.UTC),
            bookingTime.toDateTime(DateTimeZone.UTC));
    if (duration.getStandardHours() < CANCELLATION_POLICY_DEADLINE) {
        throw new Exception(msg.get("BookingCancellationDeadlineMissed"));
    }
}

From source file:energy.usef.agr.workflow.nonudi.service.PowerMatcher.java

License:Apache License

/**
 * Returns a interval ({@link String}) based on the date, ptuIndex, ptuDuration and number of ptus. For example:
 * "2015-05-01T13:00:00Z/2015-05-01T14:00:00Z". This time format is compatible with the PowerMatcher.
 *
 * @param date//from  www  .  j  a  v  a2  s  .  co  m
 * @param ptuIndex
 * @param ptuDuration
 * @param numberOfPtus
 * @return
 */
public static String getInterval(LocalDate date, int ptuIndex, int ptuDuration, int numberOfPtus) {
    LocalDateTime start = date.toDateTimeAtStartOfDay().toLocalDateTime()
            .plusMinutes((ptuIndex - 1) * ptuDuration);
    LocalDateTime end = start.plusMinutes(numberOfPtus * ptuDuration).minusSeconds(1);

    DateTime startDateTime = start.toDateTime().toDateTime(DateTimeZone.UTC);
    DateTime endDateTime = end.toDateTime().toDateTime(DateTimeZone.UTC);
    return startDateTime.toString(POWER_MATCHER_TIME_FORMAT) + "/"
            + endDateTime.toString(POWER_MATCHER_TIME_FORMAT);
}

From source file:io.personium.core.odata.PersoniumAtomEntryFormatWriter.java

License:Apache License

/**
 * {@inheritDoc}/*from   w w w . j a  va2s.c  o  m*/
 */
@Override
protected String writeEntry(XMLWriter2 writer, OEntity oe, List<OProperty<?>> entityProperties,
        List<OLink> entityLinks, String baseUri, String updated, EdmEntitySet ees, boolean isResponse) {

    String relid = null;
    String absid = null;
    if (isResponse) {
        relid = getEntityRelId(oe);
        absid = baseUri + relid;
        writeElement(writer, "id", absid);
    }

    OAtomEntity oae = getAtomInfo(oe);

    writeElement(writer, "title", oae.getAtomEntityTitle(), "type", "text");
    String summary = oae.getAtomEntitySummary();
    if (summary != null) {
        writeElement(writer, "summary", summary, "type", "text");
    }

    LocalDateTime updatedTime = oae.getAtomEntityUpdated();
    if (updatedTime != null) {
        updated = InternalUtil.toString(updatedTime.toDateTime(DateTimeZone.UTC));
    }
    writeElement(writer, "updated", updated);

    writer.startElement("author");
    writeElement(writer, "name", oae.getAtomEntityAuthor());
    writer.endElement("author");

    if (isResponse) {
        writeElement(writer, "link", null, "rel", "edit", "title", ees.getType().getName(), "href", relid);
    }

    if (entityLinks != null) {
        if (isResponse) {
            // the producer has populated the link collection, we just what he gave us.
            for (OLink link : entityLinks) {
                String rel = related + link.getTitle();
                String type = (link.isCollection()) // NOPMD - Copy of logic from inheritance source
                        ? atom_feed_content_type // CHECKSTYLE IGNORE : Copy of logic from inheritance source
                        : atom_entry_content_type;
                String href = relid + "/" + link.getTitle();
                if (link.isInline()) {
                    writer.startElement("link");
                    writer.writeAttribute("rel", rel);
                    writer.writeAttribute("type", type);
                    writer.writeAttribute("title", link.getTitle());
                    writer.writeAttribute("href", href);
                    // write the inlined entities inside the link element
                    writeLinkInline(writer, link, href, baseUri, updated, isResponse);
                    writer.endElement("link");
                } else {
                    // deferred link.
                    writeElement(writer, "link", null, "rel", rel, "type", type, "title", link.getTitle(),
                            "href", href);
                }
            }
        } else {
            // for requests we include only the provided links
            // Note: It seems that OLinks for responses are only built using the
            // title and OLinks for requests have the additional info in them
            // alread.  I'm leaving that inconsistency in place for now but this
            // else and its preceding if could probably be unified.
            for (OLink olink : entityLinks) {
                String type = olink.isCollection() ? atom_feed_content_type // CHECKSTYLE IGNORE : Copy of logic from inheritance source
                        : atom_entry_content_type;

                writer.startElement("link");
                writer.writeAttribute("rel", olink.getRelation());
                writer.writeAttribute("type", type);
                writer.writeAttribute("title", olink.getTitle());
                writer.writeAttribute("href", olink.getHref());
                if (olink.isInline()) {
                    // write the inlined entities inside the link element
                    writeLinkInline(writer, olink, olink.getHref(), baseUri, updated, isResponse);
                }
                writer.endElement("link");
            }
        }
    } // else entityLinks null

    writeElement(writer, "category", null,
            // oe is null for creates
            "term",
            oe == null ? ees.getType().getFullyQualifiedTypeName()
                    : oe.getEntityType().getFullyQualifiedTypeName(), // CHECKSTYLE IGNORE : Copy of logic from inheritance source
            "scheme", scheme);

    boolean hasStream = false;
    if (oe != null) {
        OAtomStreamEntity stream = oe.findExtension(OAtomStreamEntity.class);
        if (stream != null) {
            hasStream = true;
            writer.startElement("content");
            writer.writeAttribute("type", stream.getAtomEntityType());
            writer.writeAttribute("src", baseUri + stream.getAtomEntitySource());
            writer.endElement("content");
        }
    }

    if (!hasStream) {
        writer.startElement("content");
        writer.writeAttribute("type", MediaType.APPLICATION_XML);
    }

    writer.startElement(new QName2(m, "properties", "m"));
    writeProperties(writer, entityProperties);
    writer.endElement("properties");

    if (!hasStream) {
        writer.endElement("content");
    }
    return absid;

}

From source file:io.personium.core.odata.PersoniumAtomFeedFormatWriter.java

License:Apache License

/**
 * {@inheritDoc}/*from w w  w .  j  av  a 2  s.co m*/
 */
@Override
protected String writeEntry(XMLWriter2 writer, OEntity oe, List<OProperty<?>> entityProperties,
        List<OLink> entityLinks, String baseUri, String updated, EdmEntitySet ees, boolean isResponse) {

    String relid = null;
    String absid = null;
    if (isResponse) {
        relid = getEntityRelId(oe);
        absid = baseUri + relid;
        writeElement(writer, "id", absid);
    }

    OAtomEntity oae = getAtomInfo(oe);

    writeElement(writer, "title", oae.getAtomEntityTitle(), "type", "text");
    String summary = oae.getAtomEntitySummary();
    if (summary != null) {
        writeElement(writer, "summary", summary, "type", "text");
    }

    LocalDateTime updatedTime = oae.getAtomEntityUpdated();
    if (updatedTime != null) {
        updated = InternalUtil.toString(updatedTime.toDateTime(DateTimeZone.UTC));
    }
    writeElement(writer, "updated", updated);

    writer.startElement("author");
    writeElement(writer, "name", oae.getAtomEntityAuthor());
    writer.endElement("author");

    if (isResponse) {
        writeElement(writer, "link", null, "rel", "edit", "title", ees.getType().getName(), "href", relid);
    }

    if (entityLinks != null) {
        if (isResponse) {
            // the producer has populated the link collection, we just what he gave us.
            for (OLink link : entityLinks) {
                String rel = related + link.getTitle();
                String type = (link.isCollection()) // NOPMD - Copy of logic from inheritance source
                        ? atom_feed_content_type // CHECKSTYLE IGNORE - Copy of logic from inheritance source
                        : atom_entry_content_type;
                String href = relid + "/" + link.getTitle();
                if (link.isInline()) {
                    writer.startElement("link");
                    writer.writeAttribute("rel", rel);
                    writer.writeAttribute("type", type);
                    writer.writeAttribute("title", link.getTitle());
                    writer.writeAttribute("href", href);
                    // write the inlined entities inside the link element
                    writeLinkInline(writer, link, href, baseUri, updated, isResponse);
                    writer.endElement("link");
                } else {
                    // deferred link.
                    writeElement(writer, "link", null, "rel", rel, "type", type, "title", link.getTitle(),
                            "href", href);
                }
            }
        } else {
            // for requests we include only the provided links
            // Note: It seems that OLinks for responses are only built using the
            // title and OLinks for requests have the additional info in them
            // alread.  I'm leaving that inconsistency in place for now but this
            // else and its preceding if could probably be unified.
            for (OLink olink : entityLinks) {
                String type = olink.isCollection() ? atom_feed_content_type // CHECKSTYLE IGNORE : Copy of logic from inheritance source
                        : atom_entry_content_type;

                writer.startElement("link");
                writer.writeAttribute("rel", olink.getRelation());
                writer.writeAttribute("type", type);
                writer.writeAttribute("title", olink.getTitle());
                writer.writeAttribute("href", olink.getHref());
                if (olink.isInline()) {
                    // write the inlined entities inside the link element
                    writeLinkInline(writer, olink, olink.getHref(), baseUri, updated, isResponse);
                }
                writer.endElement("link");
            }
        }
    } // else entityLinks null

    writeElement(writer, "category", null,
            // oe is null for creates
            "term",
            oe == null ? ees.getType().getFullyQualifiedTypeName()
                    : oe.getEntityType().getFullyQualifiedTypeName(), // CHECKSTYLE IGNORE : Copy of logic from inheritance source
            "scheme", scheme);

    boolean hasStream = false;
    if (oe != null) {
        OAtomStreamEntity stream = oe.findExtension(OAtomStreamEntity.class);
        if (stream != null) {
            hasStream = true;
            writer.startElement("content");
            writer.writeAttribute("type", stream.getAtomEntityType());
            writer.writeAttribute("src", baseUri + stream.getAtomEntitySource());
            writer.endElement("content");
        }
    }

    if (!hasStream) {
        writer.startElement("content");
        writer.writeAttribute("type", MediaType.APPLICATION_XML);
    }

    writer.startElement(new QName2(m, "properties", "m"));
    writeProperties(writer, entityProperties);
    writer.endElement("properties");

    if (!hasStream) {
        writer.endElement("content");
    }
    return absid;

}

From source file:it.webappcommon.lib.DateUtils.java

License:Open Source License

/**
 * //from www .j  ava 2  s .c o  m
 * @param date
 * @param time
 * @return
 */
public static DateTime mergeDateTimeUTC(Date date, Date time) {
    // return new Date(date.getYear(), date.getMonth(), date.getDate(),
    // time.getHours(), time.getMinutes(), time.getSeconds());

    LocalDateTime a1 = new LocalDateTime(mergeDateTime(date, time).getTime());
    // LocalDateTime b1 = new LocalDateTime(mergeDateTime(_toDate,
    // _toTime).getTime());

    // Duration d = new Duration(a, b);
    // Duration d1 = new Duration(a1.toDateTime(DateTimeZone.UTC),
    // b1.toDateTime(DateTimeZone.UTC));

    // Calendar calDate =
    // GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
    // Calendar calTime =
    // GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
    //
    // calDate.setTime(date);
    // calTime.setTime(time);
    // calDate.set(Calendar.HOUR_OF_DAY, calTime.get(Calendar.HOUR_OF_DAY));
    // calDate.set(Calendar.MINUTE, calTime.get(Calendar.MINUTE));
    // calDate.set(Calendar.SECOND, calTime.get(Calendar.SECOND));
    // calDate.set(Calendar.MILLISECOND, calTime.get(Calendar.MILLISECOND));
    //
    //
    // return calDate.getTime();

    return a1.toDateTime(DateTimeZone.UTC);
}

From source file:me.tongfei.progressbar.ProgressThread.java

License:Apache License

void refresh() {
    consoleStream.print('\r');

    LocalDateTime currTime = LocalDateTime.now();
    Duration elapsed = new Duration(progress.startTime.toDateTime(DateTimeZone.UTC),
            currTime.toDateTime(DateTimeZone.UTC));

    String prefix = progress.task + " " + percentage() + " " + style.leftBracket;

    int maxSuffixLength = Math.max(0, consoleWidth - consoleRightMargin - prefix.length() - 10);
    String suffix = style.rightBracket + " " + ratio() + " (" + Util.formatDuration(elapsed) + " / "
            + eta(elapsed) + ") " + progress.extraMessage;
    if (suffix.length() > maxSuffixLength)
        suffix = suffix.substring(0, maxSuffixLength);

    length = consoleWidth - consoleRightMargin - prefix.length() - suffix.length();

    StringBuilder sb = new StringBuilder();
    sb.append(prefix);//from  w  ww  .jav a 2  s.c om

    // case of indefinite progress bars
    if (progress.indefinite) {
        int pos = (int) (progress.current % length);
        sb.append(Util.repeat(style.space, pos));
        sb.append(style.block);
        sb.append(Util.repeat(style.space, length - pos - 1));
    }
    // case of definite progress bars
    else {
        sb.append(Util.repeat(style.block, progressIntegralPart()));
        if (progress.current < progress.max) {
            sb.append(style.fractionSymbols.charAt(progressFractionalPart()));
            sb.append(Util.repeat(style.space, length - progressIntegralPart() - 1));
        }
    }
    sb.append(suffix);
    String line = sb.toString();

    consoleStream.print(line);
}

From source file:nz.al4.airclock.TimeCalculator.java

License:Open Source License

/**
 * Calculate when to set an alarm given a LocalDateTime (no time zone information)
 *
 * To do this, we need to figure out what time zone will be applied when we hit this time...
 * far from trivial!//from   ww w. j a  v  a2s  .c  o  m
 *
 * So we use linear algebra to create simple formulas for the absolute time and tz offet of our
 * alarm.
 *
 * @param localAlarmTime
 * @return
 */
public DateTime timeForAlarm(LocalDateTime localAlarmTime) {
    Log.d("timeForAlarm", "Calculating alarm for time " + localAlarmTime.toString());
    // x axis, Time in ms since 1970
    long To = mOriginTime.getMillis(); // x1
    long Td = mDestTime.getMillis(); // x3
    // y axis, Offset in milliseconds
    long Oo = mOriginTime.getZone().getOffset(mOriginTime); // y1
    long Od = mDestTime.getZone().getOffset(mDestTime); // y3

    System.out.println(String.valueOf(To) + ',' + String.valueOf(Oo));
    System.out.println(String.valueOf(Td) + ',' + String.valueOf(Od));

    // slope = x/y
    float slope = (Td - To) / (Od - Oo);
    Log.v("debug", String.valueOf(slope));
    System.out.println(String.valueOf(slope));

    /*
    now that we have the slope, we can use algebra to rearrange what we know and come up
    with formulas for what we don't.
            
    * (x1, y1) is the point at takeoff, i.e (To, Oo)
    * our unknown point, the alarm point is (x2, y2) => (Ta, Oa) (Time of alarm,
      offset of alarm)
    * the localtime of the alarm we want to calculate, T, equals x2 (absolute time at
      alarm) plus y2 (offset at time of alarm)
    (tz offset at alarm time), i.e T=x2+y2
            
    by rearranging the slope formula, y2 = (x2 - x1)/S + y1
    therefore T - x2  = (x2 - x1)/S + y1 etc, until we get the formulas below
    */

    // UTC is zero offset,
    long T = localAlarmTime.toDateTime(DateTimeZone.UTC).getMillis();
    System.out.println("T " + String.valueOf(T));
    double Ta = ((slope * To) - Oo + T) / (slope + 1);
    System.out.println("Ta " + String.valueOf(Ta));
    // y2 = T - x2
    double Oa = T - Ta;
    System.out.println("Oa " + String.valueOf(Oa));

    // construct a datetime
    DateTimeZone alarmTz = DateTimeZone.forOffsetMillis((int) Oa);
    DateTime alarmTime = new DateTime((long) Ta, alarmTz);
    Log.d("timeForAlarm", "as origin: " + alarmTime.toDateTime(mOriginTime.getZone()).toString());
    Log.d("timeForAlarm", "as dest: " + alarmTime.toDateTime(mDestTime.getZone()).toString());

    return alarmTime;
}