-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Behaviour of the 'micro' inc function #2
Comments
Thank you. I also think this is what it should be by default. Fix is on the way... |
Published the fix. Closing the issue now. |
Thanks for your help! But I'm not sure it is working as I described above. Can you explain what you expect to happen here: var version = new calver('YYYY.MM.MICRO', '2020.12.5');
version.inc();
console.log(version.get()); I would assume this should return |
I've published another update. Can you confirm that now it's working as expected? |
Yeah, this is it! thanks! var version = new calver('YYYY.MM.MICRO', '2020.11.5');
version.inc(); // 2020.12.0
var version = new calver('YYYY.MM.MICRO', '2020.12.5');
version.inc(); // 2020.12.6
|
It seems like the API has changed a lot since this issue was opened. Is this is no longer possible with the current versions? I'm looking for away to do a calendar increment that falls back to incrementing the Currently, it just throws an error when the date components aren't updated: const format = 'YYYY.MM.MICRO';
calver.inc(format, '2021.5.1', 'calendar'); // 2021.6.0
calver.inc(format, '2021.6.0', 'calendar'); // throws with 'There is no change in the version.'
calver.inc(format, '2021.6.0', 'calendar.micro'); // throws with 'Second level should be a modifier or remove it.' I'd prefer if the API worked this way (adapting from this issue's original comment): const format = 'YYYY.MM.MICRO';
const version = '2020.11.3';
// It is november 15th
calver.inc(format, version, 'calendar.micro'); // 2020.11.4
// It is november 30th
calver.inc(format, version, 'calendar.micro'); // 2020.11.5
// It is december 1st
calver.inc(format, version, 'calendar.micro'); // 2020.12.0
// a later day in december
calver.inc(format, version, 'calendar.micro'); // 2020.12.1 |
That's exactly what I found out this week. I've decided to write my own solution that is only suited for the function getVersionParts(version) {
const parts = version.split('.');
return {
year: +parts[0],
month: +parts[1],
minor: +parts[2],
};
}
function getNewVersion(input) {
const previousVersion = getVersionParts(input);
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1;
let minor = 0;
if (year === previousVersion.year && month === previousVersion.month) {
minor = previousVersion.minor + 1;
}
return `${year}.${month}.${minor}`;
} Use it like this: // in may 2021
getNewVersion('2021.5.3'); // 2021.5.4
// in june 2021
getNewVersion('2021.5.3'); // 2021.6.0 |
Hi @kherock If you try |
Hi @Duncank Noo I wrote this library to not to write our own functions. Just specify which tag you would like to update in the inc function. Look at the previous message I sent in this issue. Is it still not satisfying you? |
@muratgozel My problem isn't that I can't get it to work, this is functionality that used to be possible for incrementing micro versions. I have an automated script that should increment a version number where
You should notice that this is similar to how function incrementCalendarMicro(format, version) {
try {
return calver.inc(format, version, 'calendar');
} catch (err) {
if (!err.message.startsWith('There is no change in the version')) throw err;
return calver.inc(format, version, 'micro');
}
} |
A reasonable suggestion for |
Calendar + semantic tags available in the // assuming current date is Jan 2021.
expect(calver.inc('yy.mm.micro.modifier', '20.4.1-dev.3', 'calendar.micro')).toBe('21.1.0')
expect(calver.inc('yy.mm.micro', '21.1.0', 'calendar.micro')).toBe('21.1.1') Please do |
I believe there's still a problem const format = 'YY.MM.MICRO';
console.log(calver.inc(format, '21.1.4', 'micro')) // current package version
// 21.1.5 It's June when you published, why there's an |
@daorren The |
@muratgozel Besides, when I mentiont |
@daorren Yes, it is only for tests. I specified "micro" as a tag therefore it didn't update the calendar portion of the current version. If I were to specify "calendar.micro" then the current version would be 21.8.0. |
Thank you for your reply, now I understand I must use 'calendar' to update to current date |
When I make use of date-based elements in my version tag, I would expect Calver to automatically update these correctly.
Take this example:
The first version number was last created in november (2020-11), since it is december now, it updates to 2020.12.0.
If I want to increase the version number again in december, executing the inc() function returns exactly the same version number. Instead, we'll have to use
inc('micro')
to get 2020.12.1.Maybe I'm missing something, but it seems to me that calver-based version numbers always should be adding one to the micro-level in this case, since the year and month levels did not change from the current version number. Calver knows what day it is, so it can compare it with the current version name to determine what should be updated.
I would expect the following behaviour:
The text was updated successfully, but these errors were encountered: