-
Notifications
You must be signed in to change notification settings - Fork 0
/
deal_time.php
161 lines (145 loc) · 3.75 KB
/
deal_time.php
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
<?php
/**
* process date
* @author huntstack
* @time 2014-10-18
*/
class Process_Date{
private $date;
private $M,$D,$Y;
/**
* set the date for next operator
* @parameter date:time string or timestamp
*/
function __construct($date=""){
if($date == "" || empty($date)){
$this->date = strtotime("now");
}else if(gettype($date) == "string"){
$this->date = strtotime($date);
}else if(gettype($date) == "integer"){
$this->date = $date;
}else{
throw new Exception("paramter must be timestamp or date string or empty for current time");
}
$this->set_varibales();
}
public function set_date($date){
$this->date = strtotime($date);
$this->set_varibales();
}
private function set_varibales(){
$this->M = date("m",$this->date);
$this->D = date("d",$this->date);
$this->Y = date("Y",$this->date);
}
/**
* get the specified weeks
* @parameter $i:numbers of week
* @parameter $flag:0->last,1->next
*/
public function get_week($i=0,$flag=1){
if($flag == 0) return date("YW",strtotime("-$i week",$this->date));
else if($flag == 1) return date("YW",strtotime("+$i week",$this->date));
}
/**
* get the specified months
* @parameter $i:numbers of month
* @parameter $flag:0->last,1->next
*/
public function get_month($i=0,$flag=1){
if($flag == 0) return date("Y-m",mktime(0,0,0, $this->M-$i, 1, $this->Y));
else if($flag == 1) return date("Y-m",mktime(0,0,0, $this->M+$i, 1, $this->Y));
}
/**
* get the specified days
* @parameter $i:numbers of day
* @parameter $flag:0->last,1->next
*/
public function get_day($i=0,$flag=1){
if($flag == 0) return date("Y-m-d",mktime(0,0,0, $this->M, $this->D-$i, $this->Y));
else if($flag == 1) return date("Y-m-d",mktime(0,0,0, $this->M, $this->D+$i, $this->Y));
}
/**
* get the last $count days
* @parameter count:number
*/
public function get_last_days($count){
$return = array();
for($i=1;$i<=$count;$i++){
array_push($return, $this->get_day($i,0));
}
return $return;
}
/**
* get the next $count days
* @parameter count:number
*/
public function get_next_days($count){
$return = array();
for($i=1;$i<=$count;$i++){
array_push($return, $this->get_day($i,1));
}
return $return;
}
/**
* get the last $count weeks
* @parameter count:number
*/
public function get_last_weeks($count){
$return = array();
for($i=1;$i<=$count;$i++){
array_push($return, $this->get_week($i,0));
}
return $return;
}
/**
* get the next $count weeks
* @parameter count:number
*/
public function get_next_weeks($count){
$return = array();
for($i=1;$i<=$count;$i++){
array_push($return, $this->get_week($i,1));
}
return $return;
}
/**
* get the last $count months
* @parameter count:number
*/
public function get_last_month($count){
$return = array();
for($i=1;$i<=$count;$i++){
array_push($return, $this->get_month($i,0));
}
return $return;
}
/**
* get the next $count months
* @parameter count:number
*/
public function get_next_month($count){
$return = array();
for($i=1;$i<=$count;$i++){
array_push($return, $this->get_month($i,1));
}
return $return;
}
/**
* get the first day and the last day of a week
*/
public function get_week_begin_end(){
$return["begin"] = mktime(0,0,0, $this->M, $this->D-date("w",$this->date)+1, $this->Y);
$return["end"] = mktime(23,59,59, $this->M, $this->D-date("w",$this->date)+7, $this->Y);
return $return;
}
/**
* get the first day and the last day of a month
*/
public function get_month_begin_end(){
$return["begin"] = strtotime("first day of",$this->date);
$return["end"] = strtotime("last day of",$this->date);
return $return;
}
}
?>