moment-fquarter
Advanced tools
Comparing version 0.1.0 to 1.0.0
{ | ||
"name": "moment-fquarter", | ||
"main": "moment-fquarter.js", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/robgallen/moment-fquarter", | ||
@@ -6,0 +6,0 @@ "authors": [ |
// moment-fquarter.js | ||
// version : 0.4 | ||
// version : 1.0 | ||
// author : Rob Allen | ||
@@ -11,7 +11,11 @@ // license : MIT | ||
moment.fn.fquarter = function (startMonth) { | ||
startMonth = startMonth || 4; // default is April | ||
var thisDate = this.clone(); | ||
var initial = thisDate.local()._quarter || "Q"; | ||
var result = {}, adjustedDate, nextYear = null; | ||
startMonth = startMonth || 4; // default is April | ||
var originalDate = this.clone(); | ||
var result = {}; | ||
var adjustedDate = thisDate; | ||
var nextYear = null; | ||
var fiscalCalendarIndex = buildFiscalCalendar(startMonth).indexOf(this.month()); | ||
var monthsIntoQuarter = fiscalCalendarIndex % 3; | ||
var startOfQuarter = this.clone().startOf("month").subtract(monthsIntoQuarter, "months"); | ||
@@ -21,10 +25,7 @@ if (startMonth > 1) { | ||
nextYear = adjustedDate.clone().add(1, "years"); | ||
} else { | ||
adjustedDate = thisDate; | ||
} | ||
if (startMonth < 0) { | ||
adjustedDate = thisDate.subtract(12 + startMonth, "month").add(1, "year"); | ||
nextYear = adjustedDate.clone().add(1, "year"); | ||
} else { | ||
adjustedDate = thisDate; | ||
} | ||
@@ -35,4 +36,4 @@ | ||
result.nextYear = (nextYear) ? nextYear.year() : nextYear; | ||
result.start = originalDate.set("date", 1).subtract((originalDate.month()+12)%3, "months").format("YYYY-MM-DD"); | ||
result.end = originalDate.set("date", 1).subtract((originalDate.month()+12)%3, "months").add(3, "months").subtract(1, "day").format("YYYY-MM-DD"); | ||
result.start = startOfQuarter.format("YYYY-MM-DD"); | ||
result.end = startOfQuarter.add(3, "months").subtract(1, 'day').format("YYYY-MM-DD"); | ||
@@ -50,2 +51,19 @@ result.toString = function () { | ||
function buildFiscalCalendar(startMonth) { | ||
if (startMonth < 0) { | ||
startMonth = 13 + startMonth; | ||
} | ||
startMonth--; | ||
var months = []; | ||
for (var i = 0; i < 12; i++) { | ||
months.push(startMonth); | ||
startMonth++; | ||
if (startMonth > 11) startMonth = 0; | ||
} | ||
return months; | ||
} | ||
if (typeof define === "function" && define.amd) { | ||
@@ -52,0 +70,0 @@ define("moment-fquarter", ["moment"], onload); |
@@ -1,1 +0,1 @@ | ||
(function(){function n(n){return n.fn.fquarter=function(n){var u=this.lang()._quarter||"Q",t={},r,i=null;return n=n||4,n>1?(r=this.subtract("months",n-1),i=r.clone().add("years",1)):r=this,t.quarter=Math.ceil((r.month()+1)/3),t.year=r.year(),t.nextYear=i?i.year():i,t.toString=function(){var n=u+t.quarter+" "+t.year;return i?n+"/"+i.format("YY"):n},t},n}typeof define=="function"&&define.amd?define("moment-fquarter",["moment"],n):typeof module!="undefined"?module.exports=n(require("moment")):typeof window!="undefined"&&window.moment&&n(window.moment)}).apply(this); | ||
(function(){function t(t){return t.fn.fquarter=function(t){t=t||4;var n=this.clone(),r=n.local()._quarter||"Q",o={},a=n,u=null,d=e(t).indexOf(this.month()),f=d%3,m=this.clone().startOf("month").subtract(f,"months");return t>1&&(a=n.subtract(t-1,"months"),u=a.clone().add(1,"years")),0>t&&(a=n.subtract(12+t,"month").add(1,"year"),u=a.clone().add(1,"year")),o.quarter=Math.ceil((a.month()+1)/3),o.year=a.year(),o.nextYear=u?u.year():u,o.start=m.format("YYYY-MM-DD"),o.end=m.add(3,"months").subtract(1,"day").format("YYYY-MM-DD"),o.toString=function(){var t=r+o.quarter+" "+o.year;return u?t+"/"+u.format("YY"):t},o},t}function e(t){0>t&&(t=13+t),t--;for(var e=[],n=0;12>n;n++)e.push(t),t++,t>11&&(t=0);return e}"function"==typeof define&&define.amd?define("moment-fquarter",["moment"],t):"undefined"!=typeof module?module.exports=t(require("moment")):"undefined"!=typeof window&&window.moment&&t(window.moment)}).apply(this); |
{ | ||
"name": "moment-fquarter", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Fiscal quarterly formatting for momentjs", | ||
@@ -13,20 +13,11 @@ "author": "Rob Allen", | ||
"scripts": { | ||
"postinstall": "./node_modules/.bin/bower install", | ||
"test": "./node_modules/.bin/grunt test" | ||
"test": "mocha --reporter progress \"moment-fquarter.test.js\"" | ||
}, | ||
"main": "moment-fquarter.js", | ||
"devDependencies": { | ||
"bower": "^1.3.12", | ||
"grunt": "^0.4.4", | ||
"grunt-cli": "^0.1.13", | ||
"grunt-contrib-coffee": "^0.10.1", | ||
"grunt-contrib-uglify": "^0.4.0", | ||
"grunt-karma": "^0.8.2", | ||
"karma": "^0.12.1", | ||
"karma-chrome-launcher": "^0.1.2", | ||
"karma-jasmine": "^0.1.5", | ||
"karma-opera-launcher": "^0.1.0", | ||
"karma-phantomjs-launcher": "^0.1.2" | ||
"chai": "3.5.0", | ||
"mocha": "3.2.0", | ||
"moment": "~2.17.1" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -0,0 +0,0 @@ # moment-fquarter.js |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3
424
2
0
19701
11
1