Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
c525d860
Commit
c525d860
authored
Jan 13, 2012
by
stefanooldeman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add docs to methods and simplify condition on DateTime
parent
187564e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
13 deletions
+31
-13
library/Solarium/Query/Helper.php
library/Solarium/Query/Helper.php
+31
-13
No files found.
library/Solarium/Query/Helper.php
View file @
c525d860
...
...
@@ -123,29 +123,30 @@ class Solarium_Query_Helper
return
'"'
.
preg_replace
(
'/("|\\\)/'
,
'\\\$1'
,
$input
)
.
'"'
;
}
protected
function
isTimestamp
(
$timestamp
)
{
try
{
new
DateTime
(
$timestamp
);
}
catch
(
Exception
$e
)
{
return
false
;
}
return
true
;
}
/**
* Format a date to the expected formatting used in SOLR
*
* This format was derived to be standards compliant (ISO 8601)
* A date field shall be of the form 1995-12-31T23:59:59Z The trailing "Z" designates UTC time and is mandatory
*
* @see http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html
*
* @param mixed $input accepted formats: timestamp, date string or DateTime
* @return string or false when input is invalid
*/
public
function
formatDate
(
$input
)
{
switch
(
true
)
{
case
is_numeric
(
$input
)
&&
$this
->
isTimestamp
(
$input
)
:
case
is_numeric
(
$input
)
&&
$this
->
_
isTimestamp
(
$input
)
:
$dateTime
=
new
DateTime
(
$input
);
break
;
case
is_string
(
$input
)
&&
$this
->
isTimestamp
(
strtotime
(
$input
))
:
case
is_string
(
$input
)
&&
$this
->
_
isTimestamp
(
strtotime
(
$input
))
:
$dateTime
=
new
DateTime
(
strtotime
(
$input
));
break
;
case
!
is_string
(
$input
)
&&
!
is_numeric
(
$input
)
&&
$input
instanceof
DateTime
:
case
$input
instanceof
DateTime
:
$dateTime
=
$input
;
break
;
...
...
@@ -160,6 +161,23 @@ class Solarium_Query_Helper
return
$iso8601
;
}
/**
* Validate if date is valid
* note: do not use checkdate() and support negative timestamps
*
* @return boolean
*/
protected
function
_isTimestamp
(
$timestamp
)
{
try
{
new
DateTime
(
$timestamp
);
}
catch
(
Exception
$e
)
{
return
false
;
}
return
true
;
}
/**
* Render a range query
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment