Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/timeagoPublic

In Rust, format Duration into a string like "1 hour ago" or "01hou".

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

vi/timeago

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In Rust, format Duration into string like "1 hour ago" or "01hou".

Currently it does nottake the calendar into account and assumes each month is about 30.4 days long.

Parsing such string back to aDuration is out of scope for this crate. Maybe see thechrono-english crate instead.

Withisolang feature off, it supports Rust from version 1.24.

API

Documentation link

Simplified API excerpt (pseudocode):

pubstructFormatter<L:Language =English>{...}implFormatter{pubfnnew() ->Formatter<English>;pubfnwith_language(l:Language) ->Self;pubfnnum_items(&mutself,x:usize) ->&mutSelf;pubfnmax_unit(&mutself,x:TimeUnit) ->&mutSelf;pubfnmin_unit(&mutself,x:TimeUnit) ->&mutSelf;pubfntoo_low(&mutself,x:&'staticstr) ->&mutSelf;pubfntoo_high(&mutself,x:&'staticstr) ->&mutSelf;pubfnmax_duration(&mutself,x:Duration) ->&mutSelf;pubfnago(&mutself,x:&'staticstr) ->&mutSelf;pubfnconvert(&self,d:Duration) ->String;pubfnconvert_chrono(&self,from: chrono::DateTime,to: chrono::DateTime) ->String;}pubfnfrom_isolang(x: isolang::Language) ->Option<Box<Language>>;pubfnformat_5chars(d:Duration) ->String;

ALanguage can be constructed fromisolang::Language.

Translations

  • English
  • Russian
  • French
  • Portuguese (contributed)
  • German (unchecked)
  • Belarusian (unchecked)
  • Polish (unchecked)
  • Spanish (contributed)
  • Chinese (contributed)
  • Romanian (contributed)
  • Swedish (contributed)
  • Turkish (contributed)
  • Japanese (contributed)
  • Danish (contributed)
  • Italian (contributed)
  • Ukrainian (contributed)

If you checked some language and certify that it's allright, submit a pull request that removes "(unchecked)" or "(contributed)" in the list above.

Tool

There is a helper command line tool that allows easier experimenting when adding a new translation:

$ cargo run --features isolang en    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs     Running `target/debug/timeago en`601 minute ago72002 hours ago

See also

  • chrono-humanize
  • compound_duration - splitDuration into weeks/days/minues/etc. parts

About

In Rust, format Duration into a string like "1 hour ago" or "01hou".

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp