forked from 0x2620/oxjs
misc updates; add geo demo
This commit is contained in:
parent
09a3537dc1
commit
34753cb2ed
9 changed files with 219 additions and 81 deletions
|
|
@ -6,8 +6,8 @@
|
|||
/*@
|
||||
Ox.getDateInWeek <f> Get the date that falls on a given weekday in the same week
|
||||
# Usage
|
||||
(date, weekday) -> <dat> Date
|
||||
(date, weekday, utc) -> <dat> Date
|
||||
(date, weekday) -> <d> Date
|
||||
(date, weekday, utc) -> <d> Date
|
||||
# Arguments
|
||||
date <d> Date
|
||||
weekday <n|s> 1-7 (Monday-Sunday) or name, full ("Monday") or short ("Sun")
|
||||
|
|
@ -23,10 +23,9 @@ Ox.getDateInWeek <f> Get the date that falls on a given weekday in the same week
|
|||
// fixme: why is this Monday first? shouldn't it then be "getDateInISOWeek"??
|
||||
Ox.getDateInWeek = function(date, weekday, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
//Ox.print(date, Ox.getDate(date, utc), Ox.formatDate(date, '%u', utc), date)
|
||||
var sourceWeekday = Ox.getISODay(date, utc),
|
||||
targetWeekday = Ox.isNumber(weekday) ? weekday :
|
||||
Ox.map(Ox.WEEKDAYS, function(v, i) {
|
||||
targetWeekday = Ox.isNumber(weekday) ? weekday
|
||||
: Ox.map(Ox.WEEKDAYS, function(v, i) {
|
||||
return v.substr(0, 3) == weekday.substr(0, 3) ? i + 1 : null;
|
||||
})[0];
|
||||
return Ox.setDate(date, Ox.getDate(date, utc) - sourceWeekday + targetWeekday, utc);
|
||||
|
|
@ -72,8 +71,8 @@ Ox.getDaysInMonth <f> Get the number of days in a given month
|
|||
@*/
|
||||
Ox.getDaysInMonth = function(year, month, utc) {
|
||||
year = Ox.makeYear(year);
|
||||
month = Ox.isNumber(month) ? month :
|
||||
Ox.map(Ox.MONTHS, function(v, i) {
|
||||
month = Ox.isNumber(month) ? month
|
||||
: Ox.map(Ox.MONTHS, function(v, i) {
|
||||
return v.substr(0, 3) == month.substr(0, 3) ? i + 1 : null;
|
||||
})[0];
|
||||
return new Date(year, month, 0).getDate();
|
||||
|
|
@ -201,9 +200,9 @@ Ox.getTimezoneOffsetString <f> Get the local time zone offset as a string
|
|||
@*/
|
||||
Ox.getTimezoneOffsetString = function(date) {
|
||||
var offset = (Ox.makeDate(date)).getTimezoneOffset();
|
||||
return (offset < 0 ? '+' : '-') +
|
||||
Ox.pad(Math.floor(Math.abs(offset) / 60), 2) +
|
||||
Ox.pad(Math.abs(offset) % 60, 2);
|
||||
return (offset < 0 ? '+' : '-')
|
||||
+ Ox.pad(Math.floor(Math.abs(offset) / 60), 2)
|
||||
+ Ox.pad(Math.abs(offset) % 60, 2);
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
@ -218,8 +217,8 @@ Ox.getWeek <f> Get the week of a given day
|
|||
@*/
|
||||
Ox.getWeek = function(date, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
return Math.floor((Ox.getDayOfTheYear(date, utc) +
|
||||
Ox.getFirstDayOfTheYear(date, utc) - 1) / 7);
|
||||
return Math.floor((Ox.getDayOfTheYear(date, utc)
|
||||
+ Ox.getFirstDayOfTheYear(date, utc) - 1) / 7);
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue