Skip to content

Commit

Permalink
Added long date format support (issue moment#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-carvalho committed Oct 21, 2011
1 parent 1284b49 commit d440e4e
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 28 deletions.
38 changes: 38 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,26 @@ <h2>Formatted Date</h2>
<td>z</td>
<td>EST CST ... MST PST</td>
</tr>
<tr>
<td><b>Long date</b></td>
<td></td>
</tr>
<tr>
<td>L</td>
<td>07/10/1986</td>
</tr>
<tr>
<td>LL</td>
<td>July 10 1986</td>
</tr>
<tr>
<td>LLL</td>
<td>July 10 1986 8:30 PM</td>
</tr>
<tr>
<td>LLLL</td>
<td>Saturday, July 10 1986 8:30 PM</td>
</tr>
</table>
<a name="/display/from"></a>
<h2>Time from another moment</h2>
Expand Down Expand Up @@ -782,6 +802,12 @@ <h2>Changing languages</h2>
monthsShort : "Jan_Fev_Mar_Avr_Mai_Juin_Juil_Aou_Sep_Oct_Nov_Dec".split("_"),
weekdays : "Dimanche_Lundi_Mardi_Mercredi_Jeudi_Vendredi_Samedi".split("_"),
weekdaysShort : "Dim_Lun_Mar_Mer_Jeu_Ven_Sam".split("_"),
longDateFormat : {
L : "DD/MM/YYYY",
LL : "D MMMM YYYY",
LLL : "D MMMM YYYY HH:mm",
LLLL : "dddd, D MMMM YYYY HH:mm"
},
relativeTime : {
future : "in %s",
past : "il y a %s",
Expand Down Expand Up @@ -885,6 +911,18 @@ <h2>Weekday Abbreviations</h2>
<p>
<pre>
moment.weekdaysShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
</pre>
<a name="/custom/longDateFormats"></a>
<h2>Long Date Formats</h2>
<p><code>moment.longDateFormat</code> should be an object containing a key/value pair for each long date format (L, LL, LLL, LLLL).</p>
<p>
<pre>
moment.longDateFormat = {
L: "MM/DD/YYYY",
LL: "MMMM D YYYY",
LLL: "MMMM D YYYY h:mm A",
LLLL: "dddd, MMMM D YYYY h:mm A"
};
</pre>
</p>
<a name="/custom/relativeTime"></a>
Expand Down
2 changes: 1 addition & 1 deletion lang/all.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion lang/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
monthsShort : "Jan_Fev_Mar_Avr_Mai_Juin_Juil_Aou_Sep_Oct_Nov_Dec".split("_"),
weekdays : "Dimanche_Lundi_Mardi_Mercredi_Jeudi_Vendredi_Samedi".split("_"),
weekdaysShort : "Dim_Lun_Mar_Mer_Jeu_Ven_Sam".split("_"),
// based on this article on writing dates in french:
// http://www.btb.gc.ca/btb.php?lang=fra&cont=868
longDateFormat : {
L : "DD/MM/YYYY",
LL : "D MMMM YYYY",
LLL : "D MMMM YYYY HH:mm",
LLLL : "dddd, D MMMM YYYY HH:mm"
},
relativeTime : {
future : "dans %s",
past : "il y a %s",
Expand Down Expand Up @@ -32,4 +40,4 @@
if (typeof window !== 'undefined' && this.moment && this.moment.lang) {
this.moment.lang('fr', lang);
}
}());
}());
2 changes: 1 addition & 1 deletion lang/fr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion lang/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
monthsShort : "Gen_Feb_Mar_Apr_Mag_Giu_Lug_Ago_Set_Ott_Nov_Dic".split("_"),
weekdays : "Domenica_Lunedi_Martedi_Mercoledi_Giovedi_Venerdi_Sabato".split("_"),
weekdaysShort : "Dom_Lun_Mar_Mer_Gio_Ven_Sab".split("_"),
// copied from french, needs revision from italian speakers
longDateFormat : {
L : "DD/MM/YYYY",
LL : "D MMMM YYYY",
LLL : "D MMMM YYYY HH:mm",
LLLL : "dddd, D MMMM YYYY HH:mm"
},
relativeTime : {
future : "in %s",
past : "%s fa",
Expand Down Expand Up @@ -32,4 +39,4 @@
if (typeof window !== 'undefined' && this.moment && this.moment.lang) {
this.moment.lang('it', lang);
}
}());
}());
2 changes: 1 addition & 1 deletion lang/it.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lang/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
monthsShort : "Jan_Feb_Mar_Abr_Mai_Jun_Jul_Ago_Set_Out_Nov_Dez".split("_"),
weekdays : "Domingo_Segunda-feira_Terça-feira_Quarta-feira_Quinta-feira_Sexta-feira_Sábado".split("_"),
weekdaysShort : "Dom_Seg_Ter_Qua_Qui_Sex_Sáb".split("_"),
longDateFormat : {
L : "DD/MM/YYYY",
LL : "D \\de MMMM \\de YYYY",
LLL : "D \\de MMMM \\de YYYY HH:mm",
LLLL : "dddd, D \\de MMMM \\de YYYY HH:mm"
},
relativeTime : {
future : "em %s",
past : "%s atrás",
Expand Down Expand Up @@ -32,4 +38,4 @@
if (typeof window !== 'undefined' && this.moment && this.moment.lang) {
this.moment.lang('pt', lang);
}
}());
}());
2 changes: 1 addition & 1 deletion lang/pt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
round = Math.round,
languages = {},
hasModule = (typeof module !== 'undefined'),
paramsToParse = 'months|monthsShort|weekdays|weekdaysShort|relativeTime|ordinal'.split('|'),
paramsToParse = 'months|monthsShort|weekdays|weekdaysShort|longDateFormat|relativeTime|ordinal'.split('|'),
i,
VERSION = "1.0.1",
shortcuts = 'Month|Date|Hours|Minutes|Seconds'.split('|');
Expand Down Expand Up @@ -76,7 +76,7 @@
currentHours = date.getHours(),
currentMinutes = date.getMinutes(),
currentSeconds = date.getSeconds(),
charactersToReplace = /(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?)/g,
charactersToReplace = /(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|L?L?L?L?)/g,
nonuppercaseLetters = /[^A-Z]/g,
timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g;
// check if the character is a format
Expand Down Expand Up @@ -171,6 +171,12 @@
// depreciating 'zz' fall through to 'z'
case 'z' :
return (date.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, '');
// LONG DATES
case 'L' :
case 'LL' :
case 'LLL' :
case 'LLLL' :
return formatDate(date, moment.longDateFormat[input]);
// DEFAULT
default :
return input.replace("\\", "");
Expand Down Expand Up @@ -345,6 +351,12 @@
monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
longDateFormat : {
L : "MM/DD/YYYY",
LL : "MMMM D YYYY",
LLL : "MMMM D YYYY h:mm A",
LLLL : "dddd, MMMM D YYYY h:mm A"
},
relativeTime : {
future : "in %s",
past : "%s ago",
Expand Down Expand Up @@ -472,4 +484,4 @@
window.moment = moment;
}

})(Date);
})(Date);
Loading

0 comments on commit d440e4e

Please sign in to comment.