Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thanks to such a good plug-in, Adapted to Asian semantic functional requirements #35

Open
y377 opened this issue Jan 6, 2023 · 7 comments
Labels

Comments

@y377
Copy link

y377 commented Jan 6, 2023

Suppose 1 Expected value Calculation formula?
1 week 3 days. 10 days ago.
1 week 4 days. 2 weeks ago.
1 month and 2 weeks. 6 weeks ago
1 month and 3 weeks. 2 months ago
As mentioned above, how can I calculate it?

my _config.yml

jekyll_timeago:
  depth: 1
  threshold: 0.05
  translations_path: "data/timeago_zh_hans.yaml"
  default_locale: 'zh_hans'
  available_locales:
    - 'en'
    - 'zh_hans'

thanks!!

@y377 y377 changed the title Thanks for such a good plugin, could you please publish the calculation formula of threshold? Thanks to such a good plug-in, could you please publish the calculation formula of 'threshold'? Jan 6, 2023
@y377 y377 changed the title Thanks to such a good plug-in, could you please publish the calculation formula of 'threshold'? Thanks to such a good plug-in, could you please publish the calculation formula of [threshold] ? Jan 6, 2023
@markets
Copy link
Owner

markets commented Jan 7, 2023

Hey @y377, thanks for trying this gem! The algorithm is defined in this method:

# Builds time ranges: ['1 month', '5 days']

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

@y377
Copy link
Author

y377 commented Jan 8, 2023

Hey @y377, thanks for trying this gem! The algorithm is defined in this method:

# Builds time ranges: ['1 month', '5 days']

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

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;

I don't know ruby,example demo:
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

@y377 y377 changed the title Thanks to such a good plug-in, could you please publish the calculation formula of [threshold] ? Thanks to such a good plug-in, Adapted to Asian semantic functional requirements Jan 8, 2023
@markets
Copy link
Owner

markets commented Jan 8, 2023

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!

@y377
Copy link
Author

y377 commented Jan 10, 2023

@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?

@markets
Copy link
Owner

markets commented Jan 10, 2023

If I understood properly, you want something like:

  • 1 week and 3 days => 10 days
  • 1 week and 4 days => 2 weeks

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).

@markets markets added feature and removed feature labels Jan 10, 2023
@captn3m0
Copy link
Contributor

captn3m0 commented Feb 1, 2023

@y377 Was looking at this and thinking of ways to incorporate this, either here or in a separate gem. Can you help understand:

  1. Why is "1 week 3 days" -> "10 days", but "1 week 4 days" -> "2 weeks" ? How can we decide on whether we are going downwards or upwards?
  2. Whether such rounding applies at all times, or only when the large value is "1". Will "2 week 3 days" get rounded to "15 days"? Will "6 months, 3 weeks" get rounded to "27 weeks"? Will "5 months, 3 weeks, 2 days" get rounded to "173 days", or "23 weeks", or "23 weeks 2 days".

@y377
Copy link
Author

y377 commented Feb 1, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants