Public Member Functions | |
_LOMDurationToArray ($a_string) | |
LOM datatype duration is a string like P2M4DT7H18M2S (2 months 4 days 7 hours 18 minutes 2 seconds) This function tries to parse a given string in an array of months, days, hours, minutes and seconds. |
Definition at line 32 of file class.ilMDUtils.php.
ilMDUtils::_LOMDurationToArray | ( | $ | a_string | ) |
LOM datatype duration is a string like P2M4DT7H18M2S (2 months 4 days 7 hours 18 minutes 2 seconds) This function tries to parse a given string in an array of months, days, hours, minutes and seconds.
string | string to parse |
Definition at line 42 of file class.ilMDUtils.php.
Referenced by ilMDEducational::_getTypicalLearningTimeSeconds(), ilMDEducational::getTypicalLearningTimeSeconds(), ilMDEditorGUI::listEducational(), and ilMDEditorGUI::listQuickEdit().
{ $a_string = trim($a_string); #$pattern = '/^(PT)?(\d{1,2}H)?(\d{1,2}M)?(\d{1,2}S)?$/i'; $pattern = '/^P(\d{1,2}M)?(\d{1,2}D)?(T(\d{1,2}H)?(\d{1,2}M)?(\d{1,2}S)?)?$/i'; if(!preg_match($pattern,$a_string,$matches)) { return false; } // Month if(preg_match('/^P(\d+)M/i',$a_string,$matches)) { $months = $matches[1]; } // Days if(preg_match('/(\d+)+D/i',$a_string,$matches)) { #var_dump("<pre>",$matches,"<pre>"); $days = $matches[1]; } if(preg_match('/(\d+)+H/i',$a_string,$matches)) { #var_dump("<pre>",$matches,"<pre>"); $hours = $matches[1]; } if(preg_match('/T(\d{1,2}H)?(\d+)M/i',$a_string,$matches)) { #var_dump("<pre>",$matches,"<pre>"); $min = $matches[2]; } if(preg_match('/(\d+)S/i',$a_string,$matches)) { #var_dump("<pre>",$matches,"<pre>"); $sec = $matches[1]; } // Hack for zero values if(!$months and !$days and !$hours and !$min and !$sec) { return false; } return array($months,$days,$hours,$min,$sec); }