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

Date conversion to micro format #51

Open
satazor opened this issue May 3, 2012 · 2 comments
Open

Date conversion to micro format #51

satazor opened this issue May 3, 2012 · 2 comments
Labels

Comments

@satazor
Copy link
Contributor

satazor commented May 3, 2012

It would be nice to have a function that receives a date object or a valid date string and converts it to a more human readable date:

  • 1 day ago
  • 1 week ago

Some libraries that implement this feature:

@millermedeiros
Copy link
Owner

parsing date strings is tricky (many different formats) but converting milliseconds into the proper "scale" is very easy.

we should add an option to localize (second argument being an object with localization info), the localization scheme should support pluralization, thinking something like:

var ms = 1234567; // diff in milliseconds

ago(ms); // "20 minutes ago"

// l10n
var ptBr = {
  'minutes' : {
    '1' : '1 minuto atrás',
    'other' : '# minutos atrás'
  },
  'days' : {
    '1' : 'ontem', // yesterday
    '2' : 'antes de ontem', // so we can pass custom values for specific numbers
    'other' : '# dias atrás'
  },
  // ... weeks, months, years
};

ago(ms, ptBr); // "20 minutos atrás"

And if you pass a Date object it calculates the diff automatically.

var someDate = new Date(2011, 01, 01);
ago(someDate); // "1 year ago"

I think the utility to parse a date string into a Date object should be implemented separately and inside a date package. I think the ago() method should be inside the time package.

@satazor
Copy link
Contributor Author

satazor commented May 4, 2012

Agree, but I think that having 2 separate packages for dealing with dates (date & time) could be confusing.

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

2 participants