Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

quarterOfYear

Determine the quarter of the year.

Usage

var quarterOfYear = require( '@stdlib/time/quarter-of-year' );

quarterOfYear( [month] )

Returns the quarter of the year.

var q = quarterOfYear();
// returns <number>

By default, the function returns the quarter of the year for the current month in the current year (according to local time). To determine the quarter for a particular month, provide either a month or a Date object.

var q = quarterOfYear( new Date() );
// returns <number>

q = quarterOfYear( 4 );
// returns 2

A month may be either a month's integer value, three letter abbreviation, or full name (case insensitive).

var q = quarterOfYear( 4 );
// returns 2

q = quarterOfYear( 'April' );
// returns 2

q = quarterOfYear( 'apr' );
// returns 2

Notes

  • The function's return value is a generalization and does not take into account inaccuracies due to daylight savings conventions, crossing timezones, or other complications with time and dates.

Examples

var quarterOfYear = require( '@stdlib/time/quarter-of-year' );

var months;
var q;
var i;

months = [
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December'
];

for ( i = 0; i < months.length; i++ ) {
    q = quarterOfYear( months[ i ] );
    console.log( 'The month of %s is in Q%d.', months[ i ], q );
}

CLI

Usage

Usage: quarter-of-year [options] [month]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.

Examples

$ quarter-of-year
<number>

For a specific month,

$ quarter-of-year 4
2

See Also