Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [KOHANA] Przekształcenie daty na "dzisiaj" lub "wczoraj"
dominick
post
Post #1





Grupa: Zarejestrowani
Postów: 88
Pomógł: 0
Dołączył: 30.05.2014

Ostrzeżenie: (0%)
-----


Zamiana daty typu dd-mm-YYYY na np. "dzisiaj" gdy data jest taka sama jak dzisiejsza.

datę wyświetlam czymś takim
  1. <div>
  2. <span class="date_added">
  3. <span>
  4. <?php echo date::my($a->annoucement_date_added, 'announcement') ?>
  5. </span>
  6. </span>
  7. </div>


Znalazłem jeszcze w kontrolerze daty coś odpowiedzialnego za format:
  1. class Date extends I18n_Date {
  2.  
  3. public static function my($value, $type = NULL)
  4. {
  5. $format = NULL;
  6.  
  7. if ($type !== NULL)
  8. {
  9. $format = Kohana::$config->load('date.' . $type);
  10. }
  11.  
  12. if ($format === NULL)
  13. {
  14. $format = 'd-m-Y';
  15. }
  16.  
  17. if (is_numeric($value))
  18. {
  19. $date = date($format, $value);
  20. }
  21. else
  22. {
  23. $date = strtotime($value);
  24. $date = date($format, $date);
  25. }
  26. return $date;
  27. }
  28.  
  29.  
  30. /**
  31. * Returns time difference between two timestamps, in human readable format.
  32. * If the second timestamp is not given, the current time will be used.
  33. * Also consider using [Date::fuzzy_span] when displaying a span.
  34. *
  35. * $span = Date::span(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2)
  36. * $span = Date::span(60, 182, 'minutes'); // 2
  37. *
  38. * @param integer $remote timestamp to find the span of
  39. * @param integer $local timestamp to use as the baseline
  40. * @param string $output formatting string
  41. * @return string when only a single output is requested
  42. * @return array associative list of all outputs requested
  43. */
  44. public static function span($remote, $local = NULL, $output = 'years,months,weeks,days,hours,minutes,seconds')
  45. {
  46. // Normalize output
  47. $output = trim(strtolower( (string) $output));
  48.  
  49. if ( ! $output)
  50. {
  51. // Invalid output
  52. return FALSE;
  53. }
  54.  
  55. // Array with the output formats
  56. $output = preg_split('/[^a-z]+/', $output);
  57.  
  58. // Convert the list of outputs to an associative array
  59. $output = array_combine($output, array_fill(0, count($output), 0));
  60.  
  61. //Fix bug: Only variables should be passed by reference
  62. $fliped = array_flip($output);
  63.  
  64. // Make the output values into keys
  65. extract($fliped, EXTR_SKIP);
  66.  
  67. if ($local === NULL)
  68. {
  69. // Calculate the span from the current time
  70. $local = time();
  71. }
  72.  
  73. // Calculate timespan (seconds)
  74. $timespan = abs($remote - $local);
  75.  
  76. if (isset($output['years']))
  77. {
  78. $timespan -= Date::YEAR * ($output['years'] = (int) floor($timespan / Date::YEAR));
  79. }
  80.  
  81. if (isset($output['months']))
  82. {
  83. $timespan -= Date::MONTH * ($output['months'] = (int) floor($timespan / Date::MONTH));
  84. }
  85.  
  86. if (isset($output['weeks']))
  87. {
  88. $timespan -= Date::WEEK * ($output['weeks'] = (int) floor($timespan / Date::WEEK));
  89. }
  90.  
  91. if (isset($output['days']))
  92. {
  93. $timespan -= Date::DAY * ($output['days'] = (int) floor($timespan / Date::DAY));
  94. }
  95.  
  96. if (isset($output['hours']))
  97. {
  98. $timespan -= Date::HOUR * ($output['hours'] = (int) floor($timespan / Date::HOUR));
  99. }
  100.  
  101. if (isset($output['minutes']))
  102. {
  103. $timespan -= Date::MINUTE * ($output['minutes'] = (int) floor($timespan / Date::MINUTE));
  104. }
  105.  
  106. // Seconds ago, 1
  107. if (isset($output['seconds']))
  108. {
  109. $output['seconds'] = $timespan;
  110. }
  111.  
  112. if (count($output) === 1)
  113. {
  114. // Only a single output was requested, return it
  115. return array_pop($output);
  116. }
  117.  
  118. // Return array
  119. return $output;
  120. }
  121.  
  122. }
  123.  


Starałem się użyć jakiejś funkcji ale za każdym razem błąd - nie mam już sił proszę o pomoc.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.12.2025 - 12:34