Java 类org.joda.time.DateTimeComparator 实例源码

项目:OnOff-Tracker    文件:CardItemAdapter.java   
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    ActionsInterval item = items.get(position);
    String title = item.title;
    if (DateTimeComparator.getDateOnlyInstance().compare(item.startDate, item.endDate) != 0) {
        title = String.format(holder.title.getContext().getString(R.string.cardview_title),
                item.title,
                fmt.print(item.startDate),
                fmt.print(item.endDate));

    }
    holder.title.setText(title);
    holder.screenOn.setText(String.format(holder.screenOn.getContext().getString(R.string.cardview_screenon), item.screenOn));
    holder.screenOff.setText(String.format(holder.screenOff.getContext().getString(R.string.cardview_screenoff), item.screenOff));
    holder.unlocked.setText(String.format(holder.unlocked.getContext().getString(R.string.cardview_unlocked), item.unlocked));
}
项目:SpartaHack-Android    文件:SchedulePresenterTest.java   
@Test public void testCompare() throws Exception {
    Event rhsEvent = mock(Event.class);
    Event lhsEvent = mock(Event.class);

    DateTimeComparator dateTimeComparator = DateTimeComparator.getInstance();

    DateTime rhsDateTime = new DateTime(2017, 1, 20, 0, 0, 0, 0);
    DateTime lhsDateTime = new DateTime(2017, 1, 21, 0, 0, 0, 0);

    // set each event to return their respective DateTime
    when(rhsEvent.getTime()).thenReturn(rhsDateTime);
    when(lhsEvent.getTime()).thenReturn(lhsDateTime);

    // comparison test on DateTimes where lhs > rhs
    assertEquals(dateTimeComparator.compare(lhsEvent.getTime(), rhsEvent.getTime()), presenter.compare(lhsEvent, rhsEvent));

    rhsDateTime = new DateTime(2017, 1, 21, 0, 0, 0, 0);
    lhsDateTime = new DateTime(2017, 1, 20, 0, 0, 0, 0);

    // set each event to return their respective DateTime
    when(rhsEvent.getTime()).thenReturn(rhsDateTime);
    when(lhsEvent.getTime()).thenReturn(lhsDateTime);

    // comparison test on DateTimes where lhs < rhs
    assertEquals(dateTimeComparator.compare(lhsEvent.getTime(), rhsEvent.getTime()), presenter.compare(lhsEvent, rhsEvent));
}
项目:togg    文件:DateTimeFormatter.java   
public static String dayOrDate(Date date) {
    int actualDayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
    int actualYear = Calendar.getInstance().get(Calendar.YEAR);
    Calendar c = Calendar.getInstance();
    c.setTime(date);

    DateTimeComparator comparator = DateTimeComparator
            .getDateOnlyInstance();

    String result;
    if (comparator.compare(date, new Date()) == 0) {
        result = ToggApp.getApplication().getResources()
                .getString(R.string.today);
    } else if (actualYear == c.get(Calendar.YEAR)
            && actualDayOfYear - c.get(Calendar.DAY_OF_YEAR) == 1) {
        result = ToggApp.getApplication().getResources()
                .getString(R.string.yesterday);
    } else {
        result = literalDate(date);
    }

    return result;
}
项目:wulkanowy    文件:TimetableFragmentTab.java   
private boolean getExpanded(String dayDate) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(DATE_PATTERN);
    DateTime dayTime = dateTimeFormatter.parseDateTime(dayDate);

    DateTime currentDate = new DateTime();

    if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
        currentDate = currentDate.plusDays(2);
    } else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        currentDate = currentDate.plusDays(1);
    }

    return DateTimeComparator.getDateOnlyInstance().compare(currentDate, dayTime) == 0;
}
项目:cassandra-reaper    文件:RepairRun.java   
/**
 * Order RepairRun instances by time. Primarily endTime, secondarily startTime. Descending, i.e. latest first.
 *
 * @param other the RepairRun compared to
 * @return negative if this RepairRun is later than the specified RepairRun. Positive if earlier. 0 if equal.
 */
