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

Language PHP Lines 102
MD5 Hash cf9e0eb2f3a384ceb4ba22bb2df2a974 Estimated Cost $1,334 (why?)
Repository https://bitbucket.org/alexandrul/flatpress View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
<?php

	function date_strformat($format, $timestamp=0) {
		global $lang;

		// D l day
		
		if ( strpos($format, '%a') !== false ) {
			$i = strftime('%w', $timestamp);
			$format = str_replace('%a', $lang['date']['weekday_abbr'][$i], $format);
		}
		
		if ( strpos($format, '%A') !== false  ) {
			$i = strftime('%w', $timestamp);
			$format = str_replace('%A', $lang['date']['weekday'][$i], $format);
		}
		
		
		// F M month
		
		if ( strpos($format, '%b') !== false  ) {
			$i = intval(strftime('%m', $timestamp))-1;
			$format = str_replace('%b', $lang['date']['month_abbr'][$i], $format);
		}
		
		
		if ( strpos($format, '%B') !== false  ) {
			$i = intval(strftime('%m', $timestamp))-1;
			$format = str_replace('%B', $lang['date']['month'][$i], $format);
		}
		
			if (DIRECTORY_SEPARATOR == '\\') {
			$_win_from = array('%D',       '%h', '%n', '%r',          '%R',    '%t', '%T');
			$_win_to   = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
				if (strpos($format, '%e') !== false) {
					$_win_from[] = '%e';
					$_win_to[]   = sprintf('%\' 2d', date('j', $timestamp));
				}
				if (strpos($format, '%l') !== false) {
					$_win_from[] = '%l';
					$_win_to[]   = sprintf('%\' 2d', date('h', $timestamp));
				}
				$format = str_replace($_win_from, $_win_to, $format);
			}
		
		return strftime($format, $timestamp);
	
		
	}

	function date_time($offset=null) {
		global $fp_config;
		if (is_null($offset)) {
			$offset = $fp_config['locale']['timeoffset'];
		}
		$timestamp = time();
		return $timestamp + $offset * 3600;
	}


	/*
	function date_now($offset=0) {	
		$timestamp = gmtime();
		$time_stamp = intval($timestamp) + intval($offset) * 60 * 60;
		return date($format, $time_stamp);
	
	}
	*/
	
	// I really DON'T LIKE THIS, looks like an hack, yech...
	// Takes filename and extension as a parameter, strips
	// alphabetic chars (ascii) from filename and "parses" the date;
	// In fact it's just a substr, counting on the fact filename should be
	// "prefix%y%m%d-%H%M%S.ext"
	function date_from_id($id) {
			
			
			$strdate = substr($id, -13);
			
			if (!preg_match('/[0-9]{6}-[0-9]{6}/', $strdate))
				return array();
			
			$arr[ 'y' ] = substr($strdate, 0, 2);
			$arr[ 'm' ] = substr($strdate, 2, 2);
			$arr[ 'd' ] = substr($strdate, 4, 2);
			
			$arr[ 'H' ] = substr($strdate, 7, 2);
			$arr[ 'M' ] = substr($strdate, 9, 2);
			$arr[ 'S' ] = substr($strdate, 11, 2);
			
			$arr['ymd'] = $arr['y'] . $arr['m'] . $arr['d'];
			$arr['HMS'] = $arr['H'] . $arr['M'] . $arr['S'];
			
			$arr['time'] = mktime($arr['H'], $arr['M'], $arr['S'],
					$arr['m'], $arr['d'], $arr['y']);
			
		return $arr;
		
	}
	
?>
Back to Top