Question

I'm integrating to a legacy application that produces data files where the maximum file name size is 8 characters. I can control the name and I'd like to be able to base it on the current date and time, to the nearest second. It must be unique.

Has anyone got any nice ideas or algorithms to achieve this, without any state?

I'm using C# but any language or pseudo-code ideas are welcome!

Edit: Any characters A-Za-z0-9 allowed only (to be on the safe side),

Was it helpful?

Solution

I think the easiest solution would be to store Unix time in hex, which would last 93 years from now.

OTHER TIPS

You could get by with just the number of seconds passed since 1/1/12 0:00, but this would last for just 3 years.

Assuming case insensitivity you could code in base 36, using the 10 digits and 26 letters of the alphabet, which should last at least through your lifetime.

If you can use more chars than 0-9 you could use a pattern where months and hours are encoded as letters

months = a-l
hours = a-y (depending on if you use w or not.)
days = 0-9 + a-...

This combined with 2 digit year and seconds in the hour as hex (3 chars) amounts to

yyMdhsss

In extention to one of above answer,

    year = 2 YY it's diff year from reference year say 2000. we can have 26+26+10 aphabets to combine !
    months = 1 M a-l map each month to single alphabet
    days = 1 D a-z A-G 
    hours = 1 H a-y (map a char to a-x)
    seconds = 1 60 a-z , A-Z 0-9 chars total 26+26+10 ==> 62 avaiable chars

Keep all dates in GMT format for storing.

It fits in 6 chars ! May be we can use 1 more char as year extention if needed. Obviously, we need have custom functions to convert timedate from normal to this format.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top