當前位置: 首頁>>代碼示例>>Java>>正文


Java PrettyTime類代碼示例

本文整理匯總了Java中org.ocpsoft.prettytime.PrettyTime的典型用法代碼示例。如果您正苦於以下問題:Java PrettyTime類的具體用法?Java PrettyTime怎麽用?Java PrettyTime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PrettyTime類屬於org.ocpsoft.prettytime包,在下文中一共展示了PrettyTime類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onBindViewHolder

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Override
public void onBindViewHolder(NoteAdapter.ViewHolder holder, int position) {
    if(!name.equals(notes.get(position).getFromUserName())) {
        holder.fromName.setText("From: " + notes.get(position).getFromUserName());
    }else{
        SpannableString spanString = new SpannableString("Note to self ");
        spanString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spanString.length(), 0);
        holder.fromName.setText(spanString);
    }
    holder.content.setText(notes.get(position).getContent());
    if(!notes.get(position).isRead()){
        holder.itemView.setBackgroundColor(Color.parseColor("#ffff88"));
    }

    if(!notes.get(position).isViaSlack()){
        holder.viaSlack.setVisibility(View.INVISIBLE);
    }
    PrettyTime pt = new PrettyTime();
    holder.timeStamp.setText(pt.format(notes.get(position).getCreatedAt()));
    notes.get(position).setRead(true);
    notes.get(position).pinInBackground("NOTE");
    notes.get(position).saveInBackground();


}
 
開發者ID:donniepropst,項目名稱:note.cntxt,代碼行數:26,代碼來源:NoteAdapter.java

示例2: onCommand

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
/**
 * Check when the specified person last spoke and return with a response.
 */
@Override
public void onCommand(CommandEvent commandEvent) {
    if (commandEvent.getArgs().length == 0) {
        return;
    }

    // Preparing and responding using query
    String nick = Joiner.on(" ").join(commandEvent.getArgs());

    try {
        PreparedStatement statement = TitanBot.getDatabaseConnection().prepareStatement(
                "SELECT seen FROM seen WHERE nick LIKE ?"
        );
        statement.setString(1, nick);
        ResultSet resultSet = statement.executeQuery();
        PrettyTime prettyTime = new PrettyTime();
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(resultSet.getString("seen"));
        String pretty = prettyTime.format(date);

        TitanBot.sendReply(commandEvent.getSource(), "I last saw " + nick + " " + pretty + ".");
    } catch(Exception e) {
        TitanBot.sendReply(commandEvent.getSource(), "I have never seen " + nick + ".");
    }
}
 
開發者ID:MITBorg,項目名稱:TitanBot,代碼行數:28,代碼來源:LastSeenModule.java

示例3: sendMail

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Async
public void sendMail(User user, Build current) throws MessagingException {
  mailSender.send(msg -> {
    GHUser ghUser = null;
    if (current.getCommit() != null)
      ghUser = github.getUser(current.getCommit().getCommitterName());

    PrettyTime p = new PrettyTime(Locale.ENGLISH);
    if (current.getFinishedAt() != null)
      current.setBuildAt(p.format(DatatypeConverter.parseDateTime(current.getFinishedAt())));

    HashMap<String, Object> model = new HashMap<>();
    model.put("project", current.getBranch().getProject());
    model.put("build", current);
    model.put("committerAvatarUrl", ghUser == null ? null : user.getAvatarUrl());

    MimeMessageHelper h = new MimeMessageHelper(msg, false, "UTF-8");
    h.setFrom("[email protected]");
    h.setTo(user.getEmail());
    h.setSubject("Jandy Performance Report");
    h.setText(FreeMarkerTemplateUtils.processTemplateIntoString(freeMarkerConfigurer.getConfiguration().getTemplate("email.ftl"), model), true);


  });
}
 
開發者ID:jandy-team,項目名稱:jandy,代碼行數:26,代碼來源:Reporter.java

