dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19687
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8691: Reverting periodType.js after r8688
------------------------------------------------------------
revno: 8691
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-10-24 14:52:17 +0200
message:
Reverting periodType.js after r8688
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js 2012-10-24 10:45:58 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js 2012-10-24 12:52:17 +0000
@@ -1,406 +1,368 @@
-// generatePeriods config object: { boolean offset, boolean filterFuturePeriods, boolean reversePeriods }
-
function PeriodType()
-{
- var monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
- 'July', 'August', 'September', 'October', 'November', 'December'],
-
- format_yyyymmdd = function(date) {
- var y = date.getFullYear(),
- m = new String(date.getMonth() + 1),
- d = new String(date.getDate());
- m = m.length < 2 ? '0' + m : m;
- d = d.length < 2 ? '0' + d : d;
- return y + '-' + m + '-' + d;
- },
-
- filterFuturePeriods = function( periods ) {
- var array = [],
- now = new Date();
-
- for ( var i = 0; i < periods.length; i++ )
- {
- if ( new Date( periods[i]['startDate'] ) <= now )
- {
- array.push(periods[i]);
- }
- }
-
- return array;
- };
+{
+ var dateFormat = 'yyyy-MM-dd';
var periodTypes = [];
- periodTypes['Daily'] = new DailyPeriodType( format_yyyymmdd, filterFuturePeriods );
- periodTypes['Weekly'] = new WeeklyPeriodType( format_yyyymmdd, filterFuturePeriods );
- periodTypes['Monthly'] = new MonthlyPeriodType( format_yyyymmdd, monthNames, filterFuturePeriods );
- periodTypes['BiMonthly'] = new BiMonthlyPeriodType( format_yyyymmdd, monthNames, filterFuturePeriods );
- periodTypes['Quarterly'] = new QuarterlyPeriodType( format_yyyymmdd, monthNames, filterFuturePeriods );
- periodTypes['SixMonthly'] = new SixMonthlyPeriodType( monthNames, filterFuturePeriods );
- periodTypes['Yearly'] = new YearlyPeriodType( format_yyyymmdd, filterFuturePeriods );
- periodTypes['FinancialOct'] = new FinancialOctoberPeriodType( format_yyyymmdd, monthNames, filterFuturePeriods );
- periodTypes['FinancialJuly'] = new FinancialJulyPeriodType( format_yyyymmdd, monthNames, filterFuturePeriods );
- periodTypes['FinancialApril'] = new FinancialAprilPeriodType( format_yyyymmdd, monthNames, filterFuturePeriods );
+ periodTypes['Daily'] = new DailyPeriodType( dateFormat );
+ periodTypes['Weekly'] = new WeeklyPeriodType( dateFormat );
+ periodTypes['Monthly'] = new MonthlyPeriodType( dateFormat );
+ periodTypes['BiMonthly'] = new BiMonthlyPeriodType( dateFormat );
+ periodTypes['Quarterly'] = new QuarterlyPeriodType( dateFormat );
+ periodTypes['SixMonthly'] = new SixMonthlyPeriodType( dateFormat );
+ periodTypes['Yearly'] = new YearlyPeriodType( dateFormat );
+ periodTypes['FinancialOct'] = new FinancialOctoberPeriodType( dateFormat );
+ periodTypes['FinancialJuly'] = new FinancialJulyPeriodType( dateFormat );
+ periodTypes['FinancialApril'] = new FinancialAprilPeriodType( dateFormat );
this.get = function( key )
{
return periodTypes[key];
};
-}
-
-function DailyPeriodType( format_yyyymmdd, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset;
- date = new Date( '01 Jan ' + year );
-
- while ( date.getFullYear() === year )
- {
- var period = {};
- period['startDate'] = format_yyyymmdd( date );
- period['endDate'] = period['startDate'];
- period['name'] = period['startDate'];
- //period['id'] = 'Daily_' + period['startDate'];
- period['iso'] = period['startDate'].replace( /-/g, '' );
- period['id'] = period['iso'];
- periods.push( period );
- date.setDate( date.getDate() + 1 );
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods.reverse() : periods;
-
- return periods;
- };
-}
-
-function WeeklyPeriodType( format_yyyymmdd, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '01 Jan ' + year ),
- day = date.getDay(),
- week = 1;
-
- if ( day <= 4 )
- {
- date.setDate( date.getDate() - ( day - 1 ) );
- }
- else
- {
- date.setDate( date.getDate() + ( 8 - day ) );
- }
-
- while ( date.getFullYear() <= year )
- {
- var period = {};
- period['startDate'] = format_yyyymmdd( date );
- //period['id'] = 'Weekly_' + period['startDate'];
- period['iso'] = year + 'W' + week;
- period['id'] = period['iso'];
- date.setDate( date.getDate() + 6 );
- period['endDate'] = format_yyyymmdd( date );
- period['name'] = 'W' + week + ' - ' + period['startDate'] + ' - ' + period['endDate'];
- periods.push( period );
- date.setDate( date.getDate() + 1 );
- week++;
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods.reverse() : periods;
-
- return periods;
- };
-}
-
-function MonthlyPeriodType( format_yyyymmdd, monthNames, fnFilter )
-{
- var format_iso = function(date) {
- var y = date.getFullYear(),
- m = new String(date.getMonth() + 1);
- m = m.length < 2 ? '0' + m : m;
- return y + m;
- };
-
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '31 Dec ' + year );
-
- while ( date.getFullYear() === year )
- {
- var period = {};
- period['endDate'] = format_yyyymmdd( date );
- date.setDate( 1 );
- period['startDate'] = format_yyyymmdd( date );
- period['name'] = monthNames[date.getMonth()] + ' ' + date.getFullYear();
- //period['id'] = 'Monthly_' + period['startDate'];
- period['iso'] = format_iso( date );
- period['id'] = period['iso'];
- periods.push( period );
- date.setDate( 0 );
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods : periods.reverse();
- // Months are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
-
- return periods;
- };
-}
-
-function BiMonthlyPeriodType( format_yyyymmdd, monthNames, fnFilter )
-{
- var format_iso = function( date ) {
- var y = date.getFullYear(),
- m = new String(date.getMonth() + 1);
- m = m.length < 2 ? '0' + m : m;
- return y + m + 'B';
- };
-
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '31 Dec ' + year );
-
- while ( date.getFullYear() === year )
- {
- var period = {};
- period['endDate'] = format_yyyymmdd( date );
- date.setDate( 0 );
- date.setDate( 1 );
- period['startDate'] = format_yyyymmdd( date );
- period['name'] = monthNames[date.getMonth()] + ' - ' + monthNames[date.getMonth() + 1] + ' ' + date.getFullYear();
- //period['id'] = 'BiMonthly_' + period['startDate'];
- period['iso'] = format_iso( date );
- period['id'] = period['iso'];
- periods.push(period);
- date.setDate( 0 );
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods : periods.reverse();
- // Bi-months are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
-
- return periods;
- };
-}
-
-function QuarterlyPeriodType( format_yyyymmdd, monthNames, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '31 Dec ' + year ),
- quarter = 4;
-
- while ( date.getFullYear() === year )
- {
- var period = {};
- period['endDate'] = format_yyyymmdd( date );
- date.setDate( 0 );
- date.setDate( 0 );
- date.setDate( 1 );
- period['startDate'] = format_yyyymmdd( date );
- period['name'] = monthNames[date.getMonth()] + ' - ' + monthNames[date.getMonth() + 2] + ' ' + date.getFullYear();
- //period['id'] = 'Quarterly_' + period['startDate'];
- period['iso'] = year + 'Q' + quarter;
- period['id'] = period['iso'];
- periods.push(period);
- date.setDate( 0 );
- quarter--;
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods : periods.reverse();
- // Quarters are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
-
- return periods;
- };
-}
-
-function SixMonthlyPeriodType( monthNames, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset;
-
- var period = {};
+
+ this.reverse = function( array )
+ {
+ var reversed = [];
+ var i = 0;
+
+ for ( var j = array.length - 1; j >= 0; j-- )
+ {
+ reversed[i++] = array[j];
+ }
+
+ return reversed;
+ };
+
+ this.filterFuturePeriods = function( periods )
+ {
+ var array = [];
+ var i = 0;
+
+ var now = new Date().getTime();
+
+ for ( var j = 0; j < periods.length; j++ )
+ {
+ if ( $.date( periods[j]['endDate'], dateFormat ).date().getTime() <= now )
+ {
+ array[i++] = periods[j];
+ }
+ }
+
+ return array;
+ };
+
+ this.filterFuturePeriodsExceptCurrent = function( periods )
+ {
+ var array = [];
+ var i = 0;
+
+ var now = new Date().getTime();
+
+ for ( var j = 0; j < periods.length; j++ )
+ {
+ if ( $.date( periods[j]['startDate'], dateFormat ).date().getTime() <= now )
+ {
+ array[i++] = periods[j];
+ }
+ }
+
+ return array;
+ };
+}
+
+function DailyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-01-01', dateFormat );
+ var i = 0;
+
+ while ( startDate.date().getFullYear() <= year )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = startDate.format( dateFormat );
+ period['name'] = startDate.format( dateFormat );
+ period['id'] = 'Daily_' + period['startDate'];
+ period['iso'] = startDate.format( 'yyyyMMdd' );
+ periods[i] = period;
+
+ startDate.adjust( 'D', +1 );
+ i++;
+ }
+
+ return periods;
+ };
+}
+
+function WeeklyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-01-01', dateFormat );
+ var day = startDate.date().getDay();
+ var i = 0;
+
+ if ( day == 0 ) // Sunday, forward to Monday
+ {
+ startDate.adjust( 'D', +1 );
+ }
+ else if ( day <= 4 ) // Monday - Thursday, rewind to Monday
+ {
+ startDate.adjust( 'D', ( ( day - 1 ) * -1 ) );
+ }
+ else
+ // Friday - Saturday, forward to Monday
+ {
+ startDate.adjust( 'D', ( 8 - day ) );
+ }
+
+ var endDate = startDate.clone().adjust( 'D', +6 );
+
+ while ( startDate.date().getFullYear() <= year )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = 'W' + ( i + 1 ) + ' - ' + startDate.format( dateFormat ) + " - " + endDate.format( dateFormat );
+ period['id'] = 'Weekly_' + period['startDate'];
+ period['iso'] = year + 'W' + ( i + 1 );
+ periods[i] = period;
+
+ startDate.adjust( 'D', +7 );
+ endDate = startDate.clone().adjust( 'D', +6 );
+ i++;
+ }
+
+ return periods;
+ };
+}
+
+function MonthlyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-01-01', dateFormat );
+ var endDate = startDate.clone().adjust( 'M', +1 ).adjust( 'D', -1 );
+ var i = 0;
+
+ while ( startDate.date().getFullYear() == year )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = monthNames[i] + ' ' + year;
+ period['id'] = 'Monthly_' + period['startDate'];
+ period['iso'] = startDate.format( 'yyyyMM' );
+ periods[i] = period;
+
+ startDate.adjust( 'M', +1 );
+ endDate = startDate.clone().adjust( 'M', +1 ).adjust( 'D', -1 );
+ i++;
+ }
+
+ return periods;
+ };
+}
+
+function BiMonthlyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-01-01', dateFormat );
+ var endDate = startDate.clone().adjust( 'M', +2 ).adjust( 'D', -1 );
+ var i = 0;
+ var j = 0;
+
+ while ( startDate.date().getFullYear() == year )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = monthNames[i] + ' - ' + monthNames[i + 1] + ' ' + year;
+ period['id'] = 'BiMonthly_' + period['startDate'];
+ period['iso'] = startDate.format( 'yyyyMM' ) + 'B';
+ periods[j] = period;
+
+ startDate.adjust( 'M', +2 );
+ endDate = startDate.clone().adjust( 'M', +2 ).adjust( 'D', -1 );
+ i += 2;
+ j++;
+ }
+
+ return periods;
+ };
+}
+
+function QuarterlyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-01-01', dateFormat );
+ var endDate = startDate.clone().adjust( 'M', +3 ).adjust( 'D', -1 );
+ var i = 0;
+ var j = 0;
+
+ while ( startDate.date().getFullYear() == year )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = monthNames[i] + ' - ' + monthNames[i + 2] + ' ' + year;
+ period['id'] = 'Quarterly_' + period['startDate'];
+ period['iso'] = year + 'Q' + ( j + 1 );
+ periods[j] = period;
+
+ startDate.adjust( 'M', +3 );
+ endDate = startDate.clone().adjust( 'M', +3 ).adjust( 'D', -1 );
+ i += 3;
+ j++;
+ }
+
+ return periods;
+ };
+}
+
+function SixMonthlyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+
+ var period = [];
period['startDate'] = year + '-01-01';
period['endDate'] = year + '-06-30';
period['name'] = monthNames[0] + ' - ' + monthNames[5] + ' ' + year;
- //period['id'] = 'SixMonthly_' + period['startDate'];
+ period['id'] = 'SixMonthly_' + period['startDate'];
period['iso'] = year + 'S1';
- period['id'] = period['iso'];
- periods.push(period);
-
- period = {};
+ periods[0] = period;
+
+ period = [];
period['startDate'] = year + '-07-01';
period['endDate'] = year + '-12-31';
period['name'] = monthNames[6] + ' - ' + monthNames[11] + ' ' + year;
- //period['id'] = 'SixMonthly_' + period['startDate'];
+ period['id'] = 'SixMonthly_' + period['startDate'];
period['iso'] = year + 'S2';
- period['id'] = period['iso'];
- periods.push(period);
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods.reverse() : periods;
-
- return periods;
- };
-}
-
-function YearlyPeriodType( format_yyyymmdd, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '31 Dec ' + year );
-
- while ( ( year - date.getFullYear() ) < 10 )
- {
- var period = {};
- period['endDate'] = format_yyyymmdd( date );
- date.setMonth( 0, 1 );
- period['startDate'] = format_yyyymmdd( date );
- period['name'] = date.getFullYear().toString();
- //period['id'] = 'Yearly_' + period['startDate'];
- period['iso'] = date.getFullYear().toString();
- period['id'] = period['iso'].toString();
- periods.push(period);
- date.setDate(0);
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods : periods.reverse();
- // Years are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
-
- return periods;
- };
-}
-
-function FinancialOctoberPeriodType( format_yyyymmdd, monthNames, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '30 Sep ' + ( year + 1 ) );
-
- for ( var i = 0; i < 10; i++ )
- {
- var period = {};
- period['endDate'] = format_yyyymmdd( date );
- date.setYear( date.getFullYear() - 1 );
- date.setDate( date.getDate() + 1 );
- period['startDate'] = format_yyyymmdd( date );
- period['name'] = monthNames[9] + ' ' + date.getFullYear() + ' - ' + monthNames[8] + ' ' + ( date.getFullYear() + 1 );
- period['id'] = 'FinancialOct_' + period['startDate'];
- periods.push( period );
- date.setDate( date.getDate() - 1 );
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods : periods.reverse();
- // FinancialOctober periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
-
- return periods;
- };
-}
-
-function FinancialJulyPeriodType( format_yyyymmdd, monthNames, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '30 Jun ' + ( year + 1 ) );
-
- for ( var i = 0; i < 10; i++ )
- {
- var period = {};
- period['endDate'] = format_yyyymmdd( date );
- date.setYear( date.getFullYear() - 1 );
- date.setDate( date.getDate() + 1 );
- period['startDate'] = format_yyyymmdd( date );
- period['name'] = monthNames[6] + ' ' + date.getFullYear() + ' - ' + monthNames[5] + ' ' + ( date.getFullYear() + 1 );
- period['id'] = 'FinancialJuly_' + period['startDate'];
- periods.push( period );
- date.setDate( date.getDate() - 1 );
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods : periods.reverse();
- // FinancialJuly periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
-
- return periods;
- };
-}
-
-function FinancialAprilPeriodType( format_yyyymmdd, monthNames, fnFilter )
-{
- this.generatePeriods = function( config )
- {
- var periods = [],
- offset = parseInt(config.offset),
- isFilter = config.filterFuturePeriods,
- isReverse = config.reversePeriods,
- year = new Date().getFullYear() + offset,
- date = new Date( '31 Mar ' + ( year + 1 ) );
-
- for ( var i = 0; i < 10; i++ )
- {
- var period = {};
- period['endDate'] = format_yyyymmdd( date );
- date.setYear( date.getFullYear() - 1 );
- date.setDate( date.getDate() + 1 );
- period['startDate'] = format_yyyymmdd( date );
- period['name'] = monthNames[3] + ' ' + date.getFullYear() + ' - ' + monthNames[2] + ' ' + ( date.getFullYear() + 1 );
- period['id'] = 'FinancialApril_' + period['startDate'];
- periods.push( period );
- date.setDate( date.getDate() - 1 );
- }
-
- periods = isFilter ? fnFilter( periods ) : periods;
- periods = isReverse ? periods : periods.reverse();
- // FinancialApril periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
-
- return periods;
- };
-}
-
+ periods[1] = period;
+
+ return periods;
+ };
+}
+
+function YearlyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-01-01', dateFormat ).adjust( 'Y', -5 );
+ var endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+
+ for ( var i = 0; i < 11; i++ )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = startDate.date().getFullYear();
+ period['id'] = 'Yearly_' + period['startDate'];
+ period['iso'] = year;
+ periods[i] = period;
+
+ startDate.adjust( 'Y', +1 );
+ endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+ }
+
+ return periods;
+ };
+}
+
+function FinancialOctoberPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-10-01', dateFormat ).adjust( 'Y', -5 );
+ var endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+
+ for ( var i = 0; i < 11; i++ )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = monthNames[9] + ' ' + startDate.date().getFullYear() + '-' + monthNames[8] + ' ' + (startDate.date().getFullYear() +1 );
+ period['id'] = 'FinancialOct_' + period['startDate'];
+ period['iso'] = year + 'Oct';
+ periods[i] = period;
+
+ startDate.adjust( 'Y', +1 );
+ endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+ }
+
+ return periods;
+ };
+}
+
+function FinancialJulyPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-07-01', dateFormat ).adjust( 'Y', -5 );
+ var endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+
+ for ( var i = 0; i < 11; i++ )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = monthNames[6] + ' ' + startDate.date().getFullYear() + '-' + monthNames[5] + ' ' + (startDate.date().getFullYear() +1 );
+ period['id'] = 'FinancialJuly_' + period['startDate'];
+ period['iso'] = year + 'July';
+ periods[i] = period;
+
+ startDate.adjust( 'Y', +1 );
+ endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+ }
+
+ return periods;
+ };
+}
+
+function FinancialAprilPeriodType( dateFormat )
+{
+ this.generatePeriods = function( offset )
+ {
+ var periods = [];
+ var year = new Date().getFullYear() + offset;
+ var startDate = $.date( year + '-04-01', dateFormat ).adjust( 'Y', -5 );
+ var endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+
+ for ( var i = 0; i < 11; i++ )
+ {
+ var period = [];
+ period['startDate'] = startDate.format( dateFormat );
+ period['endDate'] = endDate.format( dateFormat );
+ period['name'] = monthNames[3] + ' ' + startDate.date().getFullYear() + '-' + monthNames[2] + ' ' + (startDate.date().getFullYear() +1 );
+ period['id'] = 'FinancialApril_' + period['startDate'];
+ period['iso'] = year + 'April';
+ periods[i] = period;
+
+ startDate.adjust( 'Y', +1 );
+ endDate = startDate.clone().adjust( 'Y', +1 ).adjust( 'D', -1 );
+ }
+
+ return periods;
+ };
+}