In App Inventor, there is a component called Clock, which has a block called "FormatDateTime" and its pink pattern has the default text "MM/dd/yyyy hh:mm:ss a" which is editable.
// -------------------------------------------------------------
// FORMAT DATE TIME (Calendar + Pattern)
// -------------------------------------------------------------
@SimpleFunction(description = "Returns text representing the date and time of an instant in the specified pattern")
public String FormatDateTime(Calendar instant, String pattern) {
try {
return Dates.FormatDateTime(instant, pattern);
} catch (IllegalArgumentException e) {
throw new YailRuntimeError(
"Invalid pattern for FormatDateTime. Examples: MM/dd/yyyy hh:mm:ss a , MMM d, yyyy HH:mm",
"Format Error");
}
}
The pre-filled text block (MM/dd/yyyy hh:mm:ss a) is not generated by the code, but hardcoded in the AI2 platform's block generator. As far as I know, there is no way to achieve this via an extension.
As mentioned, there is no way for extensions to do this. The default blocks feature was implemented in App Inventor well before extensions were added, and it would be good for us to revisit this part of the system to make it more generalizable for both our built-in components and useful for extension developers as well. If someone is interested in refactoring the system to make components declare their default blocks rather than hard coding it please let me know.