@naturalcycles/time-lib
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -0,1 +1,8 @@ | ||
# [1.4.0](https://github.com/NaturalCycles/time-lib/compare/v1.3.0...v1.4.0) (2019-07-12) | ||
### Features | ||
* .isoWeekday setter ([d6367e0](https://github.com/NaturalCycles/time-lib/commit/d6367e0)) | ||
# [1.3.0](https://github.com/NaturalCycles/time-lib/compare/v1.2.1...v1.3.0) (2019-07-09) | ||
@@ -2,0 +9,0 @@ |
@@ -11,4 +11,8 @@ import { PluginFunc } from 'dayjs'; | ||
isoWeekday(): number; | ||
/** | ||
* Set date to NEXT date that satisfies the weekday. | ||
*/ | ||
isoWeekday(setWeekday: number): this; | ||
} | ||
} | ||
export declare const isoWeekdayPlugin: PluginFunc; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isoWeekdayPlugin = (_opt, dayjsClass) => { | ||
dayjsClass.prototype.isoWeekday = function () { | ||
dayjsClass.prototype.isoWeekday = function (setWeekday) { | ||
const { $W } = this; | ||
return $W <= 0 ? $W + 7 : $W; | ||
const weekday = $W <= 0 ? $W + 7 : $W; | ||
if (setWeekday) { | ||
let diff = setWeekday - weekday; | ||
if (diff < 0) | ||
diff += 7; | ||
return this.add(diff, 'day'); | ||
} | ||
return weekday; | ||
}; | ||
}; | ||
//# sourceMappingURL=isoWeekday.js.map |
@@ -34,3 +34,3 @@ { | ||
}, | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Date/time related API, based on DayJS", | ||
@@ -37,0 +37,0 @@ "keywords": [ |
@@ -12,2 +12,7 @@ import { Dayjs, PluginFunc } from 'dayjs' | ||
isoWeekday (): number | ||
/** | ||
* Set date to NEXT date that satisfies the weekday. | ||
*/ | ||
isoWeekday (setWeekday: number): this | ||
} | ||
@@ -17,6 +22,15 @@ } | ||
export const isoWeekdayPlugin: PluginFunc = (_opt, dayjsClass) => { | ||
dayjsClass.prototype.isoWeekday = function (this: Dayjs) { | ||
dayjsClass.prototype.isoWeekday = function (this: Dayjs, setWeekday?: number) { | ||
const { $W } = this as any | ||
return $W <= 0 ? $W + 7 : $W | ||
const weekday = $W <= 0 ? $W + 7 : $W | ||
if (setWeekday) { | ||
let diff = setWeekday - weekday | ||
if (diff < 0) diff += 7 | ||
return this.add(diff, 'day') | ||
} | ||
return weekday | ||
} | ||
} |
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
16048
305