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?

1 Like

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.

1 Like

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.

3 Likes

I think I can add this functionality.

3 Likes

That'd be awesome. I can't wait to get it into FAST-CLI.

We can add standard values ​​as shadow blocks. Currently, types such as text, number, boolean, and color are supported.

image

1 Like

Why an extension?

If all you need is a default Farsi datetime pattern, code a value procedure with that name returning whatever text pattern you want.

Then you will have something that runs on both iOS and Android.