-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLBSDatetime.php
62 lines (60 loc) · 1.5 KB
/
LBSDatetime.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
<?php
/**
* Coypright © 2013 Neilsen Chan. All rights reserved.
* Author: chenjinlong
* Date: 5/25/13
* Time: 5:39 PM
* Description: LBSDatetime.php
*/
class LBSDatetime
{
/**
* Get the max day for specific ym
*
* @param $month
* @param $year
* @return int
*/
public static function getMonthLastDay($month, $year) {
switch ($month) {
case 2 :
if ($year % 4 == 0) {
if ($year % 100 == 0) {
$days = $year % 400 == 0 ? 29 : 28;
} else {
$days = 29;
}
} else {
$days = 28;
}
break;
case 4 :
case 6 :
case 9 :
case 11 :
$days = 30;
break;
default :
$days = 31;
break;
}
return $days;
}
/**
* Get a custom date by rule str
*
* @param $dateChangeString
* @param $standarDate
* @return bool|string
* @throws Exception
*/
public static function getCustomDate($dateChangeString, $standarDate)
{
if(preg_match('/^[+-]\d+$/i', $dateChangeString)){
$targetDate = date( "Y-m-d", strtotime(strval($dateChangeString).' day', strtotime($standarDate)));
return $targetDate;
}else{
throw new Exception('Invalid arg[0] of func.');
}
}
}