Example usage for org.joda.time DateTime toString

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

Introduction

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

Prototype

@ToString
public String toString() 

Source Link

Document

Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).

Usage

From source file:com.google.android.apps.paco.ServerCommunication.java

License:Open Source License

private void setNextWakeupTime() {
    DateTime nextServerCommunicationTime = new DateTime(userPrefs.getNextServerCommunicationServiceAlarmTime());
    if (isInFuture(nextServerCommunicationTime)) {
        return;/*from   ww  w  .  j av  a2 s  .c  om*/
    }

    DateTime nextCommTime = nextServerCommunicationTime.plusHours(24);
    if (nextCommTime.isBeforeNow() || nextCommTime.isEqualNow()) {
        nextCommTime = new DateTime().plusHours(24);
    }
    Intent ultimateIntent = new Intent(context, ServerCommunicationService.class);
    ultimateIntent.setData(CONTENT_URI);
    PendingIntent intent = PendingIntent.getService(context.getApplicationContext(), 0, ultimateIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, nextCommTime.getMillis(), intent);
    userPrefs.setNextServerCommunicationServiceAlarmTime(nextCommTime.getMillis());
    Log.i(PacoConstants.TAG, "Created alarm for ServerCommunicationService. Time: " + nextCommTime.toString());
}

From source file:com.hangum.tadpole.engine.utils.TimeZoneUtil.java

License:Open Source License

/**
 * ?  ? ?  ./*from w  ww  .j  a v a  2 s  .c om*/
 * 
 * @param localTimeMills
 * @return
 */
public static long chageTimeZone(long localTimeMills) {
    String dbTimeZone = GetAdminPreference.getDBTimezone();
    // db? timezone    .
    if (StringUtils.isEmpty(dbTimeZone)) {
        return localTimeMills;
    } else {
        //   UTC   . 
        DateTime sourceDateTime = new DateTime(localTimeMills,
                DateTimeZone.forID(SessionManager.getTimezone()));
        DateTime targetDateTime = sourceDateTime.withZone(DateTimeZone.forID(dbTimeZone));
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("[SessionManager dbTimezone] %s => %s => %s",
                    SessionManager.getTimezone(), localTimeMills, sourceDateTime.toString()));
            logger.debug(String.format("[targetDateTime] %s => %s", targetDateTime.getMillis(),
                    targetDateTime.toString()));
            logger.debug("===============================================================");
        }

        return targetDateTime.getMillis();
    }
}

From source file:com.helger.maven.buildinfo.GenerateBuildInfoMojo.java

License:Apache License