@Override
public int compareTo(RepairRun other) {
  DateTimeComparator comparator = DateTimeComparator.getInstance();
  int endTimeComparison = comparator.compare(endTime, other.endTime);
  if (endTimeComparison != 0) {
    return -endTimeComparison;
  } else {
    return -comparator.compare(startTime, other.startTime);
  }
}
项目:dhis2-android-eventcapture    文件:FormSectionActivity.java   
private void showDatePickerDialog() {
    final OnDateSetListener onDateSetListener = new OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, monthOfYear);
            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);

            String stringDate = (new SimpleDateFormat(DATE_FORMAT, Locale.US))
                    .format(calendar.getTime());
            String newValue = String.format(Locale.getDefault(), "%s: %s",
                    getString(R.string.report_date), stringDate);
            textViewReportDate.setText(newValue);

            DateTime currentDateTime = DateTime.now();
            DateTime selectedDateTime = DateTime.parse(stringDate);

            /*
            * in case when user selected today's date, we need to know about time as well.
            * selectedDateTime does not contain time information (only date), that's why we
            * need to create a new DateTime object by calling DateTime.now()
            */
            DateTime dateTime;
            if (DateTimeComparator.getDateOnlyInstance()
                    .compare(currentDateTime, selectedDateTime) == 0) {
                dateTime = currentDateTime;
            } else {
                dateTime = selectedDateTime;
            }

            formSectionPresenter.saveEventDate(getEventUid(), dateTime);
        }
    };

    DatePickerDialogFragment datePickerDialogFragment =
            DatePickerDialogFragment.newInstance(false);
    datePickerDialogFragment.setOnDateSetListener(onDateSetListener);
    datePickerDialogFragment.show(getSupportFragmentManager());
}
项目:sakai    文件:EventSummary.java   
private boolean isToday(long dateMs) {
    TimeZone timeZone = getCurrentUserTimezone();
    DateTime thisDate = new DateTime(dateMs).withZone(DateTimeZone.forTimeZone(timeZone));
    //Start of day at this local
    DateTime today = new DateTime().withTime(0, 0, 0, 0).withZone(DateTimeZone.forTimeZone(timeZone));
    DateTimeComparator dtComp = DateTimeComparator.getDateOnlyInstance();
    return  (dtComp.compare(thisDate, today) == 0);

}
项目:message-server    文件:MMXTopicsItemsResourceTest.java   
private void sortAscending(List<MMXPubSubItem> list) {
  Collections.sort(list, new Comparator<MMXPubSubItem>(){
    public int compare(MMXPubSubItem o1, MMXPubSubItem o2){
      MMXPubSubPayload payload1 = o1.getPayload();
      MMXPubSubPayload payload2 = o2.getPayload();
      DateTime d1 = new DateTime(payload1.getCreationDate());
      DateTime d2 = new DateTime(payload2.getCreationDate());
      return DateTimeComparator.getInstance().compare(d1, d2);
    }
  });
}
项目:message-server    文件:MMXTopicsItemsResourceTest.java   
private void sortDescending(List<MMXPubSubItem> list) {
  Collections.sort(list, new Comparator<MMXPubSubItem>(){
    public int compare(MMXPubSubItem o1, MMXPubSubItem o2){
      MMXPubSubPayload payload1 = o1.getPayload();
      MMXPubSubPayload payload2 = o2.getPayload();
      DateTime d1 = new DateTime(payload1.getCreationDate());
      DateTime d2 = new DateTime(payload2.getCreationDate());
      return DateTimeComparator.getInstance().compare(d2, d1);
    }
  });
}
项目:SpartaHack-Android    文件:AnnouncementPresenter.java   
@Override public int compare(Announcement lhs, Announcement rhs) {
    if (!rhs.getPinned() && !lhs.getPinned())
        return DateTimeComparator.getInstance().compare(rhs.getCreatedAt(), lhs.getCreatedAt());
    else if (rhs.getPinned() && lhs.getPinned())
        return DateTimeComparator.getInstance().compare(rhs.getCreatedAt(), lhs.getCreatedAt());
    else if (rhs.getPinned())
        return RIGHT_FIRST;
    return LEFT_FIRST;
}
项目:SpartaHack-Android    文件:ScheduleFragment.java   
@Override public void showEvents(ArrayList<Event> events) {
    EventListAdapter eventListAdapter = new EventListAdapter(getActivity(), events);

    ArrayList<SimpleSectionedRecyclerViewAdapter.Section> sections = new ArrayList<>();

    DateTime date = events.get(0).getTime();
    SimpleDateFormat formatDate = new SimpleDateFormat("EEEE", Locale.US);

    sections.add(new SimpleSectionedRecyclerViewAdapter.Section(0, formatDate.format(date.toDate())));
    // location the header should go at
    int sectionLoc = 0;
    for (Event e : events){
        if (DateTimeComparator.getDateOnlyInstance().compare(e.getTime(), date) == 1){
            sections.add(new SimpleSectionedRecyclerViewAdapter.Section(sectionLoc, formatDate.format(e.getTime().toDate())));
            date = e.getTime();
        }
        sectionLoc++;
    }

    SimpleSectionedRecyclerViewAdapter.Section[] dummy = new SimpleSectionedRecyclerViewAdapter.Section[sections.size()];

    SimpleSectionedRecyclerViewAdapter adapter = new SimpleSectionedRecyclerViewAdapter(getActivity(), R.layout.section_header, R.id.section_text, eventListAdapter);

    adapter.setSections(sections.toArray(dummy));

    recyclerView.setAdapter(adapter);

    errorMessage.setVisibility(View.GONE);
    progressBar.setVisibility(View.GONE);
    recyclerView.setVisibility(View.VISIBLE);
}
项目:togg    文件:TimeEntriesAdapter.java   
private DateTimeComparator getComparator() {
    if (mComparator == null) {
        this.mComparator = DateTimeComparator.getDateOnlyInstance();
    }

    return mComparator;
}
项目:sakai    文件:EventSummary.java   
private boolean isToday(long dateMs) {
    TimeZone timeZone = getCurrentUserTimezone();
    DateTime thisDate = new DateTime(dateMs).withZone(DateTimeZone.forTimeZone(timeZone));
    //Start of day at this local
    DateTime today = new DateTime().withTime(0, 0, 0, 0).withZone(DateTimeZone.forTimeZone(timeZone));
    DateTimeComparator dtComp = DateTimeComparator.getDateOnlyInstance();
    return  (dtComp.compare(thisDate, today) == 0);

}
项目:BlogReader-javafx    文件:DateUtilTest.java   
/**
 * Test of parseDateRfc822 method, of class DateUtil.
 */
