@Override protected void getContent(ByteBuffer byteBuffer) { writeVersionAndFlags(byteBuffer); if (getVersion() == 1) { IsoTypeWriter.writeUInt64(byteBuffer, DateHelper.convert(creationTime)); IsoTypeWriter.writeUInt64(byteBuffer, DateHelper.convert(modificationTime)); IsoTypeWriter.writeUInt32(byteBuffer, timescale); byteBuffer.putLong(duration); } else { IsoTypeWriter.writeUInt32(byteBuffer, DateHelper.convert(creationTime)); IsoTypeWriter.writeUInt32(byteBuffer, DateHelper.convert(modificationTime)); IsoTypeWriter.writeUInt32(byteBuffer, timescale); byteBuffer.putInt((int) duration); } IsoTypeWriter.writeFixedPoint1616(byteBuffer, rate); IsoTypeWriter.writeFixedPoint88(byteBuffer, volume); IsoTypeWriter.writeUInt16(byteBuffer, 0); IsoTypeWriter.writeUInt32(byteBuffer, 0); IsoTypeWriter.writeUInt32(byteBuffer, 0); matrix.getContent(byteBuffer); byteBuffer.putInt(previewTime); byteBuffer.putInt(previewDuration); byteBuffer.putInt(posterTime); byteBuffer.putInt(selectionTime); byteBuffer.putInt(selectionDuration); byteBuffer.putInt(currentTime); IsoTypeWriter.writeUInt32(byteBuffer, nextTrackId); }
@Override public View getView(int position, View bankView, ViewGroup parent) { // set the rowview View rowView = bankView; // reuse views if (rowView == null) { // if the row view is not null then inflate for display LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); rowView = inflater.inflate(R.layout.password_bank_item, null); } // get the text views and set the values to the values in the list TextView username = (TextView) rowView.findViewById(R.id.value_username); TextView website = (TextView) rowView.findViewById(R.id.value_website); TextView password = (TextView) rowView.findViewById(R.id.value_password); TextView expiration = (TextView) rowView.findViewById(R.id.value_expires); username.setText(PasswordInfoArrayList.get(position).getUsername()); website.setText(PasswordInfoArrayList.get(position).getWebsite()); password.setText(PasswordInfoArrayList.get(position).getPassword()); DateHelper expires = PasswordInfoArrayList.get(position).getExpiration(); boolean expired = expires.isLaterThan(DateHelper.getCurrentDate()); if (expired) { expiration.setTextColor(Color.RED); } String expStr = PasswordInfoArrayList.get(position).getExpiration().toString(); expiration.setText(expStr); return rowView; }
public static void addMedicine(Context context, MedicineObject medicineObject) { DatabaseHelper databaseHelper = new DatabaseHelper(context); databaseHelper.addMedicine(medicineObject); DateHelper.generateDates(context, medicineObject); AlarmHelper.setAlarms( context, DateHelper.getDatesFromMedicineId(context, medicineObject.getId())); }
/** * Returns a Page of DocumentPackages, that last updated in time range, which represents a * paginated query response. Important once you have many DocumentPackages. * * @param status Returned DocumentPackages must have their status set to this value to be included * in the result set * @param request Identifying which page of results to return * @param from Date range starting from this date included * @param to Date range ending of this date included * @return List of DocumentPackages that populate the specified page */ public Page<DocumentPackage> getUpdatedPackagesWithinDateRange( PackageStatus status, PageRequest request, Date from, Date to) { String fromDate = DateHelper.dateToIsoUtcFormat(from); String toDate = DateHelper.dateToIsoUtcFormat(to); String path = template .urlFor(UrlTemplate.PACKAGE_LIST_STATUS_DATE_RANGE_PATH) .replace("{status}", new PackageStatusConverter(status).toAPIPackageStatus()) .replace("{from}", Integer.toString(request.getFrom())) .replace("{to}", Integer.toString(request.to())) .replace("{lastUpdatedStartDate}", fromDate) .replace("{lastUpdatedEndDate}", toDate) .build(); try { String response = client.get(path); Result<Package> results = JacksonUtil.deserialize(response, new TypeReference<Result<Package>>() {}); return convertToPage(results, request); } catch (RequestException e) { throw new EslServerException("Could not get package list.", e); } catch (Exception e) { e.printStackTrace(); throw new EslException("Could not get package list. Exception: " + e.getMessage()); } }
/** * Creates a new Gantt Special Date Range that indicates a certain set of dates. * * @param parent Parent chart * @param start Start date * @param end End date */ public GanttSpecialDateRange(final GanttChart parent, final Calendar start, final Calendar end) { _recurDays = new ArrayList(); _parentChart = parent; if (parent != null) { _parentComposite = parent.getGanttComposite(); } _start = (start == null ? null : DateHelper.getNewCalendar(start)); _end = (end == null ? null : DateHelper.getNewCalendar(end)); if (parent != null) { _parentComposite.addSpecialDateRange(this); } updateCalculations(); }
public static void save(Properties properties, File file) throws IOException { Assert.notNull(properties, "存储的属性为空!"); OutputStream outputStream = new FileOutputStream(file); properties.store(outputStream, "saved on " + DateHelper.getStringDate()); outputStream.flush(); outputStream.close(); }
/** * Ensures the precision. * * @param date * @see DateHelper#getCalendar() */ public DateHolder(final Date date) { this.calendar = DateHelper.getCalendar(); if (date != null) { calendar.setTime(date); } ensurePrecision(); }
/** * Ensures the precision. * * @param date If null, the current date will be used. * @param precision * @see DateHelper#getCalendar() */ public DateHolder(final Date date, final DatePrecision precision) { this.calendar = DateHelper.getCalendar(); if (date != null) { this.calendar.setTime(date); } setPrecision(precision); }
public static void SetFieldValue(Persistent obj, Field field, NodeReference node) { String fieldName = field.getName(); try { if (Persistent.class.isInstance(field.get(obj))) { Persistent fieldAsPersistentObject = (Persistent) field.get(obj); if (fieldAsPersistentObject != null) { fieldAsPersistentObject.Save(); node.set(fieldAsPersistentObject.Id, obj.Id, fieldName); return; } } Long Id = obj.Id; Object fieldValue = field.get(obj); if (fieldValue instanceof java.lang.String) { node.set(fieldValue.toString(), Id, fieldName); } else if (fieldValue instanceof java.lang.Long) { long longValue = field.getLong(obj); node.set(longValue, Id, fieldName); } else if (fieldValue instanceof java.util.Date) { Date dateValue = (Date) fieldValue; node.set(DateHelper.DateToString(dateValue), obj.Id, fieldName); } } catch (Exception e) { e.printStackTrace(); } }
/** Test comparing dates when the Dates are equal. */ public void ignoreTestEquals() { Date date1 = new Date(); Date date2 = (Date) date1.clone(); assertEquals(0, comparator.compare(date1, date2)); date2 = DateHelper.addHours(date2, -3, true); assertEquals(0, comparator.compare(date1, date2)); }
Calendar getActualEndDate() { if (_lastActualEndDate != null) { return _lastActualEndDate; } if (_end != null) { _lastActualEndDate = DateHelper.getNewCalendar(_end); return _end; } // move calendar to end recurring date final Calendar cal = DateHelper.getNewCalendar(_start); for (int i = 0; i < _recurCount; i++) { switch (_frequency) { case REPEAT_DAILY: cal.add(Calendar.DATE, 1); break; case REPEAT_WEEKLY: cal.add(Calendar.WEEK_OF_YEAR, 1); break; case REPEAT_MONTHLY: cal.add(Calendar.MONTH, 1); break; case REPEAT_YEARLY: cal.add(Calendar.YEAR, 1); break; case REPEAT_DDAY: cal.add(Calendar.DATE, _ddayRepeatInterval); break; default: break; } } // set the end day to the highest day of that week final int d = getHighestRecurDate(); cal.set(Calendar.DAY_OF_WEEK, d); cal.set(Calendar.HOUR_OF_DAY, _endHour); cal.set(Calendar.MINUTE, _endMinute); cal.set(Calendar.SECOND, _endSecond); cal.set(Calendar.MILLISECOND, 999); _lastActualEndDate = DateHelper.getNewCalendar(cal); return cal; }
@Override public String toString() { return DateHelper.formatAsUTC(getDate()) + ", time zone=" + calendar.getTimeZone().getID() + ", date=" + getDate().toString(); }
/** * Ensures the precision. * * @param date * @see DateHelper#getCalendar(TimeZone, Locale) */ public DateHolder( final Date date, final DatePrecision precision, final TimeZone timeZone, final Locale locale) { this.calendar = DateHelper.getCalendar(timeZone, locale); this.calendar.setTime(date); setPrecision(precision); }
@Test // 1000000 times: 450 mills. // 1000000 times: 480 mills. // 1000000 times: 487 mills. public void toDate() { Date value = null; int count = 1000000; // 100w long beg = System.currentTimeMillis(); for (int i = 0; i < count; i++) { value = CalendarHelper.toDate(CalendarHelper.today()); } // long end = System.currentTimeMillis(); System.out.println(count + " times: " + (end - beg) + " mills. "); System.out.println(DateHelper.toString(value)); System.out.println(DateHelper.toString(value, DateHelper.DATE_TIME_MILLS_PATTERN)); }
/** Test comparing dates when date1 is lesser than date2 */ public void testLesserThan() { Date date1 = new Date(); Date date2 = (Date) date1.clone(); date1 = DateHelper.addDaysInMonth(date1, -1, true); assertEquals(1, comparator.compare(date1, date2)); date1 = new Date(); date1 = DateHelper.addMonths(date1, -1, true); assertEquals(1, comparator.compare(date1, date2)); date1 = new Date(); date1 = DateHelper.addYears(date1, -1, true); assertEquals(1, comparator.compare(date1, date2)); date1 = new Date(); date1 = DateHelper.addYears(date1, -1, true); date1 = DateHelper.addMonths(date1, -1, true); assertEquals(1, comparator.compare(date1, date2)); }
public void populateMedicineList() { if (extras != null) { Date date = (Date) extras.get("date"); DateFormat dateFormat = DateFormat.getDateInstance(); setTitle(String.format("Medicine on %s", dateFormat.format(date))); populateListView( MedicineHelper.getAllMedicineFromDateObjects( getBaseContext(), DateHelper.getDatesFromDateOnly(getBaseContext(), date))); } else { populateListView(MedicineHelper.getAllMedicines(getBaseContext())); } }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current date as the default date in the picker Calendar cal = DateHelper.getDateFromString(mActivity.getAlarmDate(), Constants.DATE_FORMAT_SHORT_DATE); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); // Create a new instance of DatePickerDialog and return it return new DatePickerDialog(mActivity, mListener, year, month, day); }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); if (getVersion() == 1) { creationTime = DateHelper.convert(IsoTypeReader.readUInt64(content)); modificationTime = DateHelper.convert(IsoTypeReader.readUInt64(content)); timescale = IsoTypeReader.readUInt32(content); duration = content.getLong(); } else { creationTime = DateHelper.convert(IsoTypeReader.readUInt32(content)); modificationTime = DateHelper.convert(IsoTypeReader.readUInt32(content)); timescale = IsoTypeReader.readUInt32(content); duration = content.getInt(); } if (duration < -1) { LOG.logWarn("mvhd duration is not in expected range"); } rate = IsoTypeReader.readFixedPoint1616(content); volume = IsoTypeReader.readFixedPoint88(content); IsoTypeReader.readUInt16(content); IsoTypeReader.readUInt32(content); IsoTypeReader.readUInt32(content); matrix = Matrix.fromByteBuffer(content); previewTime = content.getInt(); previewDuration = content.getInt(); posterTime = content.getInt(); selectionTime = content.getInt(); selectionDuration = content.getInt(); currentTime = content.getInt(); nextTrackId = IsoTypeReader.readUInt32(content); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check if a file exists for today String fileName = DateHelper.getTodayString(); File file = new File(getApplicationContext().getFilesDir(), fileName); if (file.exists()) { // tasks exist for this date, show them startActivity(new Intent(this, TaskViewerActivity.class)); } else { // No tasks for this date, go to create tasks startActivity(new Intent(this, DateSelectActivity.class)); } }
@Override public String format(final LogRecord record) { final StringBuilder logEntry = new StringBuilder(); final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(record.getMillis()); logEntry.append(DateHelper.formatDate(cal)); logEntry.append(" ["); logEntry.append(record.getThreadID()); logEntry.append("] "); logEntry.append(record.getLevel().getName()); logEntry.append(" "); logEntry.append(record.getSourceClassName()); logEntry.append(" "); logEntry.append(record.getSourceMethodName()); logEntry.append(" - "); logEntry.append(record.getMessage()); logEntry.append("\n"); return logEntry.toString(); }
/** * Checks whether the given date is included in this period. When the useTime flag is true, the * time of the parameter (date) and the time of the begin and end dates of the period are taken * into account to compute the result. When the useTime flag is false, the dates are truncated to * compute the result. */ public boolean includes(final Calendar date) { if (date == null) { return false; } else if (begin == null && end == null) { return true; } else { if (useTime) { if (begin == null) { return !date.after(end); } else if (end == null) { return !date.before(begin); } else { return !date.before(begin) && !date.after(end); } } else { final Calendar tDate = DateUtils.truncate(date, Calendar.DATE); Calendar tBegin = begin; Calendar tEnd = end; if (begin != null) { tBegin = DateUtils.truncate(begin, Calendar.DATE); } if (end != null) { // If not using time, we'll asume the end of the interval is // the instant before the next day. tEnd = DateHelper.truncateNextDay(end); } if (tBegin == null) { // it's included if the date is an instant before the next day. return tDate.before(tEnd); } else if (tEnd == null) { // it's included if the date is not before the begin return !tDate.before(tBegin); } else { return !tDate.before(tBegin) && tDate.before(tEnd); } } } }
public void setCreationTime(Date creationTime) { this.creationTime = creationTime; if (DateHelper.convert(creationTime) >= (1l << 32)) { setVersion(1); } }
/** * Ensures the precision. * * @see DateHelper#getCalendar() */ public DateHolder(final DatePrecision precision) { this.calendar = DateHelper.getCalendar(); setPrecision(precision); }
public static void removeMedicine(Context context, int id) { DatabaseHelper databaseHelper = new DatabaseHelper(context); databaseHelper.removeMedicine(id); DateHelper.removeDatesFromMedicineId(context, id); AlarmHelper.cancelAlarmFromMedicineId(context, id); }
protected int encodeLine( MessageTree tree, Message message, ChannelBuffer buf, char type, Policy policy, int level, LineCounter counter) { BufferHelper helper = m_bufferHelper; int count = 0; if (counter != null) { counter.inc(); count += helper.tr1(buf, counter.getCount() % 2 != 0 ? "odd" : "even"); } else { count += helper.tr1(buf, null); } count += helper.td1(buf); count += helper.nbsp(buf, level * 2); // 2 spaces per level count += helper.write(buf, (byte) type); if (type == 'T' && message instanceof Transaction) { long duration = ((Transaction) message).getDurationInMillis(); count += helper.write(buf, m_dateHelper.format(message.getTimestamp() + duration)); } else { count += helper.write(buf, m_dateHelper.format(message.getTimestamp())); } count += helper.td2(buf); count += helper.td(buf, message.getType()); count += helper.td(buf, message.getName()); if (policy != Policy.WITHOUT_STATUS) { if (Message.SUCCESS.equals(message.getStatus())) { count += helper.td(buf, " "); // do not output "0" } else { count += helper.td(buf, message.getStatus(), "class=\"error\""); } Object data = message.getData(); count += helper.td1(buf); if (policy == Policy.WITH_DURATION && message instanceof Transaction) { long durationInMicro = ((Transaction) message).getDurationInMicros(); long durationInMillis = durationInMicro / 1000L; if (durationInMicro < 100L) { count += helper.write(buf, String.format("%.2f", durationInMicro / 1000.0)); } else if (durationInMicro < 10000L) { // less than 10 ms count += helper.write(buf, String.format("%.2f", durationInMicro / 1000.0)); } else { // no fraction count += helper.write(buf, Long.toString(durationInMillis)); } count += helper.write(buf, "ms "); } count += helper.writeRaw(buf, String.valueOf(data)); count += helper.td2(buf); } else { count += helper.td(buf, ""); count += helper.td(buf, ""); } count += helper.tr2(buf); count += helper.crlf(buf); return count; }
List getBlocks(final Calendar start, final Calendar end) { // if (_cachedRanges != null) { return _cachedRanges; } _cachedRanges = new ArrayList(); final Calendar cal = DateHelper.getNewCalendar(_start); final Calendar ourEnd = getActualEndDate(); for (int i = 0; i < _recurCount; i++) { final Calendar calEnd = DateHelper.getNewCalendar(cal); if (_recurDays.isEmpty() && _frequency == REPEAT_DDAY) { cal.set(Calendar.HOUR_OF_DAY, _startHour); cal.set(Calendar.MINUTE, _startMinute); cal.set(Calendar.SECOND, _startSecond); cal.set(Calendar.MILLISECOND, 0); calEnd.set(Calendar.HOUR_OF_DAY, _endHour); calEnd.set(Calendar.MINUTE, _endMinute); calEnd.set(Calendar.SECOND, _endSecond); calEnd.set(Calendar.MILLISECOND, 999); if (calEnd.after(end)) { continue; } if (ourEnd != null && calEnd.after(ourEnd)) { continue; } final List foo = new ArrayList(); foo.add(DateHelper.getNewCalendar(cal)); foo.add(DateHelper.getNewCalendar(calEnd)); _cachedRanges.add(foo); } else { for (int x = 0; x < _recurDays.size(); x++) { final int day = ((Integer) _recurDays.get(x)).intValue(); cal.set(Calendar.HOUR_OF_DAY, _startHour); cal.set(Calendar.MINUTE, _startMinute); cal.set(Calendar.SECOND, _startSecond); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.DAY_OF_WEEK, day); calEnd.set(Calendar.HOUR_OF_DAY, _endHour); calEnd.set(Calendar.MINUTE, _endMinute); calEnd.set(Calendar.SECOND, _endSecond); calEnd.set(Calendar.MILLISECOND, 999); calEnd.set(Calendar.DAY_OF_WEEK, day); if (start != null && calEnd.before(start)) { continue; } if (end != null && cal.after(end) || cal.after(ourEnd)) { continue; } final List foo = new ArrayList(); foo.add(DateHelper.getNewCalendar(cal)); foo.add(DateHelper.getNewCalendar(calEnd)); _cachedRanges.add(foo); } } switch (_frequency) { case REPEAT_DAILY: cal.add(Calendar.DATE, 1); break; case REPEAT_WEEKLY: cal.add(Calendar.WEEK_OF_YEAR, 1); break; case REPEAT_MONTHLY: cal.add(Calendar.MONTH, 1); break; case REPEAT_YEARLY: cal.add(Calendar.YEAR, 1); break; case REPEAT_DDAY: cal.add(Calendar.DATE, _ddayRepeatInterval); break; default: break; } } return _cachedRanges; }
/** * Sets the end date. * * @param end End date */ public void setEnd(final Calendar end) { _end = (end == null ? null : DateHelper.getNewCalendar(end)); updateCalculations(); }
/** * Sets the start date. * * @param start Start date */ public void setStart(final Calendar start) { _start = (start == null ? null : DateHelper.getNewCalendar(start)); updateCalculations(); }
public static Period day(Calendar day) { day = DateHelper.truncate(day); return new Period(day, day); }
public void setModificationTime(Date modificationTime) { this.modificationTime = modificationTime; if (DateHelper.convert(modificationTime) >= (1l << 32)) { setVersion(1); } }