示例4: testGetBuild

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Test
public void testGetBuild() throws Exception {
  TravisClient client = new TravisClient();

  TravisClient.Result result = client.getBuild(79083233);

  System.out.println(result);

  Calendar calendar = DatatypeConverter.parseDateTime((String)result.getBuild().get("started_at"));
  PrettyTime p = new PrettyTime(Locale.ENGLISH);

  System.out.println(p.format(calendar));
  
  assertThat(((Number)result.getBuild().get("commit_id")).longValue(), is(result.getCommit().getId()));
  assertThat(result.getCommit().getId(), is(22542817L));
  assertThat(result.getCommit().getMessage(), is("add depedency of icu4j"));
  assertThat(result.getCommit().getCommitterName(), is("JCooky"));
}
 
開發者ID:jandy-team,項目名稱:jandy,代碼行數:19,代碼來源:TravisClientTest.java

示例5: getInfoContents

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Override
     public View getInfoContents(Marker marker) {
         final Observation observation = mapObservations.getMarkerObservation(marker.getId());
         if (observation == null) {
             return null;
         }

         LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         View v = inflater.inflate(R.layout.observation_infowindow, null);

ObservationProperty primaryField = observation.getPrimaryField();

String type = primaryField != null ? primaryField.getValue().toString() : "Observation";

         TextView primary = (TextView) v.findViewById(R.id.observation_primary);
         primary.setText(type);

         TextView date = (TextView) v.findViewById(R.id.observation_date);
         date.setText(new PrettyTime().format(observation.getTimestamp()));

         return v;
     }
 
開發者ID:ngageoint,項目名稱:mage-android,代碼行數:23,代碼來源:ObservationMarkerCollection.java

示例6: addLastLoginLabel

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
private void addLastLoginLabel(TitledBorder border) {
    SerializablePair<String, Long> lastLoginInfo = null;

    //If user exists
    if (!isCreate()) {
        lastLoginInfo = securityService.getUserLastLoginInfo(entity.getUsername());
    }
    final boolean loginInfoValid = (lastLoginInfo != null);
    Label lastLogin = new Label("lastLogin", new Model());
    border.add(lastLogin);
    if (loginInfoValid) {
        Date date = new Date(lastLoginInfo.getSecond());
        String clientIp = lastLoginInfo.getFirst();
        PrettyTime prettyTime = new PrettyTime();
        lastLogin.setDefaultModelObject(
                "Last logged in: " + prettyTime.format(date) + " (" + date.toString() + "), from "
                        + clientIp + ".");
    } else {
        lastLogin.setDefaultModelObject("Last logged in: " + "Never.");
    }
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:22,代碼來源:UserCreateUpdatePanel.java

示例7: addLastLoginLabel

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
private void addLastLoginLabel() {
    SerializablePair<String, Long> lastLoginInfo = null;
    boolean authenticated = authorizationService.isAuthenticated();
    boolean anonymousLoggedIn = authorizationService.isAnonymous();

    //If a user (not anonymous) is logged in
    if (authenticated && !anonymousLoggedIn) {
        String username = authorizationService.currentUsername();
        if (!StringUtils.isEmpty(username)) {
            //Try to get last login info
            lastLoginInfo = ArtifactoryWebSession.get().getLastLoginInfo();
        }
    }
    final boolean loginInfoValid = lastLoginInfo != null && lastLoginInfo.isNotNull();

    Label lastLogin = new Label("lastLogin", new Model());
    lastLogin.setVisible(loginInfoValid);
    add(lastLogin);
    if (loginInfoValid) {
        Date date = new Date(lastLoginInfo.getSecond());
        String clientIp = lastLoginInfo.getFirst();
        PrettyTime prettyTime = new PrettyTime();
        lastLogin.setDefaultModelObject("Last logged in: " + prettyTime.format(
                date) + " (" + date.toString() + "), from " + clientIp + ".");
    }
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:27,代碼來源:WelcomeBorder.java

示例8: exec

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Override
public Object exec(List arguments) throws TemplateModelException {
  if (arguments.size() < 1) {
    throw new TemplateModelException("require an Instant as argument");
  }
  if (arguments.size() > 2) {
    throw new TemplateModelException("too many arguments");
  }
  PrettyTime prettyTime = new PrettyTime(Environment.getCurrentEnvironment().getLocale());
  // only support day unit now
  if (arguments.size() == 2 && arguments.get(1).toString().equals("Day")) {
    List<TimeUnit> units = prettyTime.getUnits()
        .stream()
        .filter(timeUnit -> timeUnit.getMillisPerUnit() > new Day().getMillisPerUnit())
        .collect(Collectors.toList());
    units.forEach(prettyTime::removeUnit);
  }

  StringModel stringModel = (StringModel) arguments.get(0);
  Instant instant = (Instant) stringModel.getAdaptedObject(Instant.class);
  return prettyTime.format(Date.from(instant));
}
 
開發者ID:kaif-open,項目名稱:kaif,代碼行數:23,代碼來源:RelativeTime.java

示例9: getFragment

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Override
public Fragment getFragment(int row, int col) {
    Fragment returnFragment = null;

    if (row == 0) {
        FeedHeadline currentHeadline = mHeadlines.get(col);

        String timeFromNow = currentHeadline.hasPubDate() ? new PrettyTime().format(currentHeadline.getPostDate()) : "No publish date";
        String headlineWithDate = String.format("-- %s --\n%s\n\n%s", timeFromNow, currentHeadline.getHeadline(), currentHeadline.getArticleText());

        returnFragment = CardFragment.create(currentHeadline.getSourceHost(), headlineWithDate);
        ((CardFragment)returnFragment).setCardGravity(Gravity.BOTTOM);
        ((CardFragment)returnFragment).setExpansionEnabled(true);
        ((CardFragment)returnFragment).setExpansionDirection(CardFragment.EXPAND_DOWN);
    } else if (row == 1) {
        returnFragment = OpenOnPhoneFragment.newInstance(mHeadlines.get(col));
    }

    return returnFragment;
}
 
開發者ID:creativedrewy,項目名稱:WeaRSS,代碼行數:21,代碼來源:HeadlineGridPagerAdapter.java

示例10: setupViews

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
private void setupViews() {
    lastUpdatedText = (TextView) getView().findViewById(R.id.text_lastupdated);
    // Set relative time for last updated
    PrettyTime p = new PrettyTime();
    lastUpdatedText.setText("Last updated " + p.format(new Date(dataManager.getClassGradesLastUpdated(courseID))));

    noGradesText = (TextView) getView().findViewById(R.id.text_no_grade);

    categoryList = (RecyclerView) getView().findViewById(R.id.list_grades);
    categoryList.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
    categoryList.setItemAnimator(new DefaultItemAnimator());
    if(grades != null && grades.categories.length > 0) {
        adapter = new CategoryAdapter(getActivity(), grades);
        categoryList.setAdapter(adapter);
        categoryList.setVisibility(View.VISIBLE);
        noGradesText.setVisibility(View.GONE);
    } else {
        categoryList.setVisibility(View.GONE);
        noGradesText.setVisibility(View.VISIBLE);
    }
}
 
開發者ID:project-manatee,項目名稱:manatee-android,代碼行數:22,代碼來源:CycleFragment.java

示例11: include

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
public void include() {
	menuInfo.include();
	sideBarInfo.include();

	result.include("env", env);
	result.include("prettyTimeFormatter", new PrettyTime(locale));
	result.include("literalFormatter", brutalDateFormat.getInstance("date.joda.pattern"));
	result.include("currentUrl", getCurrentUrl());
	result.include("contextPath", req.getContextPath());
	result.include("deployTimestamp", deployTimestamp());
	result.include("shouldShowAds", ads.shouldShowAds());
	result.on(NotFoundException.class).notFound();
	result.on(BannedUserException.class)
			.include("errors", asList(messageFactory.build("error", "user.errors.banned")))
			.redirectTo(AuthController.class).loginForm("");

}
 
開發者ID:caelum,項目名稱:mamute,代碼行數:18,代碼來源:DefaultViewObjects.java

示例12: onLinkReceived

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@UiThread
void onLinkReceived() {
    PrettyTime prettyTime = new PrettyTime();
    String subtitle = String.format(
            getString(R.string.preview_subtitle_template),
            prettyTime.format(mLink.created_utc.toDate()),
            mLink.author
    );

    invalidateOptionsMenu();
    mCaptionTextView.setText(mLink.title.replace("&amp;", "&"));
    mScoreTextView.setText(mLink.score);
    mUpvoteTextView.setText(mLink.ups);
    mDownvoteTextView.setText(mLink.downs);
    mSubtitleTextView.setText(subtitle);
    mDetailContainer.setVisibility(View.VISIBLE);
}
 
開發者ID:Trolldad,項目名稱:Reddit-Headlines,代碼行數:18,代碼來源:PreviewActivity.java

示例13: getView

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	View row = convertView;
	if (row == null) {
		row = mLayoutInflater.inflate(R.layout.grid_event, parent, false);
	}

	Event event = mEvents.get(position);

	ImageView avatarImageView = (ImageView) row
	    .findViewById(R.id.creatorAvatar);
	ViewGroup avatarLoadingView = (ViewGroup) row
	    .findViewById(R.id.loadingView);
	avatarLoadingView.setVisibility(View.VISIBLE);
	new ImageLoader(avatarImageView, avatarLoadingView).execute(event
	    .getCreator().getAvatarUrl());

	TextView title = (TextView) row.findViewById(R.id.eventTitle);
	title.setText(Html.fromHtml(String.format("%s %s %s", event.getCreator()
	    .getName(), event.getAction(), event.getTarget())));

	TextView timestamp = (TextView) row.findViewById(R.id.eventTime);
	timestamp.setText(new PrettyTime().format(event.getCreatedAt()));

	return row;
}
 
開發者ID:llun,項目名稱:Tent,代碼行數:27,代碼來源:EventsAdapter.java

示例14: getView

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	View row = convertView;
	if (row == null) {
		row = mLayoutInflater.inflate(R.layout.grid_document, parent, false);
	}

	Document document = mDocuments.get(position);

	TextView titleTextView = (TextView) row.findViewById(R.id.title);
	TextView updatedTimeTextView = (TextView) row
	    .findViewById(R.id.updatedTime);

	titleTextView.setText(document.getTitle());
	updatedTimeTextView
	    .setText(new PrettyTime().format(document.getUpdatedAt()));

	return row;
}
 
開發者ID:llun,項目名稱:Tent,代碼行數:20,代碼來源:DocumentsAdapter.java

示例15: getView

import org.ocpsoft.prettytime.PrettyTime; //導入依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	View row = convertView;
	if (row == null) {
		row = mLayoutInflater.inflate(R.layout.grid_project, parent, false);
	}

	Project project = mProjects.get(position);
	TextView projectName = (TextView) row.findViewById(R.id.projectName);
	projectName.setText(project.getName());

	TextView projectUpdatedTime = (TextView) row
	    .findViewById(R.id.projectUpdatedTime);
	projectUpdatedTime.setText(String.format(
	    mResources.getString(R.string.project_last_updated),
	    new PrettyTime().format(project.getUpdatedAt())));

	ImageView starIcon = (ImageView) row.findViewById(R.id.projectStar);
	if (project.isStarred()) {
		starIcon.setVisibility(View.VISIBLE);
	} else {
		starIcon.setVisibility(View.INVISIBLE);
	}

	return row;
}
 
開發者ID:llun,項目名稱:Tent,代碼行數:27,代碼來源:ProjectFragment.java


注:本文中的org.ocpsoft.prettytime.PrettyTime類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。