From: Tim Wood Date: Mon, 27 Jun 2011 18:53:58 +0000 (-0700) Subject: finishing themed documentation X-Git-Tag: 0.5.2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bb33ed883ace8b5d8f3fa564220f40b7c2542e7;p=thirdparty%2Fmoment.git finishing themed documentation --- diff --git a/index.html b/index.html index 294e3c691..37f3a3351 100644 --- a/index.html +++ b/index.html @@ -1,77 +1,618 @@ - - - - timrwood/underscore.date @ GitHub - - - - - - Fork me on GitHub - -
- -
- - - - -
- -

underscore.date - by timrwood

- -
- Underscore.date is a javascript date library that helps create, manipulate, and format dates without extending the Date prototype. -
- -

Authors

-

Tim Wood (washwithcare@gmail.com)

-

Contact

-

Tim Wood (washwithcare@gmail.com)

- - -

Download

-

- You can download this project in either - zip or - tar formats. -

-

You can also clone the project with Git - by running: -

$ git clone git://github.com/timrwood/underscore.date
-

- - - -
- - - + + + timrwood | underscore.date @ GitHub + + + + + Fork me on Github + +
+
+ + + + +
+

+ underscore.date + by timrwood +

+ +

Underscore.date is a javascript date library that helps create, manipulate, and format dates without extending the Date prototype.

+ +

Author: Tim Wood (washwithcare@gmail.com)

+

Version: 0.5.1

+

1.82 kb (min + gzip)

+ +

Download

+

You can download this project in either + zip or + tar formats. +

+

You can also clone the project with Git by running: +

$ git clone git://github.com/timrwood/underscore.date
+

+ +

Where to use it

+ +

Node.js

+ +

Install with npm

+ +
npm install underscore.date
+ +

Usage

+ +
var _date = require('underscore.date');
+console.log(_date('September 9 1999').fromNow());
+ +

In the browser

+ +

If underscore exists, underscore.date will mix itself into the underscore namespace, so you can use as you would use an underscore function.

+ +
_.date('September 9 1999').fromNow();
+ +

Otherwise, you should use _date.

+ +
_date('September 9 1999').fromNow();
+ +

_date()

+ +

The library works by creating a _date() wrapper object. To create that wrapper, you can pass any of the following data types in.

+ +

Number

+ +
_date(1300291340510)
+ +

An integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC.

+ +

Date

+ +
_date(new Date(2010, 1, 14, 15, 25, 50, 125))
+ +

Any valid Date object. For more information on Date objects, see the JavaScript Date documentation at MDN

+ +

Array

+ +
_date([2010, 1, 14, 15, 25, 50, 125])
+ +

An array mirroring the parameters passed into Date.UTC().

+ +

[year, month = 0, date = 1, hours = 0, minutes = 0, seconds = 0, milliseconds = 0]

+ +

Any value past the year is optional, and will default to the lowest possible number.

+ +

undefined

+ +
_date()
+ +

If no value is passed to a 'dateInput' parameter, it will default to the current time using new Date().

+ +
_date() === _date(new Date())
+ +

String

+ +
_date("Dec 25, 1995")
+ +

A string that can be parsed by Date.parse().

+ +

String with format

+ +
_date("12-25-1995", "MM-DD-YYYY")
+ +

A string and a format string. The second string will be used as the format to parse the first string.

+ +

The format parts are similar to the formats from _date().format()

+ +

Important: Parsing a string with a format is by far the slowest method of creating a date. + If you have the ability to change the input, it is much faster (~15x) to use Unix timestamps.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
InputOutput
M or MMMonth
D or DDDay of month
DDD or DDDDDay of year
YY2 digit year (if greater than 70, will return 1900's, else 2000's)
YYYY4 digit year
a or AAM/PM
H, HH, h, or hh24 hour (for 12 hour time, use in conjunction with a or A)
m or mmMinutes
s or ssSeconds
+ +

_date Prototype

+ +

underscore.date contains a number of utility functions for manipulating and formatting dates.

+ +

_date.add()

+ +
_date.add(object)
+            
+ +

Adds time per the object passed in.

+ +

The object should have key value pairs as shown below.

+ +
{
+                ms : 200, // milliseconds
+                s : 10,   // seconds
+                m : 10,   // minutes (note: lowercase)
+                h : 2,    // hours
+                d : 3,    // days
+                M : 2,    // months (note: uppercase)
+                y : 3     // years
+            }
+            
+ +

All the parameters are optional. Also, there are no upper limits for the values, so you can overload any of the parameters.

+ +
{ ms : 1000000 } // a million milliseconds
+{ d : 360 }      // 360 days
+            
+ +

Special considerations for months and years

+ +

If the day of the month on the original date is greater than the number of days in the final month, the day of the month will change to the last day in the final month.

+ +

Example:

+ +
_date([2010, 0, 31])              // January 31
+_date([2010, 0, 31]).add({M : 1}) // February 28
+            
+ +

_date.subtract()

+ +
_date.subtract(object)
+            
+ +

Functions the same as _date.add(), only using subtraction instead of addition.

+ +

Example:

+ +
_date([2010, 1, 28])                 // February 28
+_date([2010, 1, 28]).subtract({M:1}) // January 28
+            
+ +

_date.format()

+ +
_date.format(string)
+            
+ +

Returns a human readable string based on the format string that was passed in.

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

The formats are created by creating a string of replacable characters.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
InputOutput
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
zz + Eastern Standard Time ... Pacific Standard Time

+ NOTE: Internet Explorer uses a different implementation of + Date.toString(), so we are unable to retrieve the full string + of the timezone, and will fall back to 'z'.

+ So:
+ Firefox, Chrome, Safari, etc. == 'Eastern Standard Time'
+ Internet Explorer, etc. == 'EST' + +

_date.from()

+ +
_date.from(date, withoutSuffix:boolean, asMilliseconds:boolean)
+            
+ +

Returns a string as relative time ('minutes ago', '5 months ago', etc).

+ +

You can pass anything that you would pass to _date() as the first parameter, or a _date() object.

+ +
_date([2007, 0, 29]).from(_date([2007, 0, 28])) // "a day ago"
+            
+ +

You can pass true as the second parameter to return without the prefixes and suffixes.

+ +
_date([2007, 0, 29]).from(_date([2007, 0, 28]), true) // "a day"
+            
+ +

You can pass true as the third parameter to return as milliseconds. + The number of milliseconds returned will be positive if the date passed + in is later than the first date, and negative if the date passed in is earlier.

+ +
_date([2007, 0, 29]).from(_date([2007, 0, 28]), true , true) // -86400000);
+_date([2007, 0, 27]).from(_date([2007, 0, 28]), true , true) // 86400000);
+            
+ +

The base strings for this function can be customized with _date.relativeTime.

+ +

_date.fromNow()

+ +
_date.fromNow(withoutSuffix:boolean, asMilliseconds:boolean)
+            
+ +

Retuns the time from now.

+ +

A shortcut for _date.from(_date(), withoutSuffix:boolean, asMilliseconds:boolean).

+ +

_date.isLeapYear()

+ +

Returns true if the year is a leap year, false if it is not

+ +

Examples :

+ +
_date([2000]).isLeapYear() // true
+_date([2001]).isLeapYear() // false
+_date([2100]).isLeapYear() // false
+            
+ +

Localization and Customization

+ +

To customize the wording of _date.format() and _date.from(), the strings are exposed through the _date object. You can modify these however you see fit.

+ +

Examples :

+ +
_date.relativeTime.future = "%s from now";
+            _date.relativeTime.past = "%s in the past";
+            
+ +

_date.relativeTime

+ +
_date.relativeTime = {
+future: "in %s",
+past: "%s ago",
+s: "seconds",
+m: "a minute",
+mm: "%d minutes",
+h: "an hour",
+hh: "%d hours",
+d: "a day",
+dd: "%d days",
+M: "a month",
+MM: "%d months",
+y: "a year",
+yy: "%d years"
+};
+            
+ +

The strings used in _date.from().

+ +

future and past are used as the suffixes/prefixes.

+ +

For all these values, a single character refers to the singular, and an double character refers to the plural.

+ +

_date.weekdays

+ +
_date.weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
+            
+ +

An array of day names, starting with Sunday.

+ +

_date.weekdaysShort

+ +
_date.weekdaysShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
+            
+ +

An array of abbreviated day names, starting with Sunday.

+ +

_date.months

+ +
_date.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
+            
+ +

An array of the names of the months, starting with January.

+ +

_date.monthsShort

+ +
_date.monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
+            
+ +

An array of the abbreviated names of the months, starting with January.

+ +

_date.ordinal

+ +
_date.ordinal = function (number) {
+var b = number % 10;
+return (~~ (number % 100 / 10) === 1) ? 'th' : 
+    (b === 1) ? 'st' : 
+    (b === 2) ? 'nd' : 
+    (b === 3) ? 'rd' : 'th';
+};
+            
+ +

A function that returns a string to be appended to the number passed in. + More information on ordinal numbers

+ +

Tests

+ +

There are a bunch of tests in the test/ folder. Check them out. If you think some tests are missing, open an issue, and I'll add it.

+ +

Speed tests

+ +

Floor vs bitwiseor vs bitwisenor vs parseint

+ +

Switch/case vs object of functions lookup

+ +

Left zero filling

+ +

Thanks to...

+ +

The folks over at date.js.

+ +

Everyone who helped with php.js date.

+ +

Ryan McGeary for his work on the jQuery timeago plugin.

+ +

License

+ +

Underscore.date is freely distributable under the terms of the MIT license.

+ +

Changelog

+ +

0.5.1

+ +

Buxfix for issue 5.

+ +

0.5.0

+ +

Dropped the redundant _date.date() in favor of _date(). + Removed _date.now(), as it is a duplicate of _date() with no parameters. + Removed _date.isLeapYear(yearNuumber). Use _date([yearNumber]).isLeapYear() instead. + Exposed customization options through the _date.relativeTime, _date.weekdays, _date.weekdaysShort, _date.months, _date.monthsShort, and _date.ordinal variables instead of the _date.customize() function.

+ +

0.4.1

+ +

Added date input formats for input strings.

+ +

0.4.0

+ +

Added underscore.date to npm. Removed dependancies on underscore.

+ +

0.3.2

+ +

Added 'z' and 'zz' to _.date().format(). Cleaned up some redundant code to trim off some bytes.

+ +

0.3.1

+ +

Cleaned up the namespace. Moved all date manipulation and display functions to the _.date() object.

+ +

0.3.0

+ +

Switched to the Underscore methodology of not mucking with the native objects' prototypes. + Made chaining possible.

+ +

0.2.1

+ +

Changed date names to be a more pseudo standardized 'dddd, MMMM Do YYYY, h:mm:ss a'. + Added Date.prototype functions add, subtract, isdst, and isleapyear.

+ +

0.2.0

+ +

Changed function names to be more concise. + Changed date format from php date format to custom format.

+ +

0.1.0

+ +

Initial release

+ + + +
+ + + diff --git a/site/bg.png b/site/bg.png new file mode 100755 index 000000000..224388e06 Binary files /dev/null and b/site/bg.png differ diff --git a/site/fork.png b/site/fork.png new file mode 100755 index 000000000..146ef8a80 Binary files /dev/null and b/site/fork.png differ diff --git a/site/style.css b/site/style.css new file mode 100755 index 000000000..191d31c88 --- /dev/null +++ b/site/style.css @@ -0,0 +1,90 @@ +/** + * html5doctor.com Reset Stylesheet (Eric Meyer's Reset Reloaded + HTML5 baseline) + * v1.6.1 2010-09-17 | Authors: Eric Meyer & Richard Clark + * html5doctor.com/html-5-reset-stylesheet/ + */ + +html, body, div, span, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, +small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, figcaption, figure, +footer, header, hgroup, menu, nav, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} + +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} + +blockquote, q { quotes: none; } + +blockquote:before, blockquote:after, +q:before, q:after { content: ""; content: none; } + +ins { background-color: #ff9; color: #000; text-decoration: none; } + +mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; } + +del { text-decoration: line-through; } + +abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; } + +table { border-collapse: collapse; border-spacing: 0; } + +hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; } + +input, select { vertical-align: middle; } + +/** + * base styles + */ + + +html { background:#AFBAC4 url(bg.png); text-align:center; color:#313749; } + +a { color:#09489A; } + +h1, h2, h3, h4, h5, h6, th { font-family:Oswald, sans-serif; line-height:1.5em; margin-bottom:20px; text-shadow:1px 1px 0 rgba(255, 255, 255, .4); } + +h1 { font-size:48px; padding-top:10px; border-top:#313749 5px solid; } +h2 { font-size:36px; padding-top:10px; border-top:#313749 2px solid; } +h3 { font-size:24px; padding-top:10px; border-top:#313749 1px dashed; } +h4 { font-size:21px; } +h5 { font-size:18px; } +h6 { font-size:16px; } + +h1 a { color:#fff; text-shadow:1px 1px 0 rgba(0, 0, 0, .4); } + +body, p { font-size:18px; line-height:1.5em; margin-bottom:20px; font-family:"Hoefler Text", Constantia, Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif; } + +pre, code { font-size:18px; line-height:1.5em; font-family:Consolas, "Courier New", Courier, monospace; } + +pre { background:rgba(255, 255, 255, .2); display:block; border:1px solid #313749; padding:10px 20px; margin-bottom:20px; } + +table { margin-bottom:20px; } + +th { padding:5px 10px; } +td { border-top:1px solid #313749; padding:5px 10px; } +td + td { background:rgba(255, 255, 255, .2); } + +/* + * special + */ + +.fork-me { position:absolute; top:0; right:0; text-indent:-9999px; width:149px; height:149px; display:block; background:url(fork.png); } + +/** + * layout + */ + +#container { margin:0 auto; width:960px; padding-top:100px; text-align:left; } \ No newline at end of file