List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.googlecode.icegem.serialization.serializers.JodaTimeDataSerializer.java
License:Open Source License
@Override public boolean toData(Object o, DataOutput dataOutput) throws IOException { if (o instanceof DateTime) { DateTime dt = (DateTime) o; dataOutput.writeLong(dt.getMillis()); Chronology chronology = dt.getChronology(); boolean customChronology = false; if (!chronology.getClass().getName().equals(ISOChronology.class.getName())) { customChronology = true;/* w ww . jav a 2 s .c om*/ } byte flags = 0; boolean customTimeZone = true; String timeZoneId = chronology.getZone().getID(); for (byte i = 0; i < TIMEZONE_IDS.length; i++) { if (timeZoneId.equals(TIMEZONE_IDS[i])) { flags = i; customTimeZone = false; break; } } if (customTimeZone) { flags = CUSTOM_TZ_ID; } flags |= customChronology ? (1 << 7) : 0; dataOutput.write(flags); if (customChronology) { dataOutput.writeUTF(chronology.getClass().getName()); } if (customTimeZone) { dataOutput.writeUTF(chronology.getZone().getID()); } return true; } return false; }
From source file:com.greenowl.callisto.web.rest.dto.SalesActivityDTO.java
public SalesActivityDTO(Long id, Long lotId, User user, Long planId, String planName, DateTime planSubscriptionDate, DateTime planExpiryDate, Double chargeAmount, Double serviceAmount, Double netAmount, Long ppId, DateTime entryDateTime, DateTime exitDateTime, String parkingStatus, String exceptionFlag, String invoiceId) { this.id = id; this.lotId = lotId; this.userId = user.getId(); this.userEmail = user.getLogin(); this.userPhoneNumber = user.getMobileNumber(); this.userLicensePlate = user.getLicensePlate(); this.planName = planName; this.planId = planId; if (planSubscriptionDate != null) { this.planSubscriptionDate = planSubscriptionDate.getMillis(); }/*from w w w.j a v a2s .c om*/ if (planExpiryDate != null) { this.planExpiryDate = planExpiryDate.getMillis(); } this.chargeAmount = chargeAmount; this.serviceAmount = serviceAmount; this.netAmount = netAmount; this.ppId = ppId; if (entryDateTime != null) { this.entryDateTime = entryDateTime.getMillis(); } if (exitDateTime != null) { this.exitDateTime = exitDateTime.getMillis(); } this.parkingStatus = parkingStatus; this.exceptionFlag = exceptionFlag; this.invoiceId = invoiceId; }
From source file:com.grepcurl.random.BaseGenerator.java
License:Apache License
public Date randomDate(String fromDate, String toDate) { if (tryOdds(DEFAULT_CHANCE_OF_NULL_DATE)) { return null; }//from w ww. j a v a2 s. c o m Validate.notNull(fromDate); Validate.notNull(toDate); long lowerBound = _dateTimeFormatter.parseDateTime(fromDate).getMillis(); DateTime upperBoundDateTime = _dateTimeFormatter.parseDateTime(toDate); long upperBound = upperBoundDateTime.getMillis(); long range = upperBound - lowerBound + 1; return upperBoundDateTime.minus(randomLong(0, range)).toDate(); }
From source file:com.gs.fw.common.mithra.attribute.calculator.arithmeticCalculator.TimestampYearCalculator.java
License:Apache License
@Override public Operation optimizedIntegerEq(int value, CalculatedIntegerAttribute intAttribute) { DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(MithraTimestamp.DefaultTimeZone); DateTime dateBefore = new DateTime().withZone(dateTimeZone).withYear(value).withDayOfMonth(1) .withMonthOfYear(1).withTimeAtStartOfDay(); DateTime dateAfter = new DateTime().withZone(dateTimeZone).withYear(value + 1).withDayOfMonth(1) .withMonthOfYear(1).withTimeAtStartOfDay(); Timestamp timestampBefore = new Timestamp(dateBefore.getMillis()); Timestamp timestampAfter = new Timestamp(dateAfter.getMillis()); return this.attribute.greaterThanEquals(timestampBefore).and(attribute.lessThan(timestampAfter)); }
From source file:com.gst.infrastructure.core.api.JodaDateTimeAdapter.java
License:Apache License
@SuppressWarnings("unused") @Override/*w w w. j ava2 s. c om*/ public JsonElement serialize(final DateTime src, final Type typeOfSrc, final JsonSerializationContext context) { JsonElement element = null; if (src != null) { element = new JsonPrimitive(src.getMillis()); } return element; }
From source file:com.guavabot.alarmpreference.Alarm.java
License:Apache License
/** * Calculates the next time that the alarm should go off. * //w w w .j a v a 2 s . com * @return Next trigger time as a UNIX timestamp or {@link Long#MAX_VALUE} if alarm is off. */ public long getNextTrigger() { if (mAlarmOn) { DateTime alarmDt = mTime.toDateTimeToday(); for (int i = 0; i < 8; i++) { if ((mWeeklyAlarms & (1 << (alarmDt.getDayOfWeek() - 1))) != 0) { //if today, we make sure the time is not in the past if (i > 0 || alarmDt.isAfterNow()) { return alarmDt.getMillis(); } } alarmDt = alarmDt.plusDays(1); } } return Long.MAX_VALUE; }
From source file:com.hangum.tadpole.engine.utils.TimeZoneUtil.java
License:Open Source License
/** * ? ? ? .//from w w w.j av a 2 s. co m * * @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.harpatec.examples.converter.DateTimeWriteConverter.java
License:Apache License
@Override public DBObject convert(DateTime source) { DBObject dbo = new BasicDBObject(); dbo.put("millis", source.getMillis()); dbo.put("formatted", source.toDateTime(DateTimeZone.UTC).toString()); return dbo;//from w w w . j av a2 s . c o m }
From source file:com.harpatec.sftp_dist.converter.DateTimeToLongConverter.java
License:Apache License
@Override public Long convert(DateTime source) { return source.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/* w w w . j a va 2s . com*/ 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; }