-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ab5fc3
commit 49c0abd
Showing
15 changed files
with
174 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 返回前几季度或后几季度的日期 | ||
* @param date 字符串/日期/时间戳 | ||
* @param offset 季度偏移量(默认0)、前几个季度、后几个季度 | ||
*/ | ||
export declare function getWhatQuarter(date: string | Date | number, offset: number): Date; | ||
|
||
/** | ||
* 返回前几季度或后几季度的日期,可以指定月初(first)、月末(last)、天数,默认当前 | ||
* @param date 字符串/日期/时间戳 | ||
* @param offset 季度偏移量(默认当前季度)、前几个季度、后几个季度 | ||
* @param day 获取哪天:月初(first)、月末(last)、指定天数(数值) | ||
*/ | ||
export declare function getWhatQuarter(date: string | Date | number, offset: number, day: number | 'first' | 'last'): Date; | ||
|
||
declare module './ctor' { | ||
interface XEUtilsMethods { | ||
getWhatQuarter: typeof getWhatQuarter; | ||
} | ||
} | ||
|
||
export default getWhatQuarter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var getWhatMonth = require('./getWhatMonth') | ||
|
||
var toStringDate = require('./toStringDate') | ||
|
||
var isValidDate = require('./isValidDate') | ||
|
||
function getQuarterNumber (date) { | ||
var month = date.getMonth() | ||
if (month < 3) { | ||
return 1 | ||
} else if (month < 6) { | ||
return 2 | ||
} else if (month < 9) { | ||
return 3 | ||
} | ||
return 4 | ||
} | ||
|
||
/** | ||
* 返回前几季度或后几季度的日期 | ||
* | ||
* @param {Date} date 日期 | ||
* @param {Number} offset 季度(默认当前季度)、前几季度、后几季度 | ||
* @param {Number} day 获取哪天:月初(first)、月末(last)、指定天数(数值),如果为空,但超过指定月份的天数时,则默认单月最后一天 | ||
* @return {Date} | ||
*/ | ||
function getWhatQuarter (date, offset, day) { | ||
var currMonth, monthOffset = offset && !isNaN(offset) ? offset * 3 : 0 | ||
date = toStringDate(date) | ||
if (isValidDate(date)) { | ||
currMonth = (getQuarterNumber(date) - 1) * 3 | ||
date.setMonth(currMonth) | ||
return getWhatMonth(date, monthOffset, day) | ||
} | ||
return date | ||
} | ||
|
||
module.exports = getWhatQuarter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters