PageRenderTime 87ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/flatpress/fp-includes/core/core.date.php

https://bitbucket.org/alexandrul/flatpress
PHP | 101 lines | 75 code | 20 blank | 6 comment | 7 complexity | cf9e0eb2f3a384ceb4ba22bb2df2a974 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MIT
  1. <?php
  2. function date_strformat($format, $timestamp=0) {
  3. global $lang;
  4. // D l day
  5. if ( strpos($format, '%a') !== false ) {
  6. $i = strftime('%w', $timestamp);
  7. $format = str_replace('%a', $lang['date']['weekday_abbr'][$i], $format);
  8. }
  9. if ( strpos($format, '%A') !== false ) {
  10. $i = strftime('%w', $timestamp);
  11. $format = str_replace('%A', $lang['date']['weekday'][$i], $format);
  12. }
  13. // F M month
  14. if ( strpos($format, '%b') !== false ) {
  15. $i = intval(strftime('%m', $timestamp))-1;
  16. $format = str_replace('%b', $lang['date']['month_abbr'][$i], $format);
  17. }
  18. if ( strpos($format, '%B') !== false ) {
  19. $i = intval(strftime('%m', $timestamp))-1;
  20. $format = str_replace('%B', $lang['date']['month'][$i], $format);
  21. }
  22. if (DIRECTORY_SEPARATOR == '\\') {
  23. $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
  24. $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
  25. if (strpos($format, '%e') !== false) {
  26. $_win_from[] = '%e';
  27. $_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
  28. }
  29. if (strpos($format, '%l') !== false) {
  30. $_win_from[] = '%l';
  31. $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
  32. }
  33. $format = str_replace($_win_from, $_win_to, $format);
  34. }
  35. return strftime($format, $timestamp);
  36. }
  37. function date_time($offset=null) {
  38. global $fp_config;
  39. if (is_null($offset)) {
  40. $offset = $fp_config['locale']['timeoffset'];
  41. }
  42. $timestamp = time();
  43. return $timestamp + $offset * 3600;
  44. }
  45. /*
  46. function date_now($offset=0) {
  47. $timestamp = gmtime();
  48. $time_stamp = intval($timestamp) + intval($offset) * 60 * 60;
  49. return date($format, $time_stamp);
  50. }
  51. */
  52. // I really DON'T LIKE THIS, looks like an hack, yech...
  53. // Takes filename and extension as a parameter, strips
  54. // alphabetic chars (ascii) from filename and "parses" the date;
  55. // In fact it's just a substr, counting on the fact filename should be
  56. // "prefix%y%m%d-%H%M%S.ext"
  57. function date_from_id($id) {
  58. $strdate = substr($id, -13);
  59. if (!preg_match('/[0-9]{6}-[0-9]{6}/', $strdate))
  60. return array();
  61. $arr[ 'y' ] = substr($strdate, 0, 2);
  62. $arr[ 'm' ] = substr($strdate, 2, 2);
  63. $arr[ 'd' ] = substr($strdate, 4, 2);
  64. $arr[ 'H' ] = substr($strdate, 7, 2);
  65. $arr[ 'M' ] = substr($strdate, 9, 2);
  66. $arr[ 'S' ] = substr($strdate, 11, 2);
  67. $arr['ymd'] = $arr['y'] . $arr['m'] . $arr['d'];
  68. $arr['HMS'] = $arr['H'] . $arr['M'] . $arr['S'];
  69. $arr['time'] = mktime($arr['H'], $arr['M'], $arr['S'],
  70. $arr['m'], $arr['d'], $arr['y']);
  71. return $arr;
  72. }
  73. ?>