Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
96e50890
Commit
96e50890
authored
8 years ago
by
twistor
Committed by
Chris Leppanen
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #2225019 by twistor: Make FeedsDateTime stringable
parent
68c0e1cd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/FeedsParser.inc
+43
-16
43 additions, 16 deletions
plugins/FeedsParser.inc
with
43 additions
and
16 deletions
plugins/FeedsParser.inc
+
43
−
16
View file @
96e50890
...
@@ -685,24 +685,11 @@ class FeedsDateTime extends DateTime {
...
@@ -685,24 +685,11 @@ class FeedsDateTime extends DateTime {
private
$_serialized_timezone
;
private
$_serialized_timezone
;
/**
/**
* Helper function to prepare the object during serialization.
* The original time value passed into the constructor.
*
* We are extending a core class and core classes cannot be serialized.
*
*
* Ref: http://bugs.php.net/41334, http://bugs.php.net/39821
* @var mixed
*/
public
function
__sleep
()
{
$this
->
_serialized_time
=
$this
->
format
(
'c'
);
$this
->
_serialized_timezone
=
$this
->
getTimezone
()
->
getName
();
return
array
(
'_serialized_time'
,
'_serialized_timezone'
);
}
/**
* Upon unserializing, we must re-build ourselves using local variables.
*/
*/
public
function
__wakeup
()
{
protected
$originalValue
;
$this
->
__construct
(
$this
->
_serialized_time
,
new
DateTimeZone
(
$this
->
_serialized_timezone
));
}
/**
/**
* Overridden constructor.
* Overridden constructor.
...
@@ -714,6 +701,8 @@ class FeedsDateTime extends DateTime {
...
@@ -714,6 +701,8 @@ class FeedsDateTime extends DateTime {
* PHP DateTimeZone object, NULL allowed
* PHP DateTimeZone object, NULL allowed
*/
*/
public
function
__construct
(
$time
=
''
,
$tz
=
NULL
)
{
public
function
__construct
(
$time
=
''
,
$tz
=
NULL
)
{
$this
->
originalValue
=
$time
;
if
(
is_numeric
(
$time
))
{
if
(
is_numeric
(
$time
))
{
// Assume UNIX timestamp if it doesn't look like a simple year.
// Assume UNIX timestamp if it doesn't look like a simple year.
if
(
strlen
(
$time
)
>
4
)
{
if
(
strlen
(
$time
)
>
4
)
{
...
@@ -751,6 +740,43 @@ class FeedsDateTime extends DateTime {
...
@@ -751,6 +740,43 @@ class FeedsDateTime extends DateTime {
$this
->
setGranularityFromTime
(
$time
,
$tz
);
$this
->
setGranularityFromTime
(
$time
,
$tz
);
}
}
/**
* Helper function to prepare the object during serialization.
*
* We are extending a core class and core classes cannot be serialized.
*
* Ref: http://bugs.php.net/41334, http://bugs.php.net/39821
*/
public
function
__sleep
()
{
$this
->
_serialized_time
=
$this
->
format
(
'c'
);
$this
->
_serialized_timezone
=
$this
->
getTimezone
()
->
getName
();
return
array
(
'_serialized_time'
,
'_serialized_timezone'
);
}
/**
* Upon unserializing, we must re-build ourselves using local variables.
*/
public
function
__wakeup
()
{
$this
->
__construct
(
$this
->
_serialized_time
,
new
DateTimeZone
(
$this
->
_serialized_timezone
));
}
/**
* Returns the string representation.
*
* Will try to use the literal input, if that is a string. Fallsback to
* ISO-8601.
*
* @return string
* The string version of this DateTime object.
*/
public
function
__toString
()
{
if
(
is_scalar
(
$this
->
originalValue
))
{
return
(
string
)
$this
->
originalValue
;
}
return
$this
->
format
(
'Y-m-d\TH:i:sO'
);
}
/**
/**
* This function will keep this object's values by default.
* This function will keep this object's values by default.
*/
*/
...
@@ -865,6 +891,7 @@ class FeedsDateTime extends DateTime {
...
@@ -865,6 +891,7 @@ class FeedsDateTime extends DateTime {
protected
function
toArray
()
{
protected
function
toArray
()
{
return
array
(
'year'
=>
$this
->
format
(
'Y'
),
'month'
=>
$this
->
format
(
'm'
),
'day'
=>
$this
->
format
(
'd'
),
'hour'
=>
$this
->
format
(
'H'
),
'minute'
=>
$this
->
format
(
'i'
),
'second'
=>
$this
->
format
(
's'
),
'zone'
=>
$this
->
format
(
'e'
));
return
array
(
'year'
=>
$this
->
format
(
'Y'
),
'month'
=>
$this
->
format
(
'm'
),
'day'
=>
$this
->
format
(
'd'
),
'hour'
=>
$this
->
format
(
'H'
),
'minute'
=>
$this
->
format
(
'i'
),
'second'
=>
$this
->
format
(
's'
),
'zone'
=>
$this
->
format
(
'e'
));
}
}
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment