Changing the output of countup

Asked Jun 18, 2021·1 reply·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Is it possible to create a countup command that will only display years/month/days (without hh/mm/ss)?

1 reply

Hey @Scarlet Bee!

Yes, it's doable using a RegExp, we can match the first part of the sentence and adapt to the varying length:

/(\d+\syear(s\b)?\s?)?(\d+\smonth(s\b)?\s?)?(\d+\sday(s\b)?\s?)?/

For example, on the following sentence the RegExp will match:

"3 years 7 months 2 days 18 hours 20 minutes 14 seconds in the future"
3 years 7 months 2 days ,3 years ,s,7 months ,s,2 days ,s

If we remove any years/months/days, or if any are singular instead of plural, it'll still match the correct first part of the sentence. Of course there is waste, but we can get rid of it by only using the first match.

So here's the final command:

!addcom !command_name $(eval t=`$(countup TIME/DATE)`.match(/(\d+\syear(s\b)?\s?)?(\d+\smonth(s\b)?\s?)?(\d+\sday(s\b)?\s?)?/); t[0]+` in the future`)