Open y377 opened 1 year ago
Hey @y377, thanks for trying this gem! The algorithm is defined in this method:
You can adjust it a bit using the threshold
and depth
params. You can also use the console to easily play with those options: https://github.com/markets/jekyll-timeago#console
Hey @y377, thanks for trying this gem! The algorithm is defined in this method:
You can adjust it a bit using the
threshold
anddepth
params. You can also use the console to easily play with those options: https://github.com/markets/jekyll-timeago#console
Thanks for your reply, I was a little hasty, because I am a ruby novice, I tried for half a day, but it still failed to work, can you create an addition?
def build_time_ago_slots(days_passed, depth, threshold, current_slots = [])
return current_slots if depth == 0 || days_passed == 0
range = days_to_range(days_passed)
days = days_in(range)
num_elems = (days_passed / days).to_i
current_slots << t(range, count: num_elems)
pending_days = days_passed - (num_elems * days)
custom_days = days_passed + (num_elems * days)
if pending_days > (days_passed * threshold).floor
build_time_ago_slots(pending_days, depth - 1, threshold, current_slots)
elsif
build_time_ago_slots(custom_days, depth, threshold, current_slots)
else
current_slots
end
end
What I'm looking for is a judgment:
default depth: 1
If the user enters a date of 7 days, he gets 1 week. If the user enters a date of 8 days, he gets 8 days. Because I am a Chinese user, for Chinese users, 1 week and 1 day ago, Chinese users are not used to such semantics, they prefer to get 8 days ago Using 2 weeks as an example: 2 weeks is originally 14 days, according to your custom week is 7 days, then the judgment should be, in the second week is the third day or the fourth day (we first divide the week by 2, get 3.5 days), now the judgment comes, if the user enters 10 (7+3) days, get 10 days ago, if the user enters 11 (7+4) days, get 2 weeks ago;
custom_days = 7 + ( week / 2 ) = 10.5 #(week / 2) =3.5;
if days < custom_days # The user entered 10 days;
return 10 days ago;
else # The user entered 11 days;
return 2 weeks ago;
The same principle applies to months and years,What do I need to do? thank you!
I'm not familiar with Western countries, but in Asia, people prefer the semantics I recommend
Let me give you a logical thought (since I don't know ruby, I can only offer my humble opinion) : If this function is implemented, resulting in code refactoring, if the European and American users do not adapt to or do not need such semantics, is it possible to judge according to lib/locales/zh_hans.yml
, if the user defines 'default_locale: 'zh_hans'
, executes the set of 'templates' I need, and periodically other languages, such as'en'
, continue to execute the original code, which does not change the habits of European and American users
Thanks for such detailed explanation @y377! Not sure if I get your points though...
The elsif
in Ruby needs a condition too:
if condition
code
elsif condition
code
else
code
end
Are you suggesting to introduce a new parameter custom_days
? This seems a bit confusing to me sorry 🙏🏼 (what about custom_weeks
, custom_months
, ...).
Maybe you can check out the original pull request where the threshold
param was added #24, in order to properly understand how that flag works.
Let me know how it goes!
@markets Well, my Chinese is English (still using a translator) causing your confusion, I'm sorry, let me rearrange.
The expected effect is: if it is 3 days a week, I want to display 10 days; if it is 4 days a week, I want to display 2 weeks, what should I do?
If I understood properly, you want something like:
To be honest, I'm not sure if this is actually possible with this gem, you should try with depth: 1
and then play with the threshold
value... but this is a bit different, as the threshold
param is more designed to "discard" small values, but you want something like a "round" feature (or "accumulate" on parent range). Maybe you can take a look to https://github.com/radar/distance_of_time_in_words, but as far as I know, this gem doesn't provide Jekyll support by default (so you will need to write a custom Liquid filter to wrap it in your Jekyll app).
@y377 Was looking at this and thinking of ways to incorporate this, either here or in a separate gem. Can you help understand:
@captn3m0 Hi, I'm glad you're interested in this date. The main "dispute" is over the definition of days and weeks, Those over 30 days are counted by month, half year and year. Since a week is 7 days, when less than half of a week, i.e. the third day < (7/2=3.5), so we take the day, when the fourth day, because > (7/2=3.5), so we take the week; Again, let's assume that every month has 30 days (except February), 30/2=15, Suppose it is day 17 when the post is written (or constructed or published); 17/7=2 weeks... 3 days, at this point we should use 17 days ago; Let's say it's day 18, 17/7=2 weeks...... Four days. We use it for three weeks. That is, the number of days remaining after counting the number of days is the general number of days with respect to the week, if it is greater than the week, if it is less than the day
As mentioned above, how can I calculate it?
my
_config.yml
thanks!!