diff --git a/source/lib/SihnonFramework/DateTime.class.php b/source/lib/SihnonFramework/DateTime.class.php new file mode 100644 index 0000000..8de5602 --- /dev/null +++ b/source/lib/SihnonFramework/DateTime.class.php @@ -0,0 +1,119 @@ + 'one', + 2 => 'two', + 3 => 'three', + 4 => 'four', + 5 => 'five', + 6 => 'six', + 7 => 'seven', + 8 => 'eight', + 9 => 'nine', + 10 => 'ten', + 11 => 'eleven' + ); + + // today + if ($sod_now == $sod) { + if ($time > $now - (self::MINUTE * 3)) { + return 'just a moment ago'; + } else if ($time > $now - (self::MINUTE * 7)) { + return 'a few minutes ago'; + } else if ($time > $now - (self::HOUR)) { + return 'less than an hour ago'; + } + return 'today at ' . date('g:ia', $time); + } + + // yesterday + if (($sod_now - $sod) <= self::DAY) { + if (date('i', $time) > (self::MINUTE + 30)) { + $time += self::HOUR / 2; + } + return 'yesterday around ' . date('ga', $time); + } + + // within the last 5 days + if (($sod_now - $sod) <= (self::DAY * 5)) { + $str = date('l', $time); + $hour = date('G', $time); + if ($hour < 12) { + $str .= ' morning'; + } else if ($hour < 17) { + $str .= ' afternoon'; + } else if ($hour < 20) { + $str .= ' evening'; + } else { + $str .= ' night'; + } + return $str; + } + + // number of weeks (between 1 and 3)... + if (($sod_now-$sod) < (self::WEEK * 3.5)) { + if (($sod_now-$sod) < (self::WEEK * 1.5)) { + return 'about a week ago'; + } else if (($sod_now-$sod) < (self::DAY * 2.5)) { + return 'about two weeks ago'; + } else { + return 'about three weeks ago'; + } + } + + // number of months (between 1 and 11)... + if (($sod_now-$sod) < (self::MONTH * 11.5)) { + for ($i = (self::WEEK * 3.5), $m=0; $i < self::YEAR; $i += self::MONTH, $m++) { + if ( ($sod_now-$sod) <= $i ) { + return 'about ' . $convert[$m] . ' month' . (($m>1)?'s':'') . ' ago'; + } + } + } + + // number of years... + for ($i = (self::MONTH * 11.5), $y=0; $i < (self::YEAR * 10); $i += self::YEAR, $y++) { + if (($sod_now-$sod) <= $i) { + return 'about ' . $convert[$y] . ' year' . (($y>1)?'s':'') . ' ago'; + } + } + + // more than ten years... + return 'more than ten years ago'; + } + +} + +?> \ No newline at end of file