Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

moment-fquarter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-fquarter

Fiscal quarterly formatting for momentjs

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
8.8K
decreased by-12.88%
Maintainers
1
Weekly downloads
 
Created
Source

moment-fquarter.js

This plugin provides fiscal quarterly formatting for moment objects.

How to use?

Call the fquarter method on any moment object. It returns an object by default and can also return a string.

moment("2013-04-01").fquarter();
// {quarter:1, year:2013, nextYear:2014}
moment("2013-04-01").fquarter().toString();
// Q1 2013/14
moment("2013-01-01").fquarter();
// {quarter:4, year:2012, nextYear:2013}
moment("2013-01-01").fquarter().toString();
// Q4 2012/13

The default fiscal year starting month is April. You can optionally pass in the start month, for example 1 (January) for normal calendar quarters, 7 or 9 (July or September) for academic quarters.

moment("2013-09-01").fquarter(9);
// {quarter:1, year:2013, nextYear:2014}
moment("2013-09-01").fquarter(9).toString();
// Q1 2013/14
moment("2013-01-01").fquarter(9);
// {quarter:2, year:2012, nextYear:2013}
moment("2013-01-01").fquarter(9).toString();
// Q2 2012/13

If you use 1 as a starting month, you do not get the additional year as all the quarters fit within the single calendar year.

moment("2013-01-01").fquarter(1);
// {quarter:1, year:2013, nextYear:null}
moment("2013-01-01").fquarter(1).toString();
// Q1 2013
moment("2013-09-01").fquarter(1);
// {quarter:3, year:2013, nextYear:null}
moment("2013-09-01").fquarter(1).toString();
// Q3 2013

Backwards fiscal year

Some countries begin their fiscal quarters in the previous year, e.g. US Federal govt. where October 2013 is Q1 2014. You can now use a negative starting month to reflect this.

moment("2013-01-01").fquarter(-3);
// {quarter:2, year:2013, nextYear:2014}
moment("2013-01-01").fquarter(-3).toString();
// Q2 2013/14
moment("2013-10-01").fquarter(-3);
// {quarter:1, year:2014, nextYear:2015}
moment("2013-10-01").fquarter(-3).toString();
// Q1 2014/15

Changing the quarter initial

week: {
	dow: 1, // Monday is the first day of the week.
	doy: 4  // The week that contains Jan 4th is the first week of the year.
},
quarter: "XYZ"

FAQs

Package last updated on 01 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc