Skip to content

Instantly share code, notes, and snippets.

@brandonsheppard
Created December 28, 2017 04:51
Show Gist options
  • Save brandonsheppard/d242ba4ba99923d332f1afdcfa4fbf86 to your computer and use it in GitHub Desktop.
Save brandonsheppard/d242ba4ba99923d332f1afdcfa4fbf86 to your computer and use it in GitHub Desktop.
Generate chronological version number based on previous version number

generateVersionNumber()

This function generates a date-based version number. Year + Month + Iteration

So, the first release in March 2017 will be 17.3.0

If multiple releases occur in a month, the final number will increase. Otherwise, an entirely new verion number will be generated.

i.e.

generateVersionNumber('17.12.10');

Output:

Given that the date is 2017-12-01 (day is irrelevant)

17.12.11

Source:

function generateVersionNumber(previousVersion){
	let today = new Date();
	var newMajor = `${today.getFullYear()}.${parseInt(today.getMonth()) + 1}`
	newMajor = newMajor.substr(2);
	oldMajorArr = previousVersion.split('.')
	oldMajor = `${oldMajorArr[0]}.${oldMajorArr[1]}`

	if(oldMajor == newMajor){
		newVersion = `${newMajor}.${parseInt(oldMajorArr[2]) + 1}`
	} else {
		newVersion = newMajor + '.0'
	}
	return newVersion;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment