-
-
Notifications
You must be signed in to change notification settings - Fork 474
Description
Describe the problem
The default sketch name template of 'sketch_MMMDDx.ino' produces names that do not sort in a sane order.
sketch_apr03a sketch_apr24a sketch_dec20b sketch_feb09a sketch_feb23b sketch_jan21a sketch_mar08b sketch_mar27b sketch_nov18a
sketch_apr06a sketch_apr25a sketch_dec21a sketch_feb09b sketch_feb23c sketch_jan22a sketch_mar09a sketch_mar27c sketch_nov24a
sketch_apr07a sketch_apr27a sketch_dec28a sketch_feb10a sketch_feb24a sketch_jan23a sketch_mar12a sketch_mar28b sketch_nov24b
sketch_apr12a sketch_dec05a sketch_dec29a sketch_feb14a sketch_feb26a sketch_jan23c sketch_mar12b sketch_mar28c sketch_nov25a
sketch_apr13a sketch_dec07a sketch_feb01a sketch_feb16a sketch_feb28b sketch_jan23d sketch_mar16a sketch_mar29a sketch_oct22a
sketch_apr14a sketch_dec10a sketch_feb01b sketch_feb16b sketch_feb28c sketch_jan24a sketch_mar18a sketch_mar30a sketch_sep12b
sketch_apr15a sketch_dec17a sketch_feb01c sketch_feb19a sketch_jan02a sketch_jan29a sketch_mar18b sketch_may02a sketch_sep12c
sketch_apr16a sketch_dec18a sketch_feb01d sketch_feb21a sketch_jan03a sketch_jan31a sketch_mar20a sketch_may02b
sketch_apr19a sketch_dec18b sketch_feb03a sketch_feb21b sketch_jan09a sketch_mar05a sketch_mar21a sketch_may02c
sketch_apr21a sketch_dec18c sketch_feb03b sketch_feb22a sketch_jan11b sketch_mar05b sketch_mar25a sketch_may03a
sketch_apr23a sketch_dec20a sketch_feb07a sketch_feb23a sketch_jan13a sketch_mar08a sketch_mar26a sketch_nov07a
January sorts after February, April comes first, and December comes second.
Using a pattern like sketch_YYYYMMDDx
would produce names which sort in a sane order.
To reproduce
Produce sketches with default names over the course of a year or multiple years.
Expected behavior
I would expect auto-generated sketch names to be created with an ISO-9660-ish name and sort in a sane, chronological order.
Either include the year and numeric month, or if awkward names that encourage renaming are the goal, use a simpler scheme like sketch_xxxx
.
Arduino IDE version
2.1.0
Operating system
macOS
Operating system version
13.2.1
Additional context
Per @ptillisch, the code is here:
arduino-ide/arduino-ide-extension/src/node/sketches-service-impl.ts
Lines 372 to 415 in 31deeeb
if (!sketchName) { | |
const monthNames = [ | |
'jan', | |
'feb', | |
'mar', | |
'apr', | |
'may', | |
'jun', | |
'jul', | |
'aug', | |
'sep', | |
'oct', | |
'nov', | |
'dec', | |
]; | |
const today = new Date(); | |
const sketchBaseName = `sketch_${ | |
monthNames[today.getMonth()] | |
}${today.getDate()}`; | |
const { config } = await this.configService.getConfiguration(); | |
const sketchbookPath = config?.sketchDirUri | |
? FileUri.fsPath(config?.sketchDirUri) | |
: os.homedir(); | |
// If it's another day, reset the count of sketches created today | |
if (this.lastSketchBaseName !== sketchBaseName) | |
this.sketchSuffixIndex = 1; | |
let nameFound = false; | |
while (!nameFound) { | |
const sketchNameCandidate = `${sketchBaseName}${sketchIndexToLetters( | |
this.sketchSuffixIndex++ | |
)}`; | |
// Note: we check the future destination folder (`directories.user`) for name collision and not the temp folder! | |
const sketchExists = await exists( | |
path.join(sketchbookPath, sketchNameCandidate) | |
); | |
if (!sketchExists) { | |
nameFound = true; | |
sketchName = sketchNameCandidate; | |
} | |
} | |
this.lastSketchBaseName = sketchBaseName; | |
} |
I'm not sure how that code pads the day numbers with zeros, but maybe something like this would work as I expect it should:
const sketchBaseName =`sketch_${today.getYear()}${today.getMonth()+1}${today.getDate()}`;
However, I'm unsure if it would 0-pad single-digit months and days.
Issue checklist
- I searched for previous reports in the issue tracker
- I verified the problem still occurs when using the latest nightly build
- My report contains all necessary details