Helper::formatFuzzyDate PHP Method

formatFuzzyDate() public static method

generate string representation of a fuzzy date (fuzzy dates are strings of the format yyyy-mm-dd, where mm and dd can be 00 to indicate not being set).
public static formatFuzzyDate ( string $value ) : string
$value string
return string
    public static function formatFuzzyDate($value)
    {
        $year = (int) substr($value, 0, 4);
        $mon = (int) substr($value, 5, 2);
        $day = (int) substr($value, 8, 2);
        if ($year && $mon && $day) {
            return self::convertMySQL2NHS($value);
        }
        if ($year && $mon) {
            return date('M Y', strtotime($year . '-' . $mon . '-01 00:00:00'));
        }
        if ($year) {
            return (string) $year;
        }
        return 'Undated';
    }

Usage Example

Exemplo n.º 1
0
        ?>
 <?php 
        echo $medication->option ? "({$medication->option->name})" : '';
        ?>
 <?php 
        echo $medication->frequency->name;
        ?>
</td>
            </tr>
            <tr>
                <th>Date</th>
                <td>
                    <?php 
        echo Helper::formatFuzzyDate($medication->start_date) . ' - ';
        if (!$current) {
            echo Helper::formatFuzzyDate($medication->end_date);
            if ($medication->stop_reason) {
                echo " (reason for stopping: {$medication->stop_reason->name})";
            }
        }
        ?>
                </td>
            </tr>
            <?php 
        if ($this->checkAccess('OprnEditMedication')) {
            ?>
                <tr>
                    <th>Actions</th>
                    <td>
                        <a href="#" class="medication_edit" data-id="<?php 
            echo $medication->id;
All Usage Examples Of Helper::formatFuzzyDate