public function setDate($date = null, $validate = true) { $date = trim($date); $is_valid = preg_match("/^" . AK_ACTION_MAILER_RFC_2822_DATE_REGULAR_EXPRESSION . "\$/", $date); $date = !$is_valid ? date('r', empty($date) ? Ak::time() : (!is_numeric($date) ? strtotime($date) : $date)) : $date; if ($validate && !$is_valid && !preg_match("/^" . AK_ACTION_MAILER_RFC_2822_DATE_REGULAR_EXPRESSION . "\$/", $date)) { trigger_error(Ak::t('You need to supply a valid RFC 2822 date. You can just leave the date field blank or pass a timestamp and Akelos will automatically format the date for you'), E_USER_ERROR); } $this->date = $date; }
public function Test_for_getTimestamp() { $this->assertEqual(Ak::getTimestamp(), Ak::time()); $this->assertEqual('17:52:03', Ak::getDate(Ak::getTimestamp('17:52:03'), 'H:i:s')); $this->assertEqual(date('Y-m-d') . ' 17:52:03', Ak::getDate(Ak::getTimestamp('17:52:03'))); $this->assertEqual('2005-12-25 00:00:00', Ak::getDate(Ak::getTimestamp('2005-12-25'))); $this->assertEqual('1592-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('1592-10-09'))); $this->assertEqual('2192-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('2192-10-09'))); $this->assertEqual('2192-10-09 01:02:03', Ak::getDate(Ak::getTimestamp('2192-10-9 01:02:03'))); }
/** * Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>timestamp()</tt>. */ function time_ago_in_words($from_time, $include_seconds = false) { return DateHelper::distance_of_time_in_words($from_time, Ak::time(), $include_seconds); }
/** * Return formatted date. * * You can supply a format as defined at http://php.net/date * * Default date is in ISO format */ function getDate($timestamp = null, $format = null) { $timestamp = !isset($timestamp) ? Ak::time() : $timestamp; $use_adodb = $timestamp <= -3600 || $timestamp >= 2147468400; if ($use_adodb) { require_once AK_CONTRIB_DIR . DS . 'adodb' . DS . 'adodb-time.inc.php'; } if (!isset($format)) { return $use_adodb ? adodb_date('Y-m-d H:i:s', $timestamp) : date('Y-m-d H:i:s', $timestamp); } elseif (!empty($format)) { return $use_adodb ? adodb_date($format, $timestamp) : date($format, $timestamp); } trigger_error(Ak::t('You must supply a valid UNIX timetamp. You can get the timestamp by calling Ak::getTimestamp("2006-09-27 20:45:57")')); return false; }
public function Test_of_populate_todo_list() { for ($i = 0; $i <= 30; $i++) { $attributes = array('task' => 'Task number ' . ($i + 3), 'due_time' => Ak::getDate(Ak::time() + 60 * 60 * 24 * $i)); $TodoTask = new TodoItem($attributes); $this->assertTrue($TodoTask->save()); $this->assertTrue($TodoTask->task == $attributes['task'] && $TodoTask->due_time == $attributes['due_time']); } }
/** * @todo Refactor this method */ function updateLocaleFiles() { $new_core_entries = array(); $new_controller_entries = array(); $new_controller_files = array(); $used_entries = AkLocaleManager::getUsedLanguageEntries(); require AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php'; $core_dictionary = $dictionary; $controllers_dictionaries = array(); foreach ($used_entries as $k => $v) { // This is a controller file if (is_array($v)) { if (!isset($controllers_dictionaries[$k])) { $controller = $k; $module_lang_file = AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php'; if (is_file($module_lang_file)) { require $module_lang_file; $controllers_dictionaries[$controller] = array_merge((array) $dictionary, (array) $v); $existing_controllers_dictionaries[$controller] = (array) $dictionary; } else { $controllers_dictionaries[$controller] = (array) $v; $new_controller_files[$controller] = $module_lang_file; } } } else { if (!isset($core_dictionary[$k])) { $new_core_entries[$k] = $k; } } } $dictionary_file = ''; foreach ($new_controller_files as $controller => $file_name) { $dictionary_file = "<?php\n\n// File created on: " . date("Y-m-d G:i:s", Ak::time()) . "\n\n\$dictionary = array();\n\n"; foreach ($controllers_dictionaries[$controller] as $k => $entry) { $entry = str_replace("'", "\\'", $entry); $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';"; } unset($controllers_dictionaries[$controller]); $dictionary_file .= "\n\n\n?>"; Ak::file_put_contents($file_name, $dictionary_file); } // Module files foreach ((array) $controllers_dictionaries as $controller => $controller_entries) { $dictionary_file = ''; foreach ($controller_entries as $entry) { if ($entry == '' || isset($existing_controllers_dictionaries[$controller][$entry])) { continue; } $entry = str_replace("'", "\\'", $entry); $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';"; } if ($dictionary_file != '') { $original_file = Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php'); $original_file = rtrim($original_file, "?> \n\r"); $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n"; $dictionary_file = $original_file . $new_entries; Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file); foreach (Ak::langs() as $lang) { if ($lang != AK_FRAMEWORK_LANGUAGE) { $lang_file = @Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php'); if (empty($lang_file)) { $dictionary_file = $original_file; } else { $lang_file = rtrim($lang_file, "?> \n\r"); $dictionary_file = $lang_file; } Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php', $dictionary_file . $new_entries); } } } } // Core locale files $dictionary_file = ''; foreach ($new_core_entries as $core_entry) { if ($core_entry == '') { continue; } $core_entry = str_replace("'", "\\'", $core_entry); $dictionary_file .= "\n\$dictionary['{$core_entry}'] = '{$core_entry}';"; } if ($dictionary_file != '') { $original_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php'); $original_file = rtrim($original_file, "?> \n\r"); $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n"; $dictionary_file = $original_file . $new_entries; Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file); foreach (Ak::langs() as $lang) { if ($lang != AK_FRAMEWORK_LANGUAGE) { $lang_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php'); if (empty($lang_file)) { $dictionary_file = str_replace("\$locale['description'] = 'English';", "\$locale['description'] = '{$lang}';", $original_file); } else { $lang_file = rtrim($lang_file, "?> \n\r"); $dictionary_file = $lang_file; } Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php', $dictionary_file . $new_entries); } } } }
/** * @todo Refactor this method */ static function updateLocaleFiles() { if (defined('AK_LOCALE_MANAGER') && class_exists(AK_LOCALE_MANAGER) && in_array('AkLocaleManager', class_parents(AK_LOCALE_MANAGER))) { return; } $paths = array(); $new_core_entries = array(); $new_controller_entries = array(); $new_controller_files = array(); $used_entries = AkLocaleManager::getUsedLanguageEntries(); list($core_locale, $core_dictionary) = AkLocaleManager::getCoreDictionary(AK_FRAMEWORK_LANGUAGE); $controllers_dictionaries = array(); foreach ($used_entries as $k => $v) { // This is a controller file if (is_array($v)) { if (!isset($controllers_dictionaries[$k])) { $controller = $k; $controllers_dictionaries[$controller] = AkLocaleManager::getDictionary(AK_FRAMEWORK_LANGUAGE, $controller); if (!empty($controllers_dictionaries[$controller])) { $existing_controllers_dictionaries[$controller] = $controllers_dictionaries[$controller]; } else { $new_controller_files[$controller] = true; } $controllers_dictionaries[$controller] = array_merge($controllers_dictionaries[$controller], (array) $v); } } else { if (!isset($core_dictionary[$k])) { $new_core_entries[$k] = $k; } } } foreach ($new_controller_files as $controller => $true) { $paths[] = AkLocaleManager::setDictionary($controllers_dictionaries[$controller], AK_FRAMEWORK_LANGUAGE, $controller, "File created on: " . date("Y-m-d G:i:s", Ak::time())); foreach (Ak::langs() as $lang) { if ($lang != AK_FRAMEWORK_LANGUAGE) { $dictionary = AkLocaleManager::getDictionary($lang, $controller); $paths[] = AkLocaleManager::setDictionary(array_merge($controllers_dictionaries[$controller], $dictionary), $lang, $controller); } } unset($controllers_dictionaries[$controller]); } // Module files foreach ((array) $controllers_dictionaries as $controller => $controller_entries) { $controller_entries = AkLocaleManager::getNewEntries($controller_entries, (array) @$existing_controllers_dictionaries[$controller]); if (!empty($controller_entries)) { $dictionary = AkLocaleManager::getDictionary(AK_FRAMEWORK_LANGUAGE, $controller); $paths[] = AkLocaleManager::setDictionary(array_merge($dictionary, $controller_entries), AK_FRAMEWORK_LANGUAGE, $controller); foreach (Ak::langs() as $lang) { if ($lang != AK_FRAMEWORK_LANGUAGE) { $dictionary = AkLocaleManager::getDictionary($lang, $controller); $paths[] = AkLocaleManager::setDictionary(array_merge($dictionary, $controller_entries), $lang, $controller); } } } } // Core locale files $new_core_entries = AkLocaleManager::getNewEntries($new_core_entries); if (!empty($new_core_entries)) { AkLocaleManager::setCoreDictionary($core_locale, array_merge($core_dictionary, $new_core_entries), AK_FRAMEWORK_LANGUAGE); foreach (Ak::langs() as $lang) { if ($lang != AK_FRAMEWORK_LANGUAGE) { list($l, $dictionary) = AkLocaleManager::getCoreDictionary($lang); if (empty($l)) { $l = $core_locale; $l['description'] = $lang; $l['locale_description'] = $lang; } if (empty($dictionary)) { $dictionary = $core_dictionary; } AkLocaleManager::setCoreDictionary($l, array_merge($dictionary, $new_core_entries), $lang); } } } return $paths; }
public function test_distance_of_time_in_words_to_now() { $this->assertEqual(DateHelper::distance_of_time_in_words_to_now('2000-02-01 01:00:00'), DateHelper::distance_of_time_in_words('2000-02-01 01:00:00', Ak::time())); }
function getValueForDateColumn($column_name, $value) { if (!$this->isNewRecord()) { if (($column_name == 'updated_on' || $column_name == 'updated_at') && empty($value)) { return null; } } elseif (($column_name == 'created_on' || $column_name == 'created_at') && empty($value)) { return Ak::time(); } elseif ($column_name == 'expires_on' || $column_name == 'expires_at') { return empty($value) ? Ak::getTimestamp('9999-12-31 23:59:59') : Ak::getTimestamp($value); } return Ak::getTimestamp($value); }