Custom Fields
Re-Envisioned
Support General Date before 1970: timestamp is stored as positive

  • Creator
    Topic
  • #24088
    Resolved Aart Jan van der Linden
    Participant

    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;
    });
Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #24089

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

    #24090
    Long 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

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