Skip to content

Commit

Permalink
Fixes to the duration property
Browse files Browse the repository at this point in the history
  • Loading branch information
dshanske committed Dec 31, 2015
1 parent a5bde6e commit 6398097
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
24 changes: 18 additions & 6 deletions includes/class-kind-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function set_cite($cite) {
}

public function build_time($date, $time, $offset) {
if (! isset($date) ) {
if ( empty($date) ) {
return false;
}
if (empty($time) ) {
Expand Down Expand Up @@ -342,13 +342,25 @@ public static function dateIntervalToString(\DateInterval $interval) {
return $specString;
}

public function get_duration($dt_start, $dt_end) {
if ( isset($this->meta['duration'] ) ) {
public function get_duration() {
if ( array_key_exists('duration', $this->meta) ) {
return $this->meta['duration'];
}
$start = date_create_from_format("Y-m-d\TH:i:sP", $dt_start);
$end = date_create_from_format("Y-m-d\TH:i:sP", $dt_end);
if ( isset($start) && isset($end) ) {
$start = array();
$end = array();
if ( array_key_exists('dt-start', $this->meta) ) {
$start = date_create_from_format("Y-m-d\TH:i:sP", $this->meta['dt-start']);
}
else if (! empty ($this->meta['cite']['published']) ) {
$start = date_create_from_format("Y-m-d\TH:i:sP",$this->meta['cite']['published']);
}
if ( ! empty ( $this->meta['dt-end'] ) ) {
$end = date_create_from_format("Y-m-d\TH:i:sP", $this->meta['dt-end']);
}
else if (! empty ($this->meta['cite']['updated']) ) {
$end = date_create_from_format("Y-m-d\TH:i:sP",$this->meta['cite']['updated']);
}
if ( ($start instanceof DateTime) && ($end instanceof DateTime) ) {
$duration = $start->diff($end);
return self::dateIntervalToString($duration);
}
Expand Down
14 changes: 13 additions & 1 deletion includes/views/kind-default.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
case 'wish':
$content .= 'p-wish';
break;
case 'read':
$content .= 'p-read-of';
break;
case 'quote':
$content .= 'p-in-reply-to';
break;
}
$content .= '">';
$content .= kind_icon($kind);
Expand All @@ -47,7 +53,13 @@
}
$site_name = self::get_site_name( $meta->get_cite(), $meta->get_url() );
if ($site_name) {
$content .= '<em>(' . $site_name . ')</em>';
$content .= '<em>(<span class="p-publication">' . $site_name . '</span>)</em>';
}
if ( in_array( $kind, array('jam', 'listen', 'play', 'read', 'watch') ) ) {
$duration = $meta->get_duration();
if ($duration) {
$content .= '(' . __( 'Duration: ', 'Post kind') . '<span class="p-duration">' . $duration . '</span>)';
}
}
if ($cite) {
$embed = self::get_embed ($meta->get_url());
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ developer of this plugin.
* Start of help system
* Hooks for possible future author data to be stored/retrieved from a nicknames cache
* Activation of the jam post kind, previously reserved.
* Addition of the read post kind, reflecting the reading of a book, as opposed to online content.
* Addition of the read post kind, reflecting having read a book, as opposed to shorter content.
* Reserving of the quote post kind, for excerpting. Will be added in future version
= Version 2.2.1 =
* Minor Tweaks and Bugfixes from changes in 2.2.0.
Expand Down

0 comments on commit 6398097

Please sign in to comment.