@Test
public void testParseDateRfc822() {
    String s = "Wed, 02 Oct 2002 15:00:00 +0200";
    DateTime expResult = DateUtil.createDate(
            2002, DateTimeConstants.OCTOBER, 2, 
            15, 0, 0, 0,
            "+02:00");
    DateTime result = DateUtil.parseDateRfc822(s);
    assertNotNull(result);
    if (result != null) {
        assertEquals(expResult.getMillis(), result.getMillis());
    }
    //assertEquals(expResult, result);
    //assertTrue(expResult.equals(result));
    assertEquals(0, DateTimeComparator.getInstance().compare(expResult, result));

    s = "Tue, 24 Feb 2009 08:30:36 +0000";
    expResult = DateUtil.createDate(
            2009, DateTimeConstants.FEBRUARY, 24, 
            8, 30, 36, 0,
            "+00:00");
    result = DateUtil.parseDateRfc822(s);
    assertNotNull(result);
    if (result != null) {
        assertEquals(expResult.getMillis(), result.getMillis());
    }
    //assertEquals(expResult, result);
    //assertTrue(expResult.equals(result));
    assertEquals(0, DateTimeComparator.getInstance().compare(expResult, result));
}
项目:atlas-deer    文件:BroadcastAggregator.java   
Collection<ResolvedBroadcast> sortBroadcastsByDateTime(ImmutableMultimap<DateTime, ResolvedBroadcast> broadcastMap) {

        List<DateTime> dateTimes = Lists.newArrayList(broadcastMap.keySet());
        dateTimes.sort(DateTimeComparator.getInstance());

        Ordering<ResolvedBroadcast> dateTimeOrdering = Ordering.explicit(dateTimes)
                .onResultOf(resolvedBroadcast ->
                        resolvedBroadcast.getBroadcast().getTransmissionTime()
                );

        return dateTimeOrdering.sortedCopy(broadcastMap.values());
    }
项目:Weather-Guru-MVP    文件:DateUtils.java   
/**
 * Check if some date is the current day
 */
