Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
pleas dont remove them :)
*/
export default [
{
name: "Date to Hex",
description: "Blocks to change a date to hex and vice versa.",
code: "AeroHutch/date-to-hex.js",
banner: "AeroHutch/date-to-hex.png",
creator: "AeroHutch",
},
Comment on lines +8 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this at least a little further down in the list. Maybe next to format numbers and date format.

{
name: "Pen+",
description: "Extended pen section! Adds blocks for drawing triangles using textures and tints, drawing images and editing their pixels, etc.",
Expand Down
73 changes: 73 additions & 0 deletions static/extensions/AeroHutch/date-to-hex.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be consistent about your usage of single quotes (') or double quotes (") for strings in this file. There really isn't a difference between the two (not in JavaScript, at least), you can easily interchange them. Given you use single quotes most often, I'd replace the double quotes in this file with single quotes.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
(function(Scratch) {
'use strict';

class HexDatePlugin {
getInfo() {
return {
id: 'hexDate',
name: 'Date to Hex',
blocks: [
{
opcode: 'dateToHex',
blockType: Scratch.BlockType.REPORTER,
text: 'convert date [DATE] to hex bytes',
arguments: {
DATE: {
type: Scratch.ArgumentType.STRING,
defaultValue: "2024-01-01"
}
}
},
{
opcode: 'hexToDate',
blockType: Scratch.BlockType.REPORTER,
text: 'convert hex [HEX] to date string',
arguments: {
HEX: {
type: Scratch.ArgumentType.STRING,
defaultValue: "0000018CD05D2000"
}
}
}
]
};
}

dateToHex(args) {
const date = new Date(args.DATE);
const timestamp = date.getTime();

if (isNaN(timestamp)) return "Invalid Date";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an issue that cannot be continued from, you should throw, not return. Throw will render an error message on the GUI and highlight the script that had an issue, returning doesn't.


// Create an 8-byte buffer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is pointless; comments should be used exceedingly sparingly, generally.

const buffer = new ArrayBuffer(8);
const view = new DataView(buffer);

// Write as Big-Endian 64-bit integer
// Note: BigInt is used because JS numbers lose precision above 53 bits
view.setBigUint64(0, BigInt(timestamp), false);
Comment on lines +46 to +48
Copy link
Contributor

@Steve0Greatness Steve0Greatness Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Big endian is the default mode of this method, anyway. Specifying it to be written in big endian in a bit pointless: DataView.prototype.setBigUint64() littleEndian.


// Convert buffer to Hex string
return Array.from(new Uint8Array(buffer))
.map(b => b.toString(16).padStart(2, '0'))
Comment on lines +42 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of work for something that is seemingly replicated perfectly fine with .toString(16).padStart(16, '0').toUpperCase(). Although feel free to correct me if I'm wrong, here.

.join('')
.toUpperCase();
}

hexToDate(args) {
try {
const hex = args.HEX.replace(/\s/g, '');
const bytes = new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
const view = new DataView(bytes.buffer);

// Read as Big-Endian 64-bit integer
const timestamp = Number(view.getBigUint64(0, false));
Comment on lines +59 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet again, I think this entire area could fairly well replaced with a singular call to parseInt, with the second parameter set to 16, to make sure it knows to parse as a 16 bit integer.

return new Date(timestamp).toString();
} catch (e) {
return "Invalid Hex";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once more, throw here. I really dislike seeing areas where random bugs can occur for no reason without even being able to track down where it's going on.

}
}
}

Scratch.extensions.register(new HexDatePlugin());
})(Scratch);
Binary file added static/images/AeroHutch/date-to-hex.png
Copy link
Contributor

@Steve0Greatness Steve0Greatness Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it matters for this PR (it can always be changed later) but AVIF is generally expected for thumbnails. You should probably either convert it on your own machine or look for an online converter to convert it for you, then upload it with the same basename but with .avif for the extension; also remember to update extensions.js to point to the AVIF version instead of the PNG.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.