Papanik / twitterjs

Automatically exported from code.google.com/p/twitterjs
MIT License
0 stars 0 forks source link

'st' not appended to 1st of month #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Post a tweet on the 1st of the month
2. Check posted tweet on your site x days (think it's 2) after been posted; the 
date will be in the format 00:00 XX Mon 0th
3.

What is the expected output? What do you see instead?
Expected: 08:00 AM Oct 1st
See instead: 08:00 AM Oct 1th

What version of the product are you using? On what operating system?
1.13.3

Please provide any additional information below.

day.substr(0, 1) won't work for the 1st of the month. I guess you were 
expecting it to return '01' (truncated to 0), but it returns just '1'

I've replaced the following lines entirely:

        function formatDate(date) {
            var ds = date.toDateString().split(/ /),
                mon = monthDict[date.getMonth()],
                day = date.getDate()+'',
                dayi = parseInt(day),
                year = date.getFullYear(),
                thisyear = (new Date()).getFullYear(),
                th = 'th';

            // anti-'th' - but don't do the 11th, 12th or 13th
            if ((dayi % 10) == 1 && day.substr(0, 1) != '1') {
                th = 'st';
            } else if ((dayi % 10) == 2 && day.substr(0, 1) != '1') {
                th = 'nd';
            } else if ((dayi % 10) == 3 && day.substr(0, 1) != '1') {
                th = 'rd';
            }

            if (day.substr(0, 1) == '0') {
                day = day.substr(1);
            }

            return mon + ' ' + day + th + (thisyear != year ? ', ' + year : '');
        }

with:

        function formatDate(date) {
            var ds = date.toDateString().split(/ /),
                mon = monthDict[date.getMonth()],
                day = date.getDate(),
                year = date.getFullYear(),
                thisyear = (new Date()).getFullYear(),
                th = 'th';

            // anti-'th'
            if ((day) == 1 || (day) == 21) {
                th = 'st';
            } else if ((day) == 2 || (day) == 22) {
                th = 'nd';
            } else if ((day) == 3 || (day) == 23) {
                th = 'rd';
            }

            return mon + ' ' + day + th + (thisyear != year ? ', ' + year : '');
        }

and it's working fine now.

Original issue reported on code.google.com by tyy...@gmail.com on 4 Oct 2010 at 9:29