CcSchedule.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /**
  3. * Skeleton subclass for representing a row from the 'cc_schedule' table.
  4. *
  5. *
  6. *
  7. * You should add additional methods to this class to meet the
  8. * application requirements. This class will only be generated as
  9. * long as it does not already exist in the output directory.
  10. *
  11. * @package propel.generator.airtime
  12. */
  13. class CcSchedule extends BaseCcSchedule {
  14. /**
  15. * Get the [optionally formatted] temporal [starts] column value.
  16. *
  17. *
  18. * @param string $format The date/time format string (either date()-style or strftime()-style).
  19. * If format is NULL, then the raw DateTime object will be returned.
  20. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  21. * @throws PropelException - if unable to parse/validate the date/time value.
  22. */
  23. public function getDbStarts($format = 'Y-m-d H:i:s.u')
  24. {
  25. if ($this->starts === null) {
  26. return null;
  27. }
  28. try {
  29. $dt = new DateTime($this->starts, new DateTimeZone("UTC"));
  30. } catch (Exception $x) {
  31. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x);
  32. }
  33. if ($format === null) {
  34. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  35. return $dt;
  36. } elseif (strpos($format, '%') !== false) {
  37. return strftime($format, $dt->format('U'));
  38. } else {
  39. return $dt->format($format);
  40. }
  41. }
  42. /**
  43. * Get the [optionally formatted] temporal [ends] column value.
  44. *
  45. *
  46. * @param string $format The date/time format string (either date()-style or strftime()-style).
  47. * If format is NULL, then the raw DateTime object will be returned.
  48. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  49. * @throws PropelException - if unable to parse/validate the date/time value.
  50. */
  51. public function getDbEnds($format = 'Y-m-d H:i:s.u')
  52. {
  53. if ($this->ends === null) {
  54. return null;
  55. }
  56. try {
  57. $dt = new DateTime($this->ends, new DateTimeZone("UTC"));
  58. } catch (Exception $x) {
  59. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x);
  60. }
  61. if ($format === null) {
  62. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  63. return $dt;
  64. } elseif (strpos($format, '%') !== false) {
  65. return strftime($format, $dt->format('U'));
  66. } else {
  67. return $dt->format($format);
  68. }
  69. }
  70. /**
  71. * Get the [optionally formatted] temporal [fadein] column value.
  72. *
  73. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  74. * @throws PropelException - if unable to parse/validate the date/time value.
  75. */
  76. public function getDbFadeIn($format = "s.u")
  77. {
  78. return parent::getDbFadein($format);
  79. }
  80. /**
  81. * Get the [optionally formatted] temporal [fadein] column value.
  82. *
  83. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  84. * @throws PropelException - if unable to parse/validate the date/time value.
  85. */
  86. public function getDbFadeOut($format = "s.u")
  87. {
  88. return parent::getDbFadeout($format);
  89. }
  90. /**
  91. *
  92. * @param String in format SS.uuuuuu, Datetime, or DateTime accepted string.
  93. *
  94. * @return CcPlaylistcontents The current object (for fluent API support)
  95. */
  96. public function setDbFadeIn($v)
  97. {
  98. $microsecond = 0;
  99. if ($v instanceof DateTime) {
  100. $dt = $v;
  101. }
  102. else if (preg_match('/^[0-9]{1,2}(\.\d{1,6})?$/', $v)) {
  103. // in php 5.3.2 createFromFormat() with "u" is not supported(bug)
  104. // Hence we need to do parsing.
  105. $info = explode('.', $v);
  106. $microsecond = $info[1];
  107. $dt = DateTime::createFromFormat("s", $info[0]);
  108. }
  109. else {
  110. try {
  111. $dt = new DateTime($v);
  112. } catch (Exception $x) {
  113. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  114. }
  115. }
  116. if ($microsecond == 0) {
  117. $this->fade_in = $dt->format('H:i:s.u');
  118. } else {
  119. $this->fade_in = $dt->format('H:i:s').".".$microsecond;
  120. }
  121. $this->modifiedColumns[] = CcSchedulePeer::FADE_IN;
  122. return $this;
  123. } // setDbFadein()
  124. /**
  125. *
  126. * @param String in format SS.uuuuuu, Datetime, or DateTime accepted string.
  127. *
  128. * @return CcPlaylistcontents The current object (for fluent API support)
  129. */
  130. public function setDbFadeOut($v)
  131. {
  132. $microsecond = 0;
  133. if ($v instanceof DateTime) {
  134. $dt = $v;
  135. }
  136. else if (preg_match('/^[0-9]{1,2}(\.\d{1,6})?$/', $v)) {
  137. // in php 5.3.2 createFromFormat() with "u" is not supported(bug)
  138. // Hence we need to do parsing.
  139. $info = explode('.', $v);
  140. $microsecond = $info[1];
  141. $dt = DateTime::createFromFormat("s", $info[0]);
  142. }
  143. else {
  144. try {
  145. $dt = new DateTime($v);
  146. } catch (Exception $x) {
  147. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  148. }
  149. }
  150. if ($microsecond == 0) {
  151. $this->fade_out = $dt->format('H:i:s.u');
  152. } else {
  153. $this->fade_out = $dt->format('H:i:s').".".$microsecond;
  154. }
  155. $this->modifiedColumns[] = CcSchedulePeer::FADE_OUT;
  156. return $this;
  157. } // setDbFadeout()
  158. /**
  159. * Sets the value of [starts] column to a normalized version of the date/time value specified.
  160. *
  161. * @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
  162. * be treated as NULL for temporal objects.
  163. * @return CcSchedule The current object (for fluent API support)
  164. */
  165. public function setDbStarts($v)
  166. {
  167. $utcTimeZone = new DateTimeZone('UTC');
  168. if ($v instanceof DateTime) {
  169. $dt = $v;
  170. $dt->setTimezone($utcTimeZone);
  171. } else {
  172. // some string/numeric value passed; we normalize that so that we can
  173. // validate it.
  174. try {
  175. if (is_numeric($v)) { // if it's a unix timestamp
  176. $dt = new DateTime('@'.$v, $utcTimeZone);
  177. } else {
  178. $dt = new DateTime($v, $utcTimeZone);
  179. }
  180. } catch (Exception $x) {
  181. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  182. }
  183. }
  184. $this->starts = ($dt ? $dt->format('Y-m-d H:i:s.u') : null);
  185. $this->modifiedColumns[] = CcSchedulePeer::STARTS;
  186. return $this;
  187. } // setDbStarts()
  188. /**
  189. * Sets the value of [ends] column to a normalized version of the date/time value specified.
  190. *
  191. * @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
  192. * be treated as NULL for temporal objects.
  193. * @return CcSchedule The current object (for fluent API support)
  194. */
  195. public function setDbEnds($v)
  196. {
  197. $utcTimeZone = new DateTimeZone('UTC');
  198. if ($v instanceof DateTime) {
  199. $dt = $v;
  200. $dt->setTimezone($utcTimeZone);
  201. } else {
  202. // some string/numeric value passed; we normalize that so that we can
  203. // validate it.
  204. try {
  205. if (is_numeric($v)) { // if it's a unix timestamp
  206. $dt = new DateTime('@'.$v, $utcTimeZone);
  207. } else {
  208. $dt = new DateTime($v, $utcTimeZone);
  209. }
  210. } catch (Exception $x) {
  211. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  212. }
  213. }
  214. $this->ends = ($dt ? $dt->format('Y-m-d H:i:s.u') : null);
  215. $this->modifiedColumns[] = CcSchedulePeer::ENDS;
  216. return $this;
  217. } // setDbEnds()
  218. public function isCurrentItem($epochNow = null) {
  219. if (is_null($epochNow)) {
  220. $epochNow = microtime(true);
  221. }
  222. $epochStart = floatval($this->getDbStarts('U.u'));
  223. $epochEnd = floatval($this->getDbEnds('U.u'));
  224. if ($epochStart < $epochNow && $epochEnd > $epochNow) {
  225. return true;
  226. }
  227. return false;
  228. }
  229. } // CcSchedule