From c984b4768db0c6342f3f11792be640805a3445c4 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sun, 24 Jul 2022 09:33:28 -0500 Subject: [PATCH] Explaining rationale and pros/cons behind encoding approach. --- repository/TiddlyWiki/Tiddler.class.st | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 9d8f111..6010092 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -126,14 +126,19 @@ Tiddler >> createdAsTWFormat [ ] { #category : #accessing } -Tiddler >> createdEncoded [ +Tiddler >> createdReversableEncoded [ + "I encode the tiddler creation date with miliseconds precision in a shorter reversable way + (from 17 characters to 10). + But when tiddlers are created with the same exact date (for example programmatically) + I produce the same encoding (because of reversability). + I recommend to use nanoID instead to get unique visible different identifiers " | output longDate | longDate := self createdAsTWFormat. - output := '' writeStream. + output := WriteStream on: ''. 1 to: 14 by: 2 do: [ :i | - output nextPutAll: (longDate copyFrom: i to: i +1 ) asInteger asCharacterDigit asString + output nextPutAll: (longDate copyFrom: i to: i +1) greaseInteger asCharacterDigit greaseString ]. - output nextPutAll: ((longDate copyFrom: 15 to: 17)). + output nextPutAll: (longDate copyFrom: 15 to: 17). ^ output contents ] @@ -532,7 +537,7 @@ Tiddler >> uid [ Tiddler >> uidGenerator [ self created ifNil: [ self created: self class nowLocal ]. - ^ self customFields at: 'uid' put: self createdEncoded. + ^ self customFields at: 'uid' put: self createdReversableEncoded. ]