mckamey / countdownjs

A simple JavaScript API for producing an accurate, intuitive description of the timespan between two Date instances.
http://countdownjs.org
MIT License
496 stars 95 forks source link

Improve localization interface #1

Closed mckamey closed 9 years ago

mckamey commented 9 years ago

Issue migrated from Bitbucket...

Currently the localization interface is a bunch of parameters on setLabels(...) and a parameterless resetLabels(). That whole method is getting a bit long and convoluted as it organically grew without much forethought.

This task is to clean it up by creating a new method accepting a general Format object which contains all those features. It will make it easier than remembering how many nulls to put before the value you actually want to set.

The current method looks like:

  countdown.setLabels(singular, plural, last, delim, empty, formatter);

Something like this would allow setting just the things to override:

countdown.setFormat({
    singular: ' millisecond| second| minute| hour| day| week| month| year| decade| century| millennium'
    plural: ' milliseconds| seconds| minutes| hours| days| weeks| months| years| decades| centuries| millennia',
    last: ' and ',
    delim: ', ',
    empty: ' ',
    formatter: function(n){ return n.String(); }
});

It's nice and compact to allow those label lists to be simple pipe ('|') delimited strings, but it should also accept an array of strings.

countdown.setFormat({
    singular: [' millisecond', ' second', ' minute', ' hour', ' day',
        ' week', ' month', ' year', ' decade', ' century', ' millennium']
    plural: [' milliseconds', ' seconds', ' minutes', ' hours', ' days',
        ' weeks', ' months', ' years', ' decades', ' centuries', ' millennia']
});
mckamey commented 9 years ago

TODO: update docs.