Format::time

Format::time

Erik SkovErik Skov Posts: 33Questions: 6Answers: 2

I have 2 time fields, which are just time, no date. I am trying to figure out the syntax for server side and client side.

I think the js is close to this:

                , { "label": "shift start:", "name": "rr_analyst.shift_start"
                    , format: "HH:mm"
                    , type: "datetime"
                    , "fieldInfo": "US style HH:mm format"
                }
                , { "label": "shift end:", "name": "rr_analyst.shift_end"
                    , format: "HH:mm"
                    , type: "datetime"
                    , "fieldInfo": "US style HH:mm format"
                }

I am fairly sure that if they were date time, the server side would need this:

            Field::inst('rr_analyst.shift_start')
                    /* MIGHT NOT BE DONE */
                ->getFormatter(Format::dateSqlToFormat('m/d/Y'))
                ->setFormatter(Format::datetime('m/d/Y','Y-m-d'))
                ->validator(Validate::dateFormat('m/d/Y')),

            Field::inst('rr_analyst.shift_end')
                    /* MIGHT NOT BE DONE */
                ->getFormatter(Format::dateSqlToFormat('d/m/Y'))
                ->setFormatter(Format::datetime('d/m/Y','Y-m-d'))
                ->validator(Validate::dateFormat('d/m/Y')),

But I can find no comments in the docs or forum as to what this should be for time fields. I would like to display as 2 digit hours, 2 digit minutes on a 24 hour clock.. I would like to write to the DB as 2 digit hours, 2 digit minutes, 2 digit seconds on a 24 hour clock. Something like this:

            Field::inst('rr_analyst.shift_start')
                    /* MIGHT NOT BE DONE */
                ->getFormatter(Format::dateSqlToFormat('h:i'))
                ->setFormatter(Format::datetime('h:i','h:i:s'))
                ->validator(Validate::dateFormat('h:i')),

            Field::inst('rr_analyst.shift_end')
                    /* MIGHT NOT BE DONE */
                ->getFormatter(Format::dateSqlToFormat('h:i'))
                ->setFormatter(Format::datetime('h:i','h:i:s'))
                ->validator(Validate::dateFormat('h:i')),

This question has an accepted answers - jump to answer

Answers

  • Erik SkovErik Skov Posts: 33Questions: 6Answers: 2

    Can someone point me to a list of possible formats?

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Hi Erik,

    On the server-side the formatting strings for the PHP libraries are defined by PHP's date formatter.

    On the client-side we support either Moment or Luxon which each define their own formatting:

    Allan

  • Erik SkovErik Skov Posts: 33Questions: 6Answers: 2

    Allan, this is fantastic. Another issue I was having resolved.
    PHP

                Field::inst('rr_analyst.shift_start')
                    ->getFormatter(Format::dateSqlToFormat('H:i'))
                    ->setFormatter(Format::datetime('H:i','H:i:s'))
                    ->validator( 'Validate::dateFormat', array(
                        "format"  => "H:i",
                        "message" => "Please enter a date in the format HH:MM in 24 hour military time."
                    ) ),
    

    JS

                    , { "label": "shift start:", "name": "rr_analyst.shift_start"
                        , format: "HH:mm"
                        , type: "datetime"
                        , "fieldInfo": "US style HH:mm format"
                    }
    
Sign In or Register to comment.