Project

General

Profile

« Previous | Next » 

Revision 13

Added by Manuela over 6 years ago

added new class 'vendor\jscalendar\Helper

View differences:

branches/main/admin/interface/version.php
48 48

  
49 49
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
50 50
if(!defined('VERSION')) { define('VERSION', '2.10.1-dev'); }
51
if(!defined('REVISION')) { define('REVISION', '12'); }
51
if(!defined('REVISION')) { define('REVISION', '13'); }
52 52
if(!defined('SP')) { define('SP', ''); }
53 53

  
branches/main/include/jscalendar/Helper.php
1
<?php
2

  
3
/*
4
 * Copyright (C) 2017 Manuela v.d.Decken <manuela@isteam.de>
5
 *
6
 * DO NOT ALTER OR REMOVE COPYRIGHT OR THIS HEADER
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, version 2 of the License.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License 2 for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License 2
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
/**
21
 * Description of Helper
22
 *
23
 * @package      DynarchJsCalendar
24
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
25
 * @author       Manuela v.d.Decken <manuela@isteam.de>
26
 * @license      GNU General Public License 2.0
27
 * @version      0.0.1
28
 * @revision     $Id$
29
 * @since        File available since 13.09.2017
30
 * @deprecated   no / since 0000/00/00
31
 * @description  xxx
32
 */
33
//declare(strict_types = 1);
34
//declare(encoding = 'UTF-8');
35

  
36
namespace vendor\jscalendar;
37

  
38
// use
39

  
40
/**
41
 * short description of class
42
 */
43
class Helper
44
{
45
/**
46
 * transform date/time string into Unix timestamp
47
 * @param string $sTimeString a date/time string using one of the declared patterns
48
 * @param string (optional) $sFormat (not defined yet)
49
 * @return int  unix timestamp
50
 */
51
    public static function getTimestampFromString($sTimeString, $sFormat = '')
52
    {
53
        $iTimestamp = $iPatternFound = 0;
54
        if (trim($sTimeString)) { // procceed only if string not empty
55
            $aFormats = [
56
                // "dd.mm.[yy]yy[ [h]h:[m]m:[s]s]"
57
                ['/^\s*?(\d{1,2})\.(\d{1,2})\.(\d{4}|\d{2})(\s*.*)?\s*?$/si', '\3-\2-\1\4'],
58
                // "mm\/dd\/[yy]yy[ [h]h:[m]m:[s]s]"
59
                ['/^\s*?(\d{1,2})\/(\d{1,2})\/(\d{4}|\d{2})(\s*.*)?\s*?$/si', '\3-\1-\2\4'],
60
            ];
61
            foreach ($aFormats as $aPattern) {
62
                $sTmpTimeString = preg_replace($aPattern[0], $aPattern[1], $sTimeString, -1, $iPatternFound);
63
                if ($iPatternFound) {
64
                    $iTimestamp = strtotime($sTmpTimeString);
65
                    break;
66
                }
67
            }
68
        }
69
        return $iTimestamp;
70
    }
71
}
0 72

  

Also available in: Unified diff