private static boolean isToday(String date) {
  return DateTimeComparator.getDateOnlyInstance().compare(new DateTime(), new DateTime(date))
      == 0;
}
项目:messagemedia-rest-api-java-sdk    文件:JsonUtilitiesTest.java   
@Test
@UseDataProvider("validDateStrings")
public void testDeserializationOfValidDateString(String dateString, DateTime dateObject) throws ParseException, IOException {
    DateTimeComparator dateTimeComparator = DateTimeComparator.getInstance();
    assertEquals(0, dateTimeComparator.compare(dateObject, bytesToObject(("\"" + dateString + "\"").getBytes("UTF-8"), DateTime.class)));
}
项目:Portofino    文件:PositionComparator.java   
public PositionComparator() {
    dateTimeComparator = DateTimeComparator.getInstance();
    stringComparator = new StringComparator();
}
项目:Portofino    文件:EventWeekComparator.java   
public EventWeekComparator() {
    dateTimeComparator = DateTimeComparator.getInstance();
    stringComparator = new StringComparator();
}
项目:civilizer    文件:FragmentOrder.java   
@Override
public int compare(Fragment arg0, Fragment arg1) {
    DateTimeComparator comparator = DateTimeComparator.getInstance();
    return comparator.compare(arg0.getUpdateDatetime(), arg1.getUpdateDatetime());
}
项目:civilizer    文件:FragmentOrder.java   
@Override
public int compare(Fragment arg0, Fragment arg1) {
    DateTimeComparator comparator = DateTimeComparator.getInstance();
    return comparator.compare(arg0.getCreationDatetime(), arg1.getCreationDatetime());
}
项目:SpartaHack-Android    文件:SchedulePresenter.java   
@Override public int compare(Event lhs, Event rhs) {
    return DateTimeComparator.getInstance().compare(lhs.getTime(), rhs.getTime());
}
项目:manydesigns.cn    文件:EventWeekComparator.java   
public EventWeekComparator() {
    dateTimeComparator = DateTimeComparator.getInstance();
    stringComparator = new StringComparator();
}
项目:BlogReader-javafx    文件:Controller.java   
/**
 * 
 * @param url
 * @param rb 
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    logger.log(Level.INFO, "initialize");

    // initialize label
    titleLabel.textProperty().bind(model.titleProperty());

    progressIndicator.visibleProperty().bind(isLoading);

    // initialize table
    // * add two columns
    // * bind the model
    // * add selection listener
    TableColumn titleColumn = new TableColumn();
    titleColumn.setText(TITLE_COLUMN_TEXT);
    titleColumn.prefWidthProperty().bind(itemsTableView.widthProperty().subtract(200));
    titleColumn.setCellValueFactory(new PropertyValueFactory<FeedItem, String>(TITLE_PROPERTY_NAME));

    TableColumn pubDateColumn = new TableColumn();
    pubDateColumn.setText(DATE_COLUMN_TEXT);
    pubDateColumn.setPrefWidth(180);
    pubDateColumn.setCellValueFactory(new PropertyValueFactory<FeedItem, DateTime>(PUBDATE_PROPERTY_NAME));
    pubDateColumn.setCellFactory(getDateTimeCellFactory(DATE_FORMAT));
    pubDateColumn.setComparator(DateTimeComparator.getInstance());

    itemsTableView.getColumns().add(titleColumn);
    itemsTableView.getColumns().add(pubDateColumn);
    itemsTableView.itemsProperty().bind(model.itemsProperty());
    itemsTableView.getSelectionModel().selectedItemProperty()
            .addListener(new SelectionChangeListener(itemWebView));

    // initialize webview
    // * disable the contextmenu
    // * listen to statechanges
    itemWebView.setContextMenuEnabled(false);
    final WebEngine webEngine = itemWebView.getEngine();
    webEngine.getLoadWorker().stateProperty().addListener(
            new WebEngineChangeListener(webEngine));

    // fetch data in the background
    logger.log(Level.INFO, "Begin loading feed");
    Task<Document> getFeedDocument = new LoadDocumentTask(FEED_URL);
    getFeedDocument.valueProperty().addListener(new ChangeListener<Document>() {
        @Override
        public void changed(ObservableValue<? extends Document> ov, Document t, Document t1) {
            model.itemsProperty().clear();
            Document doc = t1;
            if (doc != null) {
                final String title = FeedParser.readTitle(doc);
                final List<FeedItem> items = FeedParser.readItems(doc);
                if (title != null && items != null) {
                    logger.log(Level.INFO, "Feed loaded and read");
                    model.titleProperty().set(title);
                    model.itemsProperty().addAll(items);
                    itemsTableView.getSelectionModel().selectFirst();
                } else {
                    logger.log(Level.SEVERE, "Error reading feed");
                    model.titleProperty().set("Error reading feed");
                }
            } else {
                logger.log(Level.SEVERE, "Error loading feed");
                model.titleProperty().set("Error loading feed");
            }
            isLoading.set(false);
        }
    });
    new Thread(getFeedDocument).start();

}
项目:kafka-connect-mixpanel    文件:DateUtils.java   
public static int compare(String d1, String d2){

        DateTime date1 = DateTime.parse(d1);
        DateTime date2 = DateTime.parse(d2);

        return DateTimeComparator.getDateOnlyInstance().compare(date1, date2);
    }