PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.2
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / classes / date-tools.php
date-tools.php
45 lines 862 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes;
5
6 // If this file is called directly, abort.
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 class Date_Tools {
12
13 const TIME = 1;
14 const DATE = 2;
15 const DATETIME = 3;
16
17 public static function time_to_string( string $value, int $stamp_format = self::DATE ): string {
18 // Min/max come from the field block's own attributes (admin-authored).
19 $value = jet_fb_parse_dynamic_trusted( $value );
20
21 if ( ! is_scalar( $value ) ) {
22 return '';
23 }
24
25 if ( self::TIME === $stamp_format ) {
26 return $value;
27 }
28
29 $format = '';
30
31 switch ( $stamp_format ) {
32 case self::DATE:
33 $format = 'Y-m-d';
34 break;
35 case self::DATETIME:
36 $format = 'Y-m-d\TH:i';
37 break;
38 }
39
40 // phpcs:ignore WordPress.DateTime.RestrictedFunctions
41 return Tools::is_valid_timestamp( $value ) ? date( $format, $value ) : $value;
42 }
43
44 }
45