Date before 1970: timestamp is stored as positive

Support General Date before 1970: timestamp is stored as positiveResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24088

    Hi!

    I'm having a small issue with storing pre-1970 dates as timestamp: they should be negative, but after saving the post the value is turned into the positive value.

    So 1914-10-10 (-1740356372000) becomes 2025-02-24 (1740356372000) after saving.

    Hope you can find a fix, so I can keep using your perfect plugin on the WW-I project I'm working on....

    Best,

    Aart Jan

     add_filter('rwmb_meta_boxes', function ($metaBoxes) {
        $metaBoxes[] = [
           'title'           => 'Gegevens',
           'style'             => 'seamless',
           'id'              => 'tijdlijn',
           'post_types'      => 'gebeurtenis',
           'fields'          => [
               [
                   'id' => 'van',
                   'type' => 'date',
                   'admin_columns' => ['position'=> 'after title','sort'=>true],
                   'name' => 'Vanaf',
                   'timestamp' => true,
               ],
            ],
        ];
        return $metaBoxes;
    });
    #24089

    I believe it has to do with the sanitize_datetime() function in sanitizer.php (line 237). The abs() seems unnecessary?

    #24090
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for your reporting.

    The sanitization is used for the regular cases, for a specific case, you can bypass the sanitization by using the setting 'sanitize_callback' => 'none'. Get more details in the documentation https://docs.metabox.io/sanitization/#bypass-the-sanitization.

    #24098

    Hi!

    Thank you, I wasn't aware of that option. That certainly helps.

    Best,

    Aart Jan

    #31929
    Cereal ConceptCereal Concept
    Participant

    Hi !
    Great to know, I just encountered this problem.
    It would be great to have a this info on the date and datetime field pages in the documentation I think.

    Have a nice day !

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.