Metamorphing Machine I rather be this walking metamorphosis
than having that old formed opinion about everything!

The most shaming piece of code I ever did (so far...)

I don't know if you know it, but we VB developers are known to deliver at all costs.
While some non-VB devs are known to be obsessed with correctness and/or performance (lookig at you, C++), VB devs code the right way, the hard way, or the wrong way, as long as their goal is met!
I even heard once a co-worker saying "Never trust a developer", after seeing some of the code being churned at the time.

Today I'm going to share the most embarrassing piece of code I ever did. Actually, I cannot share share it, because technically it belongs to my employer. But I can share my stream of thoughts about it.

I have been working on a web system for a couple of years now. It deals with bills, and it has a grid that displays bills' data like value, date of issue, issuer's name, and so on.
We have the date of issue formatted according to the user's locale and, right out of the box, our grid is unable to sort it correctly. My co-worker at the time and I searched high and low and were unable to find a way to fix it.

So The Customer© had an issue with it, and rightfully so. We proposed formatting the dates in sort-friendly format like year-month-day, but The Customer© was adamant we should not change dates' format.
Replacing that grid was a no-option, as we would need to re-do several features and we simply had no time to do it.

What to do now!?

So, I started thinking "What if I prepend each date with its number version?" That would make sorting work, but that number could not be seen.
"What if its font color were the same as the background?" I quickly discarded this idea because if the customer were to select the date's text, they would be able to see my supposedly undercovered number.
Then I remembered some Unicode characters were invisible. Can you see where this is going (no pun intended)?

So I researched and picked up two of the invisible Unicode characters.
In the server-side of code I transformed the date to a number using C#'s Date's ToOADate method (I was lucky enough the date did not have a time part).
Then converted the resulting double to an int and encoded it in binary using the two invisible Unicode characters.
The last step was to prepended it to date of issue and sent it to the client side, whose only job was to display it.

It worked like a charm, with one minor caveat: That grid is exportable to .CSV format, and once the file is opened one can see a sequence of little squares before the date where should have be none.
I suppose The Customer© does not use that feature, as I heard no complaint from him since the implementation went live.

And that's it. It is such an ugly hack that I'm proud to be ashamed of this code.

Andrej Biasic
As I said above, I cannot publish that specific piece of code because reasons, but I've found a Javascript version of it that I did and completely forgot about.
This one is OK to share:

const formatSortableDate = (dt) => {
let n = dt.valueOf();
n -= dt.getTimezoneOffset() * 60000;
n /= 86400000;
n |= 0;
n += 25569;
let result = n.toString(2)
.replace(/1/g, "\uFEFF")
.replace(/0/g, "\u200B");
return result;

Andrej Biasic