function parse_effective_date($input, $default_value = NULL, $parse_hint = NULL) { if (isset($parse_hint) and $parse_hint != '') { TTDate::setDateFormat($parse_hint); } return TTDate::parseDateTime($input); }
function parse_transaction_date($input, $default_value = NULL, $parse_hint = NULL, $raw_row = NULL) { if (isset($parse_hint) and $parse_hint != '') { TTDate::setDateFormat($parse_hint); return TTDate::parseDateTime($input); } else { return TTDate::strtotime($input); } }
function test_parseEpoch() { Debug::text('Testing Date Parsing of EPOCH!', __FILE__, __LINE__, __METHOD__, 10); TTDate::setDateFormat('m-d-y'); TTDate::setTimeZone('PST'); TTDate::setTimeFormat('g:i A'); $this->assertEquals(TTDate::parseDateTime(1162670400), (int) 1162670400); TTDate::setDateFormat('Y-m-d'); TTDate::setTimeZone('PST'); TTDate::setTimeFormat('g:i A'); $this->assertEquals(TTDate::parseDateTime(1162670400), (int) 1162670400); $this->assertEquals(TTDate::parseDateTime(600), (int) 600); //Test small epochs that may conflict with 24hr time that just has the time and not a date. $this->assertEquals(TTDate::parseDateTime(1800), (int) 1800); //Test small epochs that may conflict with 24hr time that just has the time and not a date. $this->assertEquals(TTDate::parseDateTime(-600), (int) -600); //Test small epochs that may conflict with 24hr time that just has the time and not a date. $this->assertEquals(TTDate::parseDateTime(-1800), (int) -1800); //Test small epochs that may conflict with 24hr time that just has the time and not a date. }
function test_parseEpoch() { Debug::text('Testing Date Parsing of EPOCH!', __FILE__, __LINE__, __METHOD__, 10); TTDate::setDateFormat('m-d-y'); TTDate::setTimeZone('PST'); TTDate::setTimeFormat('g:i A'); $this->assertEquals(TTDate::parseDateTime(1162670400), (int) 1162670400); TTDate::setDateFormat('Y-m-d'); TTDate::setTimeZone('PST'); TTDate::setTimeFormat('g:i A'); $this->assertEquals(TTDate::parseDateTime(1162670400), (int) 1162670400); }
function parse_time_stamp($input, $default_value = NULL, $parse_hint = NULL) { //Use this to manually force a specific timezone. //TTDate::setTimeZone('GMT'); if (strpos($parse_hint, '#') !== FALSE) { $split_parse_hint = explode('#', $parse_hint); } if (isset($split_parse_hint[0]) and $split_parse_hint[0] != '') { TTDate::setDateFormat($split_parse_hint[0]); } if (isset($split_parse_hint[1]) and $split_parse_hint[1] != '') { TTDate::setTimeFormat($split_parse_hint[1]); } else { TTDate::setTimeFormat('g:i A'); } return TTDate::parseDateTime($input); }
function _postParseRow($row_number, $raw_row) { $raw_row['user_id'] = $this->getUserIdByRowData($raw_row); if ($raw_row['user_id'] == FALSE) { unset($raw_row['user_id']); } //Combine date/time columns together and convert all time_stamp columns into epochs. $column_map = $this->getColumnMap(); //Include columns that should always be there. //Handle one punch per row. if (isset($column_map['time_stamp'])) { Debug::Text('Parsing time_stamp column...', __FILE__, __LINE__, __METHOD__, 10); $date_time_format = $column_map['time_stamp']['parse_hint'] . '_' . $column_map['time_stamp']['parse_hint']; } elseif (!isset($column_map['time_stamp']) and isset($column_map['date']) and isset($column_map['time'])) { Debug::Text('Parsing date/time column...', __FILE__, __LINE__, __METHOD__, 10); //$raw_row['time_stamp'] = $raw_row[$column_map['date']['map_column_name']].' '. $raw_row[$column_map['time']['map_column_name']]; $raw_row['time_stamp'] = $raw_row['date'] . ' ' . $raw_row['time']; $date_time_format = $column_map['date']['parse_hint'] . '_' . $column_map['time']['parse_hint']; unset($raw_row['date'], $raw_row['time']); } else { $date_time_format = 'd-M-y_g:i A T'; } if (isset($raw_row['time_stamp'])) { $split_date_time_format = explode('_', $date_time_format); //Debug::Arr($split_date_time_format, 'Date/Time Format: '. $date_time_format, __FILE__, __LINE__, __METHOD__,10); TTDate::setDateFormat($split_date_time_format[0]); TTDate::setTimeFormat($split_date_time_format[1]); $raw_row['time_stamp'] = TTDate::parseDateTime($raw_row['time_stamp']); } //Debug::Arr($column_map, 'Column Map', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($raw_row, 'Raw Row', __FILE__, __LINE__, __METHOD__,10); //Handle two punches per row. if (isset($column_map['in_time_stamp']) and isset($column_map['out_time_stamp'])) { Debug::Text('Parsing Two punches per row...', __FILE__, __LINE__, __METHOD__, 10); $in_date_time_format = $column_map['in_time_stamp']['parse_hint'] . '_' . $column_map['in_time_stamp']['parse_hint']; $out_date_time_format = $column_map['out_time_stamp']['parse_hint'] . '_' . $column_map['out_time_stamp']['parse_hint']; unset($raw_row['status'], $raw_row['type']); } elseif (!isset($column_map['in_time_stamp']) and !isset($column_map['out_time_stamp']) and isset($column_map['in_punch_date']) and isset($column_map['in_punch_time']) and isset($column_map['out_punch_date']) and isset($column_map['out_punch_time'])) { Debug::Text('Parsing Two punches per row with separte date/time columns...', __FILE__, __LINE__, __METHOD__, 10); $raw_row['in_time_stamp'] = $raw_row['in_punch_date'] . ' ' . $raw_row['in_punch_time']; $in_date_time_format = $column_map['in_punch_date']['parse_hint'] . '_' . $column_map['in_punch_time']['parse_hint']; unset($raw_row['in_punch_date'], $raw_row['in_punch_time']); $raw_row['out_time_stamp'] = $raw_row['out_punch_date'] . ' ' . $raw_row['out_punch_time']; $out_date_time_format = $column_map['out_punch_date']['parse_hint'] . '_' . $column_map['out_punch_time']['parse_hint']; unset($raw_row['out_punch_date'], $raw_row['out_punch_time']); unset($raw_row['status'], $raw_row['type']); } else { $in_date_time_format = $out_date_time_format = $date_time_format = 'd-M-y_g:i A T'; } if (isset($raw_row['in_time_stamp']) and isset($raw_row['out_time_stamp'])) { Debug::Text('bParsing Two punches per row...', __FILE__, __LINE__, __METHOD__, 10); $split_in_date_time_format = explode('_', $in_date_time_format); TTDate::setDateFormat($split_in_date_time_format[0]); TTDate::setTimeFormat($split_in_date_time_format[1]); $raw_row['in_time_stamp'] = TTDate::parseDateTime($raw_row['in_time_stamp']); $split_out_date_time_format = explode('_', $out_date_time_format); TTDate::setDateFormat($split_out_date_time_format[0]); TTDate::setTimeFormat($split_out_date_time_format[1]); $raw_row['out_time_stamp'] = TTDate::parseDateTime($raw_row['out_time_stamp']); } if (!isset($raw_row['in_type']) and !isset($raw_row['out_type']) and !isset($raw_row['type']) and (!isset($raw_row['type_id']) or isset($raw_row['type_id']) and $raw_row['type_id'] == '')) { Debug::Text('Defaulting to normal punch type...', __FILE__, __LINE__, __METHOD__, 10); $raw_row['type_id'] = 10; //Normal } if (!isset($raw_row['in_status']) and !isset($raw_row['out_status']) and !isset($raw_row['status']) and (!isset($raw_row['status_id']) or isset($raw_row['status_id']) and $raw_row['status_id'] == '')) { Debug::Text('Defaulting to IN punch status...', __FILE__, __LINE__, __METHOD__, 10); $raw_row['status_id'] = 10; //IN } if ($this->getImportOptions('disable_rounding') == TRUE) { $raw_row['disable_rounding'] = TRUE; } unset($raw_row['date'], $raw_row['time']); Debug::Arr($raw_row, 'postParse Row: ', __FILE__, __LINE__, __METHOD__, 10); return $raw_row; }
function parse_date($input, $default_value = NULL, $parse_hint = NULL) { if (isset($parse_hint) and $parse_hint != '') { TTDate::setDateFormat($parse_hint); return TTDate::getMiddleDayEpoch(TTDate::parseDateTime($input)); } else { return TTDate::getMiddleDayEpoch(TTDate::strtotime($input)); } }
function setDateTimePreferences() { //TTDate::setTimeZone( $this->getTimeZone() ); if ($this->setTimeZonePreferences() == FALSE) { //In case setting the time zone failed, most likely due to MySQL timezone issues. return FALSE; } TTDate::setDateFormat($this->getDateFormat()); TTDate::setTimeFormat($this->getTimeFormat()); TTDate::setTimeUnitFormat($this->getTimeUnitFormat()); return TRUE; }