aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/datetime.php
blob: 9c9292a8e4ee54d8c0fe7dc0fc845e654a865b0b (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

namespace phpbb;

/**
* phpBB custom extensions to the PHP DateTime class
* This handles the relative formats phpBB employs
*/
class datetime extends \DateTime
{
	/**
	* String used to wrap the date segment which should be replaced by today/tomorrow/yesterday
	*/
	const RELATIVE_WRAPPER = '|';

	/**
	* @var user User who is the context for this DateTime instance
	*/
	protected $user;

	/**
	* @var array Date formats are preprocessed by phpBB, to save constant recalculation they are cached.
	*/
	static protected $format_cache = array();

	/**
	* Constructs a new instance of \phpbb\datetime, expanded to include an argument to inject
	* the user context and modify the timezone to the users selected timezone if one is not set.
	*
	* @param string $time String in a format accepted by strtotime().
	* @param \DateTimeZone $timezone Time zone of the time.
	* @param user $user object for context.
	*/
	public function __construct($user, $time = 'now', \DateTimeZone $timezone = null)
	{
		$this->user	= $user;
		$timezone	= $timezone ?: $this->user->timezone;

		parent::__construct($time, $timezone);
	}

	/**
	* Formats the current date time into the specified format
	*
	* @param string $format Optional format to use for output, defaults to users chosen format
	* @param boolean $force_absolute Force output of a non relative date
	* @return string Formatted date time
	*/
	public function format($format = '', $force_absolute = false)
	{
		$format		= $format ? $format : $this->user->date_format;
		$format		= self::format_cache($format, $this->user);
		$relative	= ($format['is_short'] && !$force_absolute);
		$now		= new self($this->user, 'now', $this->user->timezone);

		$timestamp	= $this->getTimestamp();
		$now_ts		= $now->getTimeStamp();

		$delta		= $now_ts - $timestamp;

		if ($relative)
		{
			/*
			* Check the delta is less than or equal to 1 hour
			* and the delta not more than a minute in the past
			* and the delta is either greater than -5 seconds or timestamp
			* and current time are of the same minute (they must be in the same hour already)
			* finally check that relative dates are supported by the language pack
			*/
			if ($delta <= 3600 && $delta > -60 &&
				($delta >= -5 || (($now_ts / 60) % 60) == (($timestamp / 60) % 60))
				&& isset($this->user->lang['datetime']['AGO']))
			{
				return $this->user->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60)));
			}
			else
			{
				$midnight = clone $now;
				$midnight->setTime(0, 0, 0);

				$midnight	= $midnight->getTimestamp();

				$day = false;

				if ($timestamp > $midnight + 86400)
				{
					$day = 'TOMORROW';
				}
				else if ($timestamp > $midnight)
				{
					$day = 'TODAY';
				}
				else if ($timestamp > $midnight - 86400)
				{
					$day = 'YESTERDAY';
				}

				if ($day !== false)
				{
					// Format using the short formatting and finally swap out the relative token placeholder with the correct value
					return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang']));
				}
			}
		}

		return strtr(parent::format($format['format_long']), $format['lang']);
	}

	/**
	* Magic method to convert DateTime object to string
	*
	* @return string Formatted date time, according to the users default settings.
	*/
	public function __toString()
	{
		return $this->format();
	}

	/**
	* Pre-processes the specified date format
	*
	* @param string $format Output format
	* @param user $user User object to use for localisation
	* @return array Processed date format
	*/
	static protected function format_cache($format, $user)
	{
		$lang = $user->lang_name;

		if (!isset(self::$format_cache[$lang]))
		{
			self::$format_cache[$lang] = array();
		}

		if (!isset(self::$format_cache[$lang][$format]))
		{
			// Is the user requesting a friendly date format (i.e. 'Today 12:42')?
			self::$format_cache[$lang][$format] = array(
				'is_short'		=> strpos($format, self::RELATIVE_WRAPPER) !== false,
				'format_short'	=> substr($format, 0, strpos($format, self::RELATIVE_WRAPPER)) . self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER . substr(strrchr($format, self::RELATIVE_WRAPPER), 1),
				'format_long'	=> str_replace(self::RELATIVE_WRAPPER, '', $format),
				'lang'			=> array_filter($user->lang['datetime'], 'is_string'),
			);

			// Short representation of month in format? Some languages use different terms for the long and short format of May
			if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false))
			{
				self::$format_cache[$lang][$format]['lang']['May'] = $user->lang['datetime']['May_short'];
			}
		}

		return self::$format_cache[$lang][$format];
	}
}
v class='ctx'> msgstr ""
-#: any.pm:857
+#: any.pm:862
#, c-format
msgid "(already added %s)"
msgstr "(%s በፊት ተጨምሯል)"
-#: any.pm:863
+#: any.pm:868
#, c-format
msgid "Please give a user name"
msgstr "እባክዎ የተጠቃሚ ስም ይስጡ"
-#: any.pm:864
+#: any.pm:869
#, c-format
msgid ""
"The user name must start with a lower case letter followed by only lower "
"cased letters, numbers, `-' and `_'"
msgstr ""
-#: any.pm:865
+#: any.pm:870
#, c-format
msgid "The user name is too long"
msgstr "የተጠቃሚ ስሙ በጣም ረጅም ነው"
-#: any.pm:866
+#: any.pm:871
#, c-format
msgid "This user name has already been added"
msgstr "ይህ የተጠቃሚ ስም በፊትም ነበር"
-#: any.pm:872 any.pm:908
+#: any.pm:877 any.pm:913
#, c-format
msgid "User ID"
msgstr "የተጠቃሚ መለያ ቁጥር"
-#: any.pm:872 any.pm:909
+#: any.pm:877 any.pm:914
#, c-format
msgid "Group ID"
msgstr "የብድን መለያ ቁጥር"
-#: any.pm:873
+#: any.pm:878
#, fuzzy, c-format
msgid "%s must be a number"
msgstr "(%f በሰነድ-ስም ይተካል፤ %l በመስመር ቁጥር)"
-#: any.pm:874
+#: any.pm:879
#, c-format
msgid "%s should be above 500. Accept anyway?"
msgstr ""
-#: any.pm:878
+#: any.pm:883
#, fuzzy, c-format
msgid "User management"
msgstr "የተጠቃሚ ስም"
-#: any.pm:883
+#: any.pm:888
#, c-format
msgid "Enable guest account"
msgstr ""
-#: any.pm:884 authentication.pm:239
+#: any.pm:889 authentication.pm:239
#, fuzzy, c-format
msgid "Set administrator (root) password"
msgstr "የroot ሚስጢራዊ ቃል ይምረጡ"
-#: any.pm:890
+#: any.pm:895
#, fuzzy, c-format
msgid "Enter a user"
msgstr ""
"የተጠቃሚ ስም ያስገቡ\n"
"%s"
-#: any.pm:892
+#: any.pm:897
#, c-format
msgid "Icon"
msgstr "ምልክት"
-#: any.pm:895
+#: any.pm:900
#, c-format
msgid "Real name"
msgstr "እውነተኛ ስም"
-#: any.pm:902
+#: any.pm:907
#, fuzzy, c-format
msgid "Login name"
msgstr "Name=ዝምብለህ ይግባ"
-#: any.pm:907
+#: any.pm:912
#, c-format
msgid "Shell"
msgstr "ሼል"
-#: any.pm:950
+#: any.pm:955
#, fuzzy, c-format
msgid "Please wait, adding media..."
msgstr "ሲያትም እባክዎ ይጠብቁ\n"
-#: any.pm:980 security/l10n.pm:14
+#: any.pm:985 security/l10n.pm:14
#, c-format
msgid "Autologin"
msgstr ""
-#: any.pm:981
+#: any.pm:986
#, c-format
msgid "I can set up your computer to automatically log on one user."
msgstr ""
-#: any.pm:982
+#: any.pm:987
#, fuzzy, c-format
msgid "Use this feature"
msgstr "ይህንን ሁኔታ መጠቀም ይፈልጋሉ?"
-#: any.pm:983
+#: any.pm:988
#, c-format
msgid "Choose the default user:"
msgstr "ቀዳሚ ተጠቃሚ ይምረጡ:"
-#: any.pm:984
+#: any.pm:989
#, c-format
msgid "Choose the window manager to run:"
msgstr ""
-#: any.pm:995 any.pm:1015 any.pm:1083
+#: any.pm:1000 any.pm:1020 any.pm:1088
#, c-format
msgid "Release Notes"
msgstr ""
-#: any.pm:1022 any.pm:1371 interactive/gtk.pm:819
+#: any.pm:1027 any.pm:1376 interactive/gtk.pm:819
#, c-format
msgid "Close"
msgstr "ዝጋ"
-#: any.pm:1069
+#: any.pm:1074
#, c-format
msgid "License agreement"
msgstr ""
-#: any.pm:1071 diskdrake/dav.pm:26
+#: any.pm:1076 diskdrake/dav.pm:26
#, c-format
msgid "Quit"
msgstr "ውጣ"
-#: any.pm:1078
+#: any.pm:1083
#, fuzzy, c-format
msgid "Do you accept this license ?"
msgstr "ሌላ አልዎት?"
-#: any.pm:1079
+#: any.pm:1084
#, c-format
msgid "Accept"
msgstr "ተቀበል"
-#: any.pm:1079
+#: any.pm:1084
#, c-format
msgid "Refuse"
msgstr "አትቀበል"
-#: any.pm:1105 any.pm:1167
+#: any.pm:1110 any.pm:1172
#, c-format
msgid "Please choose a language to use"
msgstr "እባክዎ መጠቀሚያ ቋንቋ ይምረጡ።"
-#: any.pm:1133
+#: any.pm:1138
#, c-format
msgid ""
"%s can support multiple languages. Select\n"
@@ -530,82 +530,82 @@ msgid ""
"when your installation is complete and you restart your system."
msgstr ""
-#: any.pm:1135
+#: any.pm:1140
#, c-format
msgid "Mageia"
msgstr ""
-#: any.pm:1136
+#: any.pm:1141
#, c-format
msgid "Multi languages"
msgstr ""
-#: any.pm:1145 any.pm:1176
+#: any.pm:1150 any.pm:1181
#, c-format
msgid "Old compatibility (non UTF-8) encoding"
msgstr ""
-#: any.pm:1146
+#: any.pm:1151
#, c-format
msgid "All languages"
msgstr "ሁሉንም ቋንቋዎች"
-#: any.pm:1168
+#: any.pm:1173
#, fuzzy, c-format
msgid "Language choice"
msgstr "የመመሪያ ገጾች"
-#: any.pm:1222
+#: any.pm:1227
#, c-format
msgid "Country / Region"
msgstr "ሀገር / አካባቢ"
-#: any.pm:1223
+#: any.pm:1228
#, c-format
msgid "Please choose your country"
msgstr "እባክዎ ሀገሮን ይምረጡ።"
-#: any.pm:1225
+#: any.pm:1230
#, c-format
msgid "Here is the full list of available countries"
msgstr "እዚህ ያሉት ሀገሮች ሙሉ ዝርዝር ይገኛል"
-#: any.pm:1226
+#: any.pm:1231
#, fuzzy, c-format
msgid "Other Countries"
msgstr "ሌላ ምርጫዎች"
-#: any.pm:1226 interactive.pm:488 interactive/gtk.pm:445
+#: any.pm:1231 interactive.pm:488 interactive/gtk.pm:445
#, c-format
msgid "Advanced"
msgstr "ጠላቂ"
-#: any.pm:1232
+#: any.pm:1237
#, fuzzy, c-format
msgid "Input method:"
msgstr "የX ዘገባ የማስትገባት ዘዴ"
-#: any.pm:1235
+#: any.pm:1240
#, c-format
msgid "None"
msgstr "ምንም"
-#: any.pm:1316
+#: any.pm:1321
#, c-format
msgid "No sharing"
msgstr "መጋራት የለም"
-#: any.pm:1316
+#: any.pm:1321
#, c-format
msgid "Allow all users"
msgstr "ለሁሉም ተጠቃሚዎች ፍቀድ"
-#: any.pm:1316
+#: any.pm:1321
#, c-format
msgid "Custom"
msgstr "ምርጫ"
-#: any.pm:1320
+#: any.pm:1325
#, c-format
msgid ""
"Would you like to allow users to share some of their directories?\n"
@@ -615,86 +615,86 @@ msgid ""
"\"Custom\" permit a per-user granularity.\n"
msgstr ""
-#: any.pm:1332
+#: any.pm:1337
#, c-format
msgid ""
"NFS: the traditional Unix file sharing system, with less support on Mac and "
"Windows."
msgstr ""
-#: any.pm:1335
+#: any.pm:1340
#, c-format
msgid ""
"SMB: a file sharing system used by Windows, Mac OS X and many modern Linux "
"systems."
msgstr ""
-#: any.pm:1343
+#: any.pm:1348
#, c-format
msgid ""
"You can export using NFS or SMB. Please select which you would like to use."
msgstr ""
-#: any.pm:1371
+#: any.pm:1376
#, c-format
msgid "Launch userdrake"
msgstr "userdrake አስጀምር"
-#: any.pm:1373
+#: any.pm:1378
#, c-format
msgid ""
"The per-user sharing uses the group \"fileshare\". \n"
"You can use userdrake to add a user to this group."
msgstr ""
-#: any.pm:1480
+#: any.pm:1485
#, c-format
msgid ""
"You need to logout and back in again for changes to take effect. Press OK to "
"logout now."
msgstr ""
-#: any.pm:1484
+#: any.pm:1489
#, c-format
msgid "You need to log out and back in again for changes to take effect"
msgstr ""
-#: any.pm:1519
+#: any.pm:1524
#, c-format
msgid "Timezone"
msgstr "የሰአት ክልል"
-#: any.pm:1519
+#: any.pm:1524
#, c-format
msgid "Which is your timezone?"
msgstr "የሰአት ክልሎት የትኛው ነው?"
-#: any.pm:1542 any.pm:1544
+#: any.pm:1547 any.pm:1549
#, c-format
msgid "Date, Clock & Time Zone Settings"
msgstr ""
-#: any.pm:1545
+#: any.pm:1550
#, c-format
msgid "What is the best time?"
msgstr ""
-#: any.pm:1549
+#: any.pm:1554
#, fuzzy, c-format
msgid "%s (hardware clock set to UTC)"
msgstr "ለሀርድዌር ሰአት GMT ተመርጧል"
-#: any.pm:1550
+#: any.pm:1555
#, fuzzy, c-format
msgid "%s (hardware clock set to local time)"
msgstr "ለሀርድዌር ሰአት GMT ተመርጧል"
-#: any.pm:1552
+#: any.pm:1557
#, c-format
msgid "NTP Server"
msgstr "NTP ሰርቨር"
-#: any.pm:1553
+#: any.pm:1558
#, c-format
msgid "Automatic time synchronization (using NTP)"
msgstr ""