casbloem / vue-luxon

Easy use of datetime with Luxon in Vue
https://npmjs.com/package/vue-luxon
72 stars 8 forks source link

order of replacing :a and :ago #10

Closed morgenstern closed 5 years ago

morgenstern commented 5 years ago

I want to use correct German grammar for time ago which needs the :ago word be placed before the number of days/hours etc.

Example: English: 17 days ago German: vor 17 Tagen

This could be changed through diffForHumans settings as follows:

    diffForHumans: {
      past: ":ago :a :w",
    },

BUT unfortunately the parser replaces :a before replacing :ago which leads to broken results: 17go 17 Tagen [:a]go [:a] [:w]

Possible solution: Change the order in which the parser replaces :a an :ago as follows

FROM:

      return parser
        .replace(/\:a/, amount)
        .replace(/\:ago/, options.i18n.ago)
        .replace(/\:in/, options.i18n.in)
        .replace(/\:w/, str);
    };

TO:

      return parser
        .replace(/\:ago/, options.i18n.ago)
        .replace(/\:in/, options.i18n.in)
        .replace(/\:a/, amount)
        .replace(/\:w/, str);
    };
casbloem commented 5 years ago

I'll change it in the next version. Thanks!