From 4122959e04efe4c09e9faa7bf293d9e9c18f9f58 Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Mon, 17 Oct 2011 09:43:07 -0700 Subject: [PATCH] Updating the package.json and docs --- docs/index.html | 290 +++++++++++++++++++++++++++++++++++++++++++++++- package.json | 48 ++++---- 2 files changed, 310 insertions(+), 28 deletions(-) diff --git a/docs/index.html b/docs/index.html index 25a44b5ba..4accee727 100644 --- a/docs/index.html +++ b/docs/index.html @@ -339,7 +339,6 @@ moment().seconds() === new Date().getSeconds();

 moment().minutes(30); // set the minutes to 30
-moment().minutes(); // get the minutes value
 

@@ -347,7 +346,6 @@ moment().minutes(); // get the minutes value

 moment().hours(12); // set the hours to 12
-moment().hours(); // get the hours value
 

@@ -355,7 +353,6 @@ moment().hours(); // get the hours value

 moment().day(5); // set the day to 5
-moment().day(); // get the day value
 

@@ -363,7 +360,6 @@ moment().day(); // get the day value

 moment().month(5); // set the month to June
-moment().month(); // get the month value
 

@@ -371,7 +367,291 @@ moment().month(); // get the month value

 moment().year(1984); // set the year to 1984
-moment().year(); // get the year value
+
+

+ +

Display

+

Once parsing and manipulation are done, you need some way to display the moment. Moment.js offers many ways of doing that.

+ +

Formatted Date

+

The most robust display option is moment.fn.format. It takes a string of tokens and replaces them with their corresponding values from the Date object.

+

+

+var date = new Date(2010, 1, 14, 15, 25, 50, 125);
+moment(date).format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm"
+moment(date).format("ddd, hA");                       // "Sun, 3PM"
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TokenOutput
Month
M1 2 ... 11 12
Mo1st 2nd ... 11th 12th
MM01 02 ... 11 12
MMMJan Feb ... Nov Dec
MMMMJanuary February ... November December
Day of Month
D1 2 ... 30 30
Do1st 2nd ... 30th 31st
DD01 02 ... 30 31
Day of Year
DDD1 2 ... 364 365
DDDo1st 2nd ... 364th 365th
DDDD001 002 ... 364 365
Day of Week
d0 1 ... 5 6
do0th 1st ... 5th 6th
dddSun Mon ... Fri Sat
ddddSunday Monday ... Friday Saturday
Week of Year
w1 2 ... 52 53
wo1st 2nd ... 52nd 53rd
ww01 02 ... 52 53
Year
YY70 71 ... 29 30
YYYY1970 1971 ... 2029 2030
AM/PM
AAM PM
aam pm
Hour
H0 1 ... 22 23
HH00 01 ... 22 23
h1 2 ... 11 12
hh01 02 ... 11 12
Minute
m0 1 ... 58 59
mm00 01 ... 58 59
Second
s0 1 ... 58 59
ss00 01 ... 58 59
Timezone
zEST CST ... MST PST
+ +

Time from another moment

+

Another common way of displaying time, sometimes called timeago, is handled by moment.fn.from.

+

+

+var a = moment([2007, 0, 29]);
+var b = moment([2007, 0, 28]);
+a.from(b) // "a day ago"
+
+

+

If you pass true as the second parameter, you can get the value without the suffix. This is useful wherever you need to have a human readable length of time.

+

+

+var start = moment([2007, 0, 5]);
+var end = moment([2007, 0, 10]);
+start.from(end); // "in 5 days"
+start.from(end, true); // "5 days"
+
+

+

The base strings are customized by moment.lang or by modifying the values directly using moment.relativeTime.

+

The breakdown of which string is displayed when is outlined in the table below.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RangeKeySample Output
0 to 45 secondssseconds ago
45 to 90 secondsma minute ago
90 seconds to 45 minutesmm2 minutes ago ... 45 minutes ago
45 to 90 minuteshan hour ago
90 minutes to 22 hours hh2 hours ago ... 22 hours ago
22 to 36 hoursda day ago
36 hours to 25 daysdd2 days ago ... 25 days ago
25 to 45 daysMa month ago
45 to 345 daysMM2 months ago ... 11 months ago
345 to 547 days (1.5 years)ya year ago
548 days+yy2 years ago ... 20 years ago
+ +

Time from now

+

This is just a map to moment.fn.from(new Date())

+

+

+moment([2007, 0, 29]).fromNow(); // 4 years ago
+
+

+

Like moment.fn.from, if you pass true as the second parameter, you can get the value without the suffix.

+

+

+moment([2007, 0, 29]).fromNow(); // 4 years ago
+moment([2007, 0, 29]).fromNow(true); // 4 years
 

diff --git a/package.json b/package.json index c06bfc781..83144272e 100755 --- a/package.json +++ b/package.json @@ -1,25 +1,27 @@ { - "name": "underscore.date", - "version": "0.6.1", - "description": "Underscore.date is a javascript date library that helps create, manipulate, and format dates without extending the `Date` prototype.", - "homepage": "https://github.com/timrwood/underscore.date", - "author": "Tim Wood (http://timwoodcreates.com/)", - "keywords": [ - "underscore", - "date" - ], - "main": "./underscore.date", - "engines": { - "node": "*" - }, - "repository": { - "type": "git", - "url": "https://github.com/timrwood/underscore.date.git" - }, - "bugs": { - "url": "https://github.com/timrwood/underscore.date/issues" - }, - "licenses" : [ - { "type" : "MIT" } - ] + "name": "moment", + "version": "1.0.0", + "description": "Moment.js is a javascript date library that helps create, manipulate, and format dates without extending the `Date` prototype.", + "homepage": "https://github.com/timrwood/moment", + "author": "Tim Wood (http://timwoodcreates.com/)", + "keywords": [ + "moment", + "date" + ], + "main": "./moment", + "engines": { + "node": "*" + }, + "repository": { + "type": "git", + "url": "https://github.com/timrwood/moment.git" + }, + "bugs": { + "url": "https://github.com/timrwood/moment/issues" + }, + "licenses" : [ + { + "type" : "MIT" + } + ] } -- 2.47.3