private Map<String, String> _determineBuildInfoProperties() {
    // Get the current time, using the time zone specified in the settings
    final DateTime aDT = PDTFactory.getCurrentDateTime();

    // Build the default properties
    final Map<String, String> aProps = new LinkedHashMap<String, String>();
    // Version 1: initial
    // Version 2: added dependency information; added per build plugin the key
    // property/*from   ww w.  j  av  a  2 s. c o m*/
    aProps.put("buildinfo.version", "2");

    // Project information
    aProps.put("project.groupid", project.getGroupId());
    aProps.put("project.artifactid", project.getArtifactId());
    aProps.put("project.version", project.getVersion());
    aProps.put("project.name", project.getName());
    aProps.put("project.packaging", project.getPackaging());

    // Parent project information (if available)
    final MavenProject aParentProject = project.getParent();
    if (aParentProject != null) {
        aProps.put("parentproject.groupid", aParentProject.getGroupId());
        aProps.put("parentproject.artifactid", aParentProject.getArtifactId());
        aProps.put("parentproject.version", aParentProject.getVersion());
        aProps.put("parentproject.name", aParentProject.getName());
    }

    // All reactor projects (nested projects)
    // Don't emit this, if this is "1" as than only the current project would be
    // listed
    if (reactorProjects != null && reactorProjects.size() != 1) {
        final String sPrefix = "reactorproject.";

        // The number of reactor projects
        aProps.put(sPrefix + "count", Integer.toString(reactorProjects.size()));

        // Show details of all reactor projects, index starting at 0
        int nIndex = 0;
        for (final MavenProject aReactorProject : reactorProjects) {
            aProps.put(sPrefix + nIndex + ".groupid", aReactorProject.getGroupId());
            aProps.put(sPrefix + nIndex + ".artifactid", aReactorProject.getArtifactId());
            aProps.put(sPrefix + nIndex + ".version", aReactorProject.getVersion());
            aProps.put(sPrefix + nIndex + ".name", aReactorProject.getName());
            ++nIndex;
        }
    }

    // Build Plugins
    final List<?> aBuildPlugins = project.getBuildPlugins();
    if (aBuildPlugins != null) {
        final String sPrefix = "build.plugin.";
        // The number of build plugins
        aProps.put(sPrefix + "count", Integer.toString(aBuildPlugins.size()));

        // Show details of all plugins, index starting at 0
        int nIndex = 0;
        for (final Object aObj : aBuildPlugins) {
            final Plugin aPlugin = (Plugin) aObj;
            aProps.put(sPrefix + nIndex + ".groupid", aPlugin.getGroupId());
            aProps.put(sPrefix + nIndex + ".artifactid", aPlugin.getArtifactId());
            aProps.put(sPrefix + nIndex + ".version", aPlugin.getVersion());
            final Object aConfiguration = aPlugin.getConfiguration();
            if (aConfiguration != null) {
                // Will emit an XML structure!
                aProps.put(sPrefix + nIndex + ".configuration", aConfiguration.toString());
            }
            aProps.put(sPrefix + nIndex + ".key", aPlugin.getKey());
            ++nIndex;
        }
    }

    // Build dependencies
    final List<?> aDependencies = project.getDependencies();
    if (aDependencies != null) {
        final String sDepPrefix = "dependency.";
        // The number of build plugins
        aProps.put(sDepPrefix + "count", Integer.toString(aDependencies.size()));

        // Show details of all dependencies, index starting at 0
        int nDepIndex = 0;
        for (final Object aDepObj : aDependencies) {
            final Dependency aDependency = (Dependency) aDepObj;
            aProps.put(sDepPrefix + nDepIndex + ".groupid", aDependency.getGroupId());
            aProps.put(sDepPrefix + nDepIndex + ".artifactid", aDependency.getArtifactId());
            aProps.put(sDepPrefix + nDepIndex + ".version", aDependency.getVersion());
            aProps.put(sDepPrefix + nDepIndex + ".type", aDependency.getType());
            if (aDependency.getClassifier() != null)
                aProps.put(sDepPrefix + nDepIndex + ".classifier", aDependency.getClassifier());
            aProps.put(sDepPrefix + nDepIndex + ".scope", aDependency.getScope());
            if (aDependency.getSystemPath() != null)
                aProps.put(sDepPrefix + nDepIndex + ".systempath", aDependency.getSystemPath());
            aProps.put(sDepPrefix + nDepIndex + ".optional", Boolean.toString(aDependency.isOptional()));
            aProps.put(sDepPrefix + nDepIndex + ".managementkey", aDependency.getManagementKey());

            // Add all exclusions of the current dependency
            final List<?> aExclusions = aDependency.getExclusions();
            if (aExclusions != null) {
                final String sExclusionPrefix = sDepPrefix + nDepIndex + ".exclusion.";
                // The number of build plugins
                aProps.put(sExclusionPrefix + "count", Integer.toString(aExclusions.size()));

                // Show details of all dependencies, index starting at 0
                int nExclusionIndex = 0;
                for (final Object aExclusionObj : aExclusions) {
                    final Exclusion aExclusion = (Exclusion) aExclusionObj;
                    aProps.put(sExclusionPrefix + nExclusionIndex + ".groupid", aExclusion.getGroupId());
                    aProps.put(sExclusionPrefix + nExclusionIndex + ".artifactid", aExclusion.getArtifactId());
                    ++nExclusionIndex;
                }
            }

            ++nDepIndex;
        }
    }

    // Build date and time
    aProps.put("build.datetime", aDT.toString());
    aProps.put("build.datetime.millis", Long.toString(aDT.getMillis()));
    aProps.put("build.datetime.date", aDT.toLocalDate().toString());
    aProps.put("build.datetime.time", aDT.toLocalTime().toString());
    aProps.put("build.datetime.timezone", aDT.getZone().getID());
    final int nOfsMilliSecs = aDT.getZone().getOffset(aDT);
    aProps.put("build.datetime.timezone.offsethours",
            Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_HOUR));
    aProps.put("build.datetime.timezone.offsetmins",
            Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_MINUTE));
    aProps.put("build.datetime.timezone.offsetsecs",
            Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_SECOND));
    aProps.put("build.datetime.timezone.offsetmillisecs", Integer.toString(nOfsMilliSecs));

    // Emit system properties?
    if (withAllSystemProperties || CollectionHelper.isNotEmpty(selectedSystemProperties))
        for (final Map.Entry<String, String> aEntry : CollectionHelper
                .getSortedByKey(SystemProperties.getAllProperties()).entrySet()) {
            final String sName = aEntry.getKey();
            if (withAllSystemProperties || _matches(selectedSystemProperties, sName))
                if (!_matches(ignoredSystemProperties, sName))
                    aProps.put("systemproperty." + sName, aEntry.getValue());
        }

    // Emit environment variable?
    if (withAllEnvVars || CollectionHelper.isNotEmpty(selectedEnvVars))
        for (final Map.Entry<String, String> aEntry : CollectionHelper.getSortedByKey(System.getenv())
                .entrySet()) {
            final String sName = aEntry.getKey();
            if (withAllEnvVars || _matches(selectedEnvVars, sName))
                if (!_matches(ignoredEnvVars, sName))
                    aProps.put("envvar." + sName, aEntry.getValue());
        }

    return aProps;
}

From source file:com.hmiard.leaves.framework.LeavesApplication.java

License:Open Source License

/**
 * Utility debug.//from ww  w .ja  v a2 s  . c  om
 *
 * @param something String to debug.
 */
public static void say(String something) {

    DateTime date = new DateTime();
    System.out.println(date.toString() + " > Leaves Application : " + something + Leaves.NLSP);
}

From source file:com.hmiard.leaves.webserver.Http.LeavesResponse.java

License:Open Source License

/**
 * Sending the response body.//from   w w  w . j a va 2s.  c o m
 *
 * @param socket OutputStream
 * @throws Error
 */
protected void send(OutputStream socket) throws Error {

    DateTime date = new DateTime();

    try {
        if (status == null)
            throw new Error("Response.send() : the status can't be null !");

        PrintWriter pw = new PrintWriter(socket);
        pw.print("HTTP/1.1 " + status.getDescription() + " \r\n");

        if (mime != null)
            pw.print("Content-Type: " + mime + "\r\n");

        if (header == null || header.get("Date") == null)
            pw.print("Date: " + date.toString() + "\r\n");

        if (header != null)
            for (String key : header.keySet())
                pw.print(key + ": " + header.get(key) + "\r\n");

        sendConnection(pw, header);

        if (requestMethod != GenericSession.Method.HEAD && chunk)
            sendAsChunked(socket, pw);
        else {
            int pending = (data != null) ? data.available() : 0;
            sendContentLength(pw, header, pending);
            pw.print("\r\n");
            pw.flush();
            sendAsFixedLength(socket, pending);
        }
        socket.flush();
        FileUtils.close(data);
    } catch (IOException ioe) {
        Leaves.say("Couldn't write the response body");
    }
}

From source file:com.hmiard.leaves.webserver.Server.LeavesServer.java

License:Open Source License

/**
 * Utility debug./*w  w w  .j  a  v a 2  s .c om*/
 *
 * @param something String to debug.
 */
public static void say(String something) {

    DateTime date = new DateTime();
    System.out.println(date.toString() + " > Leaves Server : " + something);
}

From source file:com.hmsinc.epicenter.model.health.Interaction.java

License:Open Source License

private int calculateAgeFromDOB(final DateTime dob) {

    int years = -1;
    if (dob != null) {

        Validate.isTrue(dob.isBefore(interactionDate), "Date of birth was in the future: " + dob.toString());
        years = new Period(dob, interactionDate, PeriodType.years()).getYears();
    }//from ww  w .  j a v  a  2s  .  co m
    return years;
}

From source file:com.identityconcepts.shibboleth.profile.WSFedHandler.java

License:Apache License

/**
  * Creates an authentication statement for the current request.
  * /*from w  ww.ja  v  a2 s .c  om*/
  * @param requestContext current request context
  * 
  * @return constructed authentication statement
  */
protected AuthnStatement buildAuthnStatement(WSFedRequestContext requestContext) {

    AuthnContext authnContext = buildAuthnContext(requestContext);

    AuthnStatement statement = authnStatementBuilder.buildObject();
    statement.setAuthnContext(authnContext);
    statement.setAuthnInstant(new DateTime());

    Session session = getUserSession(requestContext.getInboundMessageTransport());
    if (session != null) {
        statement.setSessionIndex(session.getSessionID());
    }

    long maxSPSessionLifetime = requestContext.getProfileConfiguration().getMaximumSPSessionLifetime();
    if (maxSPSessionLifetime > 0) {
        DateTime lifetime = new DateTime(DateTimeZone.UTC).plus(maxSPSessionLifetime);
        log.debug("Explicitly setting SP session expiration time to '{}'", lifetime.toString());
        statement.setSessionNotOnOrAfter(lifetime);
    }

    statement.setSubjectLocality(buildSubjectLocality(requestContext));

    return statement;
}

From source file:com.indeed.imhotep.sql.ast2.FromClause.java

License:Apache License

public FromClause(String dataset, DateTime start, DateTime end) {
    this(dataset, start, end, start.toString(), end.toString());
}

From source file:com.jbirdvegas.mgerrit.search.AgeSearch.java

License:Apache License

@Override
public String[] getEscapeArgument() {
    DateTime now = new DateTime();
    Period period = mPeriod;/*from ww w .j  a v  a2  s  .  co  m*/

    // Equals: we need to do some arithmetic to get a range from the period
    if ("=".equals(getOperator())) {
        if (period == null) {
            period = new Period(mInstant, Instant.now());
        }
        DateTime earlier = now.minus(adjust(period, +1));
        DateTime later = now.minus(period);
        return new String[] { earlier.toString(), later.toString() };
    } else {
        if (period == null) {
            return new String[] { mInstant.toString() };
        }
        return new String[] { now.minus(period).toString() };
    }
}