XOOPS RMCommon Utilities
2.1.8.91RC
Main Page
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
timeformatter.php
Go to the documentation of this file.
1
<?php
2
// $Id: timeformatter.php 1056 2012-09-12 15:43:20Z i.bitcero $
3
// --------------------------------------------------------------
4
// Red México Common Utilities
5
// A framework for Red México Modules
6
// Author: Eduardo Cortés <i.bitcero@gmail.com>
7
// Email: i.bitcero@gmail.com
8
// License: GPL 2.0
9
// --------------------------------------------------------------
10
11
class
RMTimeFormatter
12
{
13
private
$time
= 0;
14
private
$format
=
''
;
15
23
function
__construct
(
$time
=0,
$format
=
''
){
24
$this->time =
$time
;
25
$this->
format
=
$format
;
26
}
27
31
public
function
get
(){
32
static
$instance;
33
34
if
(!isset($instance)) {
35
$instance =
new
RMTimeFormatter
();
36
}
37
38
return
$instance;
39
}
40
41
public
function
format
(
$time
=0,
$format
=
''
){
42
43
$time
=
$time
<=0 ? $this->time :
$time
;
44
$format
=
$format
==
''
? $this->
format
:
$format
;
45
46
if
(
$format
==
''
||
$time
<0){
47
trigger_error(
__
(
'You must provide a valid time and format value to use RMTimeFormatter::format() method'
,
'rmcommon'
));
48
return
;
49
}
50
51
$find = array(
52
'%d%'
,
// Day number
53
'%D%'
,
// Day name
54
'%m%'
,
// Month number
55
'%M%'
,
// Month name
56
'%T%'
,
// Month three letters
57
'%y%'
,
// Year with two digits (e.g. 04, 05, etc.)
58
'%Y%'
,
// Year with four digits (e.g. 2004, 2005, etc.)
59
'%h%'
,
// Hour
60
'%i%'
,
// Minute
61
'%s%'
// Second
62
);
63
64
$replace = array(
65
date(
'd'
,
$time
),
66
$this->
days
(
$time
),
67
date(
'm'
,
$time
),
68
$this->
months
(
$time
),
69
substr($this->
months
(
$time
), 0, 3),
70
date(
'y'
,
$time
),
71
date(
'Y'
,
$time
),
72
date(
'H'
,
$time
),
73
date(
'i'
,
$time
),
74
date(
's'
,
$time
)
75
);
76
77
return
str_replace($find, $replace,
$format
);
78
79
}
80
87
public
function
days
(
$time
= 0){
88
89
$time
=
$time
<=0 ? $this->time :
$time
;
90
if
(
$time
<=0)
return
;
91
92
$days = array(
93
__
(
'Sunday'
,
'rmcommon'
),
94
__
(
'Monday'
,
'rmcommon'
),
95
__
(
'Tuesday'
,
'rmcommon'
),
96
__
(
'Wednesday'
,
'rmcommon'
),
97
__
(
'Thursday'
,
'rmcommon'
),
98
__
(
'Friday'
,
'rmcommon'
),
99
__
(
'Saturday'
,
'rmcommon'
)
100
);
101
102
return
$days[date(
"w"
,
$time
)];
103
104
}
105
106
public
function
months
(
$time
=0){
107
$time
=
$time
<=0 ? $this->time :
$time
;
108
if
(
$time
<=0)
return
;
109
110
$months = array(
111
__
(
'January'
,
'rmcommon'
),
112
__
(
'February'
,
'rmcommon'
),
113
__
(
'March'
,
'rmcommon'
),
114
__
(
'April'
,
'rmcommon'
),
115
__
(
'May'
,
'rmcommon'
),
116
__
(
'June'
,
'rmcommon'
),
117
__
(
'July'
,
'rmcommon'
),
118
__
(
'August'
,
'rmcommon'
),
119
__
(
'September'
,
'rmcommon'
),
120
__
(
'October'
,
'rmcommon'
),
121
__
(
'November'
,
'rmcommon'
),
122
__
(
'December'
,
'rmcommon'
),
123
);
124
125
return
$months[date(
'n'
,
$time
)-1];
126
127
}
128
129
130
}
L:
XOOPS_Allure
SVN_XOOPS2
RMC
rmcommon
trunk
rmcommon
class
timeformatter.php
Generated on Sun Mar 17 2013 20:41:07 for XOOPS RMCommon Utilities by
1.8.3.1