Changes to tiny date format to remove mon and show short format dates instead

This commit is contained in:
Neil Lalonde 2013-06-28 13:09:53 -04:00
parent 3c9cdead49
commit 2d6118297d
4 changed files with 27 additions and 23 deletions

View File

@ -4,7 +4,7 @@ Discourse.Formatter = (function(){
var updateRelativeAge, autoUpdatingRelativeAge, relativeAge, relativeAgeTiny, var updateRelativeAge, autoUpdatingRelativeAge, relativeAge, relativeAgeTiny,
relativeAgeMedium, relativeAgeMediumSpan, longDate, toTitleCase, relativeAgeMedium, relativeAgeMediumSpan, longDate, toTitleCase,
shortDate, breakUp; shortDate, shortDateNoYear, breakUp;
breakUp = function(string, maxLength){ breakUp = function(string, maxLength){
if(string.length <= maxLength) { if(string.length <= maxLength) {
@ -29,6 +29,10 @@ Discourse.Formatter = (function(){
return moment(date).shortDate(); return moment(date).shortDate();
}; };
shortDateNoYear = function(date) {
return moment(date).shortDateNoYear();
};
// http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript // http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
// TODO: locale support ? // TODO: locale support ?
toTitleCase = function toTitleCase(str) toTitleCase = function toTitleCase(str)
@ -104,16 +108,16 @@ Discourse.Formatter = (function(){
case(distanceInMinutes >= 1440 && distanceInMinutes <= 2519): case(distanceInMinutes >= 1440 && distanceInMinutes <= 2519):
formatted = t("x_days", {count: 1}); formatted = t("x_days", {count: 1});
break; break;
case(distanceInMinutes >= 2520 && distanceInMinutes <= 129599): case(distanceInMinutes >= 2520 && distanceInMinutes <= 20160):
formatted = t("x_days", {count: Math.round(distanceInMinutes / 1440.0)}); formatted = t("x_days", {count: Math.round(distanceInMinutes / 1440.0)});
break; break;
case(distanceInMinutes >= 129600 && distanceInMinutes <= 525599): case(distanceInMinutes >= 20160 && distanceInMinutes <= 525599):
formatted = t("x_months", {count: Math.round(distanceInMinutes / 43200.0)}); formatted = shortDateNoYear(date);
break; break;
default: default:
var months = Math.round(distanceInMinutes / 43200.0); var months = Math.round(distanceInMinutes / 43200.0);
if (months < 24) { if (months < 12) {
formatted = t("x_months", {count: months}); formatted = shortDateNoYear(date);
} else { } else {
formatted = t("over_x_years", {count: Math.round(months / 12.0)}); formatted = t("over_x_years", {count: Math.round(months / 12.0)});
} }

View File

@ -103,7 +103,7 @@
} }
} }
.main-link { .main-link {
width: 515px; width: 495px;
font-size: 16px; font-size: 16px;
i.score { i.score {
@ -132,12 +132,12 @@
@include medium-width { @include medium-width {
.main-link { .main-link {
width: 400px; width: 380px;
} }
} }
@include small-width { @include small-width {
.main-link { .main-link {
width: 355px; width: 335px;
} }
} }
.topic-statuses:empty { .topic-statuses:empty {
@ -178,6 +178,9 @@
color: inherit; color: inherit;
} }
} }
.activity {
width: 50px;
}
} }
// Category list // Category list

View File

@ -28,12 +28,6 @@ en:
x_days: x_days:
one: "1d" one: "1d"
other: "%{count}d" other: "%{count}d"
about_x_months:
one: "1mon"
other: "%{count}mon"
x_months:
one: "1mon"
other: "%{count}mon"
about_x_years: about_x_years:
one: "1y" one: "1y"
other: "%{count}y" other: "%{count}y"

View File

@ -22,6 +22,10 @@ var formatMonths = function(months) {
return formatDays(months * 30); return formatDays(months * 30);
}; };
var shortDate = function(days){
return moment().subtract('days', days).format('D MMM');
};
test("formating medium length dates", function() { test("formating medium length dates", function() {
format = "medium"; format = "medium";
@ -29,10 +33,6 @@ test("formating medium length dates", function() {
return $(html).text(); return $(html).text();
}; };
var shortDate = function(days){
return moment().subtract('days', days).format('D MMM');
};
var shortDateYear = function(days){ var shortDateYear = function(days){
return moment().subtract('days', days).format('D MMM, YYYY'); return moment().subtract('days', days).format('D MMM, YYYY');
}; };
@ -74,10 +74,13 @@ test("formating tiny dates", function() {
equal(formatMins(60), "1h"); equal(formatMins(60), "1h");
equal(formatHours(4), "4h"); equal(formatHours(4), "4h");
equal(formatDays(1), "1d"); equal(formatDays(1), "1d");
equal(formatDays(20), "20d"); equal(formatDays(14), "14d");
equal(formatMonths(3), "3mon"); equal(formatDays(15), shortDate(15));
equal(formatMonths(23), "23mon"); equal(formatDays(92), shortDate(92));
equal(formatMonths(24), "> 2y"); equal(formatDays(364), shortDate(364));
equal(formatDays(365), "> 1y");
equal(formatDays(500), "> 1y");
equal(formatDays(365*2), "> 2y");
}); });
test("autoUpdatingRelativeAge", function() { test("autoUpdatingRelativeAge", function() {