gregorian-calendar
Advanced tools
Comparing version 2.0.5 to 3.0.0
@@ -17,37 +17,9 @@ /** | ||
* in the default time zone with the default locale. | ||
* - one argument timezoneOffset: | ||
* Constructs a GregorianCalendar based on the current time | ||
* in the given timezoneOffset with the default locale. | ||
* - one argument locale: | ||
* Constructs a GregorianCalendar | ||
* based on the current time in the default time zone with the given locale. | ||
* - two arguments | ||
* Constructs a GregorianCalendar based on the current time in the given time zone with the given locale. | ||
* - zone - the given time zone. | ||
* - aLocale - the given locale. | ||
* | ||
* - 3 to 6 arguments: | ||
* Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale. | ||
* - year - the value used to set the YEAR calendar field in the calendar. | ||
* - month - the value used to set the MONTH calendar field in the calendar. Month value is 0-based. e.g., | ||
* 0 for January. | ||
* - dayOfMonth - the value used to set the DAY_OF_MONTH calendar field in the calendar. | ||
* - hourOfDay - the value used to set the HOUR_OF_DAY calendar field in the calendar. | ||
* - minute - the value used to set the MINUTE calendar field in the calendar. | ||
* - second - the value used to set the SECONDS calendar field in the calendar. | ||
* | ||
* | ||
* @class Date.Gregorian | ||
*/ | ||
function GregorianCalendar(timezoneOffset, locale) { | ||
var args = [].slice.call(arguments, 0); | ||
if (typeof timezoneOffset === 'object') { | ||
locale = timezoneOffset; | ||
timezoneOffset = locale.timezoneOffset; | ||
} else if (args.length >= 3) { | ||
timezoneOffset = locale = null; | ||
} | ||
function GregorianCalendar(locale) { | ||
locale = locale || defaultLocale; | ||
@@ -70,7 +42,5 @@ | ||
*/ | ||
if (typeof timezoneOffset !== 'number') { | ||
timezoneOffset = locale.timezoneOffset; | ||
} | ||
this.timezoneOffset = timezoneOffset; | ||
this.timezoneOffset = locale.timezoneOffset; | ||
/** | ||
@@ -92,6 +62,2 @@ * The first day of the week | ||
this.fieldsComputed = false; | ||
if (arguments.length >= 3) { | ||
this.set.apply(this, args); | ||
} | ||
} | ||
@@ -305,3 +271,5 @@ | ||
if (field === WEEK_OF_MONTH) { | ||
var cal = new GregorianCalendar(fields[YEAR], fields[MONTH], 1); | ||
var cal = this.clone(); | ||
cal.clear(); | ||
cal.set(fields[YEAR], fields[MONTH], 1); | ||
return cal.get(WEEK_OF_MONTH); | ||
@@ -334,3 +302,5 @@ } | ||
case WEEK_OF_YEAR: | ||
var endOfYear = new GregorianCalendar(fields[YEAR], GregorianCalendar.DECEMBER, 31); | ||
var endOfYear = this.clone(); | ||
endOfYear.clear(); | ||
endOfYear.set(fields[YEAR], GregorianCalendar.DECEMBER, 31); | ||
value = endOfYear.get(WEEK_OF_YEAR); | ||
@@ -343,3 +313,5 @@ if (value === 1) { | ||
case WEEK_OF_MONTH: | ||
var endOfMonth = new GregorianCalendar(fields[YEAR], fields[MONTH], getMonthLength(fields[YEAR], fields[MONTH])); | ||
var endOfMonth = this.clone(); | ||
endOfMonth.clear(); | ||
endOfMonth.set(fields[YEAR], fields[MONTH], getMonthLength(fields[YEAR], fields[MONTH])); | ||
value = endOfMonth.get(WEEK_OF_MONTH); | ||
@@ -1171,2 +1143,3 @@ break; | ||
var gc = this.clone(); | ||
gc.clear(); | ||
gc.setWeekDate(weekYear, 2, this.get(DAY_OF_WEEK)); | ||
@@ -1244,3 +1217,6 @@ return gc.getActualMaximum(WEEK_OF_YEAR); | ||
} | ||
var cal = new GregorianCalendar(this.timezoneOffset, this.locale); | ||
var cal = new GregorianCalendar(this.locale); | ||
cal.setTimezoneOffset(cal.getTimezoneOffset()); | ||
cal.setFirstDayOfWeek(cal.getFirstDayOfWeek()); | ||
cal.setMinimalDaysInFirstWeek(cal.getMinimalDaysInFirstWeek()); | ||
cal.setTime(this.time); | ||
@@ -1247,0 +1223,0 @@ return cal; |
@@ -7,20 +7,6 @@ /** | ||
module.exports = { | ||
// in minutes | ||
timezoneOffset: -8 * 60, | ||
firstDayOfWeek: 0, | ||
minimalDaysInFirstWeek: 1, | ||
// DateFormatSymbols | ||
eras: ['BC', 'AD'], | ||
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', | ||
'August', 'September', 'October', 'November', 'December'], | ||
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', | ||
'Oct', 'Nov', 'Dec'], | ||
weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', | ||
'Saturday'], | ||
shortWeekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | ||
ampms: ['AM', 'PM'], | ||
datePatterns: ['EEEE, MMMM d, yyyy', 'MMMM d, yyyy', 'MMM d, yyyy', 'M/d/yy'], | ||
timePatterns: ['h:mm:ss a \'GMT\'Z', 'h:mm:ss a', 'h:mm:ss a', 'h:mm a'], | ||
dateTimePattern: '{date} {time}' | ||
// in minutes | ||
timezoneOffset: -8 * 60, | ||
firstDayOfWeek: 0, | ||
minimalDaysInFirstWeek: 1 | ||
}; |
@@ -7,22 +7,6 @@ /** | ||
module.exports = { | ||
// in minutes | ||
timezoneOffset: 8 * 60, | ||
firstDayOfWeek: 1, | ||
minimalDaysInFirstWeek: 1, | ||
// DateFormatSymbols | ||
eras: ['公元前', '公元'], | ||
months: ['一月', '二月', '三月', '四月', '五月', '六月', | ||
'七月', '八月', '九月', '十月', '十一月', '十二月'], | ||
shortMonths: ['一月', '二月', '三月', '四月', '五月', '六月', | ||
'七月', '八月', '九月', '十月', '十一月', '十二月'], | ||
weekdays: ['星期天', '星期一', '星期二', '星期三', '星期四', | ||
'星期五', '星期六'], | ||
shortWeekdays: ['周日', '周一', '周二', '周三', '周四', '周五', | ||
'周六'], | ||
ampms: ['上午', '下午'], | ||
/*jshint quotmark: false*/ | ||
datePatterns: ["yyyy'年'M'月'd'日' EEEE", "yyyy'年'M'月'd'日'", "yyyy-M-d", "yy-M-d"], | ||
timePatterns: ["ahh'时'mm'分'ss'秒' 'GMT'Z", "ahh'时'mm'分'ss'秒'", "H:mm:ss", "ah:mm"], | ||
dateTimePattern: '{date} {time}' | ||
// in minutes | ||
timezoneOffset: 8 * 60, | ||
firstDayOfWeek: 1, | ||
minimalDaysInFirstWeek: 1 | ||
}; |
{ | ||
"name": "gregorian-calendar", | ||
"version": "2.0.5", | ||
"version": "3.0.0", | ||
"author": "yiminghe <yiminghe@gmail.com>", | ||
"description": "date time utils like momentjs", | ||
"keywords": [ | ||
"date", | ||
"time", | ||
"momentjs" | ||
], | ||
"engines": { | ||
"node": "~0.11" | ||
"node": ">=0.10" | ||
}, | ||
@@ -14,36 +20,6 @@ "license": "MIT", | ||
"devDependencies": { | ||
"aggregate-bower": "^1.0.2", | ||
"async": "^0.9.0", | ||
"auto-deps": "^1.0.3", | ||
"expect.js": "^0.3.1", | ||
"gulp": "^3.8.7", | ||
"gulp-clean": "^0.3.1", | ||
"gulp-filter": "^1.0.0", | ||
"gulp-footer": "^1.0.5", | ||
"gulp-header": "^1.0.5", | ||
"gulp-jscs": "^1.1.0", | ||
"gulp-jshint": "^1.8.4", | ||
"gulp-kclean": "~0.0.15", | ||
"gulp-modulex": "^1.0.0", | ||
"gulp-rename": "^1.2.0", | ||
"gulp-replace": "^0.4.0", | ||
"gulp-uglify": "^0.3.1", | ||
"gulp-util": "^3.0.0", | ||
"gulp-wrapper": "^0.1.5", | ||
"jshint": "^2.5.5", | ||
"jshint-stylish": "^0.4.0", | ||
"koa": "^0.11.0", | ||
"koa-body": "^0.2.0", | ||
"koa-modularize": "^3.0.3", | ||
"koa-mount": "^1.3.0", | ||
"koa-node-jscover": "^1.1.1", | ||
"koa-serve-index": "^1.0.1", | ||
"koa-static": "^1.4.7", | ||
"mocha": "^1.21.4", | ||
"modulex": "^1.7.4", | ||
"node-jscover": "^0.6.8", | ||
"node-jscover-coveralls": "^1.0.10", | ||
"node-jscover-handler": "^1.0.3", | ||
"precommit-hook": "^1.0.7", | ||
"through2": "^0.6.2" | ||
"rc-server": "^2.0.4", | ||
"rc-tools": "^1.2.6" | ||
}, | ||
@@ -57,12 +33,16 @@ "precommit": [ | ||
"scripts": { | ||
"start": "node --harmony server", | ||
"history": "rc-tools run history", | ||
"start": "node --harmony node_modules/.bin/rc-server", | ||
"publish": "spm publish && rc-tools run tag", | ||
"lint": "rc-tools run lint", | ||
"test": "", | ||
"publish": "spm publish && gulp tag", | ||
"lint": "gulp lint", | ||
"browser-test": "mocha-phantomjs http://localhost:$npm_package_config_port/tests/browser/runner.html", | ||
"browser-test-cover": "mocha-phantomjs -R node_modules/node-jscover/lib/reporters/mocha/console http://localhost:$npm_package_config_port/tests/browser/runner.html?coverage" | ||
"saucelabs": "rc-tools run saucelabs", | ||
"browser-test": "rc-tools run browser-test", | ||
"browser-test-cover": "rc-tools run browser-test-cover" | ||
}, | ||
"spm":{ | ||
"output": ["lib/locale/*.js"] | ||
"spm": { | ||
"output": [ | ||
"lib/locale/*.js" | ||
] | ||
} | ||
} |
277
README.md
@@ -6,2 +6,3 @@ # gregorian-calendar | ||
[![date](https://nodei.co/npm/gregorian-calendar.png)](https://npmjs.org/package/gregorian-calendar) | ||
[![SPM version](http://spmjs.io/badge/gregorian-calendar)](http://spmjs.io/package/gregorian-calendar) | ||
[![NPM downloads](http://img.shields.io/npm/dm/gregorian-calendar.svg)](https://npmjs.org/package/gregorian-calendar) | ||
@@ -11,6 +12,8 @@ [![Build Status](https://secure.travis-ci.org/yiminghe/gregorian-calendar.png?branch=master)](https://travis-ci.org/yiminghe/gregorian-calendar) | ||
[![Dependency Status](https://gemnasium.com/yiminghe/gregorian-calendar.png)](https://gemnasium.com/yiminghe/gregorian-calendar) | ||
[![Bower version](https://badge.fury.io/bo/gregorian-calendar.svg)](http://badge.fury.io/bo/gregorian-calendar) | ||
[![node version](https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square)](http://nodejs.org/download/) | ||
[![Sauce Test Status](https://saucelabs.com/buildstatus/gregorian-calendar)](https://saucelabs.com/u/gregorian-calendar) | ||
[![Sauce Test Status](https://saucelabs.com/browser-matrix/gregorian-calendar.svg)](https://saucelabs.com/u/gregorian-calendar) | ||
## use on node | ||
@@ -23,2 +26,272 @@ | ||
console.log(date.getDayOfWeek()); | ||
``` | ||
``` | ||
## API | ||
### Constructor GregorianCalendar(locale) | ||
* locale: specify suc as timeZoneOffset, firstDayOfWeek, can be require('gregorian-calendar/lib/locale/zh-cn') or require('gregorian-calendar/lib/locale/en-us') | ||
### Enums | ||
```js | ||
SUNDAY: 0, | ||
/** | ||
* Enum indicating monday | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
MONDAY: 1, | ||
/** | ||
* Enum indicating tuesday | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
TUESDAY: 2, | ||
/** | ||
* Enum indicating wednesday | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
WEDNESDAY: 3, | ||
/** | ||
* Enum indicating thursday | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
THURSDAY: 4, | ||
/** | ||
* Enum indicating friday | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
FRIDAY: 5, | ||
/** | ||
* Enum indicating saturday | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
SATURDAY: 6, | ||
/** | ||
* Enum indicating january | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
JANUARY: 0, | ||
/** | ||
* Enum indicating february | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
FEBRUARY: 1, | ||
/** | ||
* Enum indicating march | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
MARCH: 2, | ||
/** | ||
* Enum indicating april | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
APRIL: 3, | ||
/** | ||
* Enum indicating may | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
MAY: 4, | ||
/** | ||
* Enum indicating june | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
JUNE: 5, | ||
/** | ||
* Enum indicating july | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
JULY: 6, | ||
/** | ||
* Enum indicating august | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
AUGUST: 7, | ||
/** | ||
* Enum indicating september | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
SEPTEMBER: 8, | ||
/** | ||
* Enum indicating october | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
OCTOBER: 9, | ||
/** | ||
* Enum indicating november | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
NOVEMBER: 10, | ||
/** | ||
* Enum indicating december | ||
* @type Number | ||
* @member Date.Gregorian | ||
*/ | ||
DECEMBER: 11 | ||
``` | ||
### GregorianCalendar.prototype.setTime(time: Number) | ||
set absolute time for current instance | ||
### Number GregorianCalendar.prototype.getTime() | ||
get absolute time for current instance | ||
### GregorianCalendar.prototype.setTimezoneOffset(timezoneOffset: Number) | ||
set current date instance's timezone offset (in minutes) | ||
### Number GregorianCalendar.prototype.getTimezoneOffset() | ||
get current date instance's timezone offset (in minutes) | ||
### GregorianCalendar.prototype.setYear(year: Number) | ||
set the year of the given calendar field. | ||
### Number GregorianCalendar.prototype.getYear() | ||
Returns the year of the given calendar field. | ||
### GregorianCalendar.prototype.setMonth(month: Number) | ||
set the month of the given calendar field. January is 0, you can use enum | ||
### Number GregorianCalendar.prototype.getMonth() | ||
Returns the month of the given calendar field. | ||
### GregorianCalendar.prototype.setDayOfMonth(day: Number) | ||
set the day of month of the given calendar field. | ||
### Number GregorianCalendar.prototype.getDayOfMonth() | ||
Returns the day of month of the given calendar field. | ||
### GregorianCalendar.prototype.setHourOfDay(hour: Number) | ||
set the hour of day for the given calendar field. | ||
### Number GregorianCalendar.prototype.getHourOfDay() | ||
Returns the hour of day for the given calendar field. | ||
### GregorianCalendar.prototype.setMinute(minute: Number) | ||
set the minute of the given calendar field. | ||
### Number GregorianCalendar.prototype.getMinute() | ||
Returns the minute of the given calendar field. | ||
### GregorianCalendar.prototype.setSecond(second: Number) | ||
set the second of the given calendar field. | ||
### Number GregorianCalendar.prototype.getSecond() | ||
Returns the second of the given calendar field. | ||
### GregorianCalendar.prototype.setMilliSecond(second: Number) | ||
set the millisecond of the given calendar field. | ||
### Number GregorianCalendar.prototype.getMilliSecond() | ||
Returns the millisecond of the given calendar field. | ||
### Number GregorianCalendar.prototype.getWeekOfYear() | ||
Returns the week of year of the given calendar field. | ||
### Number GregorianCalendar.prototype.getWeekOfMonth() | ||
Returns the week of month of the given calendar field. | ||
### Number GregorianCalendar.prototype.getDayOfYear() | ||
Returns the day of year of the given calendar field. | ||
### Number GregorianCalendar.prototype.getDayOfWeek() | ||
Returns the day of week of the given calendar field. sunday is 0, monday is 1 | ||
### Number GregorianCalendar.prototype.getDayOfWeekInMonth() | ||
Returns the day of week in month of the given calendar field. | ||
### GregorianCalendar.prototype.addYear(amount: Number) | ||
add the year of the given calendar field. | ||
### GregorianCalendar.prototype.addMonth(amount: Number) | ||
add the month of the given calendar field. | ||
### GregorianCalendar.prototype.addDayOfMonth(amount: Number) | ||
add the day of month of the given calendar field. | ||
### GregorianCalendar.prototype.addHourOfDay(amount: Number) | ||
add the hour of day of the given calendar field. | ||
### GregorianCalendar.prototype.addMinute(amount: Number) | ||
add the minute of the given calendar field. | ||
### GregorianCalendar.prototype.addSecond(amount: Number) | ||
add the second of the given calendar field. | ||
### GregorianCalendar.prototype.addMilliSecond(amount: Number) | ||
add the millisecond of the given calendar field. | ||
### Number GregorianCalendar.prototype.getWeekYear() | ||
Returns the week number of year represented by this GregorianCalendar. | ||
### GregorianCalendar.prototype.setWeekDate(weekYear: Number, weekOfYear: Number, dayOfWeek: Number) | ||
Sets this GregorianCalendar to the date given by the date specifiers - weekYear, | ||
weekOfYear, and dayOfWeek. weekOfYear follows the WEEK_OF_YEAR numbering. | ||
The dayOfWeek value must be one of the DAY_OF_WEEK values: SUNDAY to SATURDAY. | ||
* weekYear: the week year | ||
* weekOfYear: the week number based on weekYear | ||
* dayOfWeek: the day of week value | ||
### Number GregorianCalendar.prototype.getWeeksInWeekYear() | ||
Returns the number of weeks in the week year | ||
### GregorianCalendar GregorianCalendar.prototype.clone() | ||
Returns a clone of current instance | ||
### boolean GregorianCalendar.prototype.equals(other: GregorianCalendar) | ||
### GregorianCalendar.prototype.clear() | ||
clear all field of current instance |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4
295
0
0
67293
18
1662