Additionnal methods for date manipulation
Number of milliseconds in a day (24 hours per day)
Number of milliseconds in an hour (60 minutes per hour)
Number of milliseconds in a minute (60 seconds per minute)
Number of milliseconds in a month (4.348121428571429 weeks per month)
Number of milliseconds in a second (1000 ms per second)
Number of milliseconds in a week (7 days per week)
Number of milliseconds in a year (365.2422 days per year)
Flexible formatting a given date object.
format
date = NOW
lang = CURRENT_ENV_LANG
format
String
A custom format composed of %- tokens. Characters that are not part of a token will be rendered literally.
%Y,%y
Token
Year variants: [2011, 11]
%M,%m,%A,%a,%B,%b,%C,%c
Token
Month variants: [01, 1, January, january, Jan, jan, JA, Ja]
%D,%d,%e
Token
Day variants: [02, 2, 2nd]
%W,%w,%X,%x,%Z,%z
Token
Weekday variants: [Sunday, sunday, Sun, sun, Su, su]
%H,%h,%K,%k,%p
Token
Hour variants [15, 15, 03, 3, pm]
%I,%i
Token
Minute variants [04, 4]
%S,%s
Token
Second variants [05, 5]
[date = NOW]
Date
Optional
A date to be formatted.
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
The formatted date.
kafe.date.format('%W, %A %e, %Y', new Date('2013-07-17'), 'en');
// returns "Tuesday, July 16th, 2013"
kafe.date.format('%W, %d %a, %Y', new Date('2013-07-17'), 'fr');
// returns "Mardi, 16 juillet, 2013"
Get a relative time expression from a specific datetime.
time
now = NOW
lang = CURRENT_ENV_LANG
time
Date
Specific datetime object.
[now = NOW]
Date
Optional
Comparative datetime object to calculate the time difference.
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
The relative time expression
kafe.date.formatRelative(new Date('2013-07-19 6:00:00'), new Date('2013-07-19 20:00:00'), 'en');
// returns "14 hours ago"
kafe.date.formatRelative(new Date('2013-05-19'), new Date('2013-07-19'), 'en');
// returns "2 months ago"
Get a clean representation for all possible days of a month.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of clean representations for all possible days of a month.
kafe.date.getDayNames('en');
// returns ["1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", ... ]
kafe.date.getDayNames('en')[3];
// returns "4th"
Get the day number out of the full year (365 days).
d
d
Date
The date
The day of the year
kafe.date.getDayYear(new Date('2013-07-17'));
// returns 198
Get the number of days for all the months of a given year.
year
year
Number
The year.
An ordered array of day counts for each months of the given year.
kafe.date.getMaxMonth(2013);
// returns [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
kafe.date.getMaxMonth(2013)[3];
// returns 30
Get the 1-char abbreviations of the months of the year.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of 1-char month abbreviations.
kafe.date.getMonth1Names('en');
// returns ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"]
kafe.date.getMonth1Names('en')[3];
// returns "A"
Get the 2-char abbreviations of the months of the year.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of 2-char month abbreviations.
kafe.date.getMonth2Names('en');
// returns ["Ja", "Fe", "Mr", "Al", "Ma", "Jn", "Jl", "Au", "Se", "Oc", "No", "De"]
kafe.date.getMonth2Names('en')[3];
// returns "Al"
Get the 3-char abbreviations of the months of the year.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of 3-char month abbreviations.
kafe.date.getMonth3Names('en');
// returns ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
kafe.date.getMonth3Names('en')[3];
// returns "Apr"
Get the full name of the months of the year.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of month names.
kafe.date.getMonthNames('en');
// returns ["January", "February", "March", "April", "May", "June", ... ]
kafe.date.getMonthNames('en')[3];
// returns "April"
Get the 1-char abbreviations of the days of the week.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of 1-char weekday abbreviations.
kafe.date.getWeekday1Names('en');
// returns ["S", "M", "T", "W", "T", "F", "S"]
kafe.date.getWeekday1Names('en')[3];
// returns "W"
Get the 2-char abbreviations of the days of the week.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of 2-char weekday abbreviations.
kafe.date.getWeekday2Names('en');
// returns ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
kafe.date.getWeekday2Names('en')[3];
// returns "We"
Get the 3-char abbreviations of the days of the week.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of 3-char weekday abbreviations.
kafe.date.getWeekday3Names('en');
// returns ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
kafe.date.getWeekday3Names('en')[3];
// returns "Wed"
Get the full name of the days of the week.
lang = CURRENT_ENV_LANG
[lang = CURRENT_ENV_LANG]
String
Optional
A two character language code.
An ordered array of weekday names.
kafe.date.getWeekdayNames('en');
// returns ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
kafe.date.getWeekdayNames('en')[3];
// returns "Wednesday"
Returns whether the date is within a leap year or not.
year
year
Number
The year.
If it is a leap year or not.
kafe.date.isLeapYear(2013);
// returns false
kafe.date.isLeapYear(2004);
// returns true
Returns whether the date is within a weekend.
d
d
Date
The date
If it is within a weekend or not.
kafe.date.isWeekend(new Date('2013-07-17'));
// returns false
kafe.date.isWeekend(new Date('2013-07-20'));
// returns true
Creates an html table calendar for a given month/year combination. You can also provide specific dates with destination url to be included in the rendered source.
year
month
links
year
Number
The year
month
Number
The month
[links]
Object
Optional
The links by date
YYYY-MM-DD
Array
The links
The rendered HTML
kafe.date.makeMonthCalendar(2013, 4, {'2013-04-03':'http://mybirthday.com/'});
// returns "<table data-month="2013-04"><caption>Avril 2013</caption><thead><tr><th>Dim</th><th>Lun</th><th>Mar</th><th>Mer</th><th>Jeu</th><th>Ven</th><th>Sam</th></thead><tbody><tr><td> </td><td data-date="2013-04-01"><span>1</span></td><td data-date="2013-04-02"><span>2</span></td><td data-date="2013-04-03"><a href="http://mybirthday.com/">3</a></td><td data-date="2013-04-04"><span>4</span></td><td data-date="2013-04-05"><span>5</span></td><td data-date="2013-04-06"><span>6</span></td></tr><tr><td data-date="2013-04-07"><span>7</span></td><td data-date="2013-04-08"><span>8</span></td><td data-date="2013-04-09"><span>9</span></td><td data-date="2013-04-10"><span>10</span></td><td data-date="2013-04-11"><span>11</span></td><td data-date="2013-04-12"><span>12</span></td><td data-date="2013-04-13"><span>13</span></td></tr><tr><td data-date="2013-04-14"><span>14</span></td><td data-date="2013-04-15"><span>15</span></td><td data-date="2013-04-16"><span>16</span></td><td data-date="2013-04-17"><span>17</span></td><td data-date="2013-04-18"><span>18</span></td><td data-date="2013-04-19"><span>19</span></td><td data-date="2013-04-20"><span>20</span></td></tr><tr><td data-date="2013-04-21"><span>21</span></td><td data-date="2013-04-22"><span>22</span></td><td data-date="2013-04-23"><span>23</span></td><td data-date="2013-04-24"><span>24</span></td><td data-date="2013-04-25"><span>25</span></td><td data-date="2013-04-26"><span>26</span></td><td data-date="2013-04-27"><span>27</span></td></tr><tr><td data-date="2013-04-28"><span>28</span></td><td data-date="2013-04-29"><span>29</span></td><td data-date="2013-04-30"><span>30</span></td><td> </td><td> </td><td> </td><td> </td></tr></tbody></table>"
Parses a given datetime string into a standard datetime object.
dtstring
dtstring
String
Custom datetime string
The date object
kafe.date.parse('2012-08-08T12:18:00.000-04:00');
// returns Wed Aug 08 2012 12:18:00 GMT-0400 (EDT)
kafe.date.parse('June 3, 2013');
// returns Mon Jun 03 2013 00:00:00 GMT-0400 (EDT)
Refreshes a dropdown containing the days of a given year/month combination.
obj
month
year
obj
DOMElement
The <select> element
month
Number
The month
year
Number
The year
$('.select-month').on('change', function(e) {
kafe.date.refreshSelectDays('.select-day', $(this).val(), $('.select-year').val());
})