Request for help on creating a clock Extensions

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.

I created a new extension and wanted to simulate this, but in my created block, the pink pattern was not created and the pattern is empty.

My function text is as follows:

     // -------------------------------------------------------------
    //  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");
        }
    }

Can anyone guide me?

At this moment, we are unable to attach examples to the parameters from extensions.

I think there was a proposal about this topic.

1 Like

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.