Duration.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. # Generated by the protocol buffer compiler. DO NOT EDIT!
  3. # source: google/protobuf/duration.proto
  4. namespace Google\Protobuf;
  5. use Google\Protobuf\Internal\GPBType;
  6. use Google\Protobuf\Internal\RepeatedField;
  7. use Google\Protobuf\Internal\GPBUtil;
  8. /**
  9. * A Duration represents a signed, fixed-length span of time represented
  10. * as a count of seconds and fractions of seconds at nanosecond
  11. * resolution. It is independent of any calendar and concepts like "day"
  12. * or "month". It is related to Timestamp in that the difference between
  13. * two Timestamp values is a Duration and it can be added or subtracted
  14. * from a Timestamp. Range is approximately +-10,000 years.
  15. * # Examples
  16. * Example 1: Compute Duration from two Timestamps in pseudo code.
  17. * Timestamp start = ...;
  18. * Timestamp end = ...;
  19. * Duration duration = ...;
  20. * duration.seconds = end.seconds - start.seconds;
  21. * duration.nanos = end.nanos - start.nanos;
  22. * if (duration.seconds < 0 && duration.nanos > 0) {
  23. * duration.seconds += 1;
  24. * duration.nanos -= 1000000000;
  25. * } else if (duration.seconds > 0 && duration.nanos < 0) {
  26. * duration.seconds -= 1;
  27. * duration.nanos += 1000000000;
  28. * }
  29. * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
  30. * Timestamp start = ...;
  31. * Duration duration = ...;
  32. * Timestamp end = ...;
  33. * end.seconds = start.seconds + duration.seconds;
  34. * end.nanos = start.nanos + duration.nanos;
  35. * if (end.nanos < 0) {
  36. * end.seconds -= 1;
  37. * end.nanos += 1000000000;
  38. * } else if (end.nanos >= 1000000000) {
  39. * end.seconds += 1;
  40. * end.nanos -= 1000000000;
  41. * }
  42. * Example 3: Compute Duration from datetime.timedelta in Python.
  43. * td = datetime.timedelta(days=3, minutes=10)
  44. * duration = Duration()
  45. * duration.FromTimedelta(td)
  46. * # JSON Mapping
  47. * In JSON format, the Duration type is encoded as a string rather than an
  48. * object, where the string ends in the suffix "s" (indicating seconds) and
  49. * is preceded by the number of seconds, with nanoseconds expressed as
  50. * fractional seconds. For example, 3 seconds with 0 nanoseconds should be
  51. * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
  52. * be expressed in JSON format as "3.000000001s", and 3 seconds and 1
  53. * microsecond should be expressed in JSON format as "3.000001s".
  54. *
  55. * Generated from protobuf message <code>google.protobuf.Duration</code>
  56. */
  57. class Duration extends \Google\Protobuf\Internal\Message
  58. {
  59. /**
  60. * Signed seconds of the span of time. Must be from -315,576,000,000
  61. * to +315,576,000,000 inclusive. Note: these bounds are computed from:
  62. * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
  63. *
  64. * Generated from protobuf field <code>int64 seconds = 1;</code>
  65. */
  66. protected $seconds = 0;
  67. /**
  68. * Signed fractions of a second at nanosecond resolution of the span
  69. * of time. Durations less than one second are represented with a 0
  70. * `seconds` field and a positive or negative `nanos` field. For durations
  71. * of one second or more, a non-zero value for the `nanos` field must be
  72. * of the same sign as the `seconds` field. Must be from -999,999,999
  73. * to +999,999,999 inclusive.
  74. *
  75. * Generated from protobuf field <code>int32 nanos = 2;</code>
  76. */
  77. protected $nanos = 0;
  78. /**
  79. * Constructor.
  80. *
  81. * @param array $data {
  82. * Optional. Data for populating the Message object.
  83. *
  84. * @type int|string $seconds
  85. * Signed seconds of the span of time. Must be from -315,576,000,000
  86. * to +315,576,000,000 inclusive. Note: these bounds are computed from:
  87. * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
  88. * @type int $nanos
  89. * Signed fractions of a second at nanosecond resolution of the span
  90. * of time. Durations less than one second are represented with a 0
  91. * `seconds` field and a positive or negative `nanos` field. For durations
  92. * of one second or more, a non-zero value for the `nanos` field must be
  93. * of the same sign as the `seconds` field. Must be from -999,999,999
  94. * to +999,999,999 inclusive.
  95. * }
  96. */
  97. public function __construct($data = NULL) {
  98. \GPBMetadata\Google\Protobuf\Duration::initOnce();
  99. parent::__construct($data);
  100. }
  101. /**
  102. * Signed seconds of the span of time. Must be from -315,576,000,000
  103. * to +315,576,000,000 inclusive. Note: these bounds are computed from:
  104. * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
  105. *
  106. * Generated from protobuf field <code>int64 seconds = 1;</code>
  107. * @return int|string
  108. */
  109. public function getSeconds()
  110. {
  111. return $this->seconds;
  112. }
  113. /**
  114. * Signed seconds of the span of time. Must be from -315,576,000,000
  115. * to +315,576,000,000 inclusive. Note: these bounds are computed from:
  116. * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
  117. *
  118. * Generated from protobuf field <code>int64 seconds = 1;</code>
  119. * @param int|string $var
  120. * @return $this
  121. */
  122. public function setSeconds($var)
  123. {
  124. GPBUtil::checkInt64($var);
  125. $this->seconds = $var;
  126. return $this;
  127. }
  128. /**
  129. * Signed fractions of a second at nanosecond resolution of the span
  130. * of time. Durations less than one second are represented with a 0
  131. * `seconds` field and a positive or negative `nanos` field. For durations
  132. * of one second or more, a non-zero value for the `nanos` field must be
  133. * of the same sign as the `seconds` field. Must be from -999,999,999
  134. * to +999,999,999 inclusive.
  135. *
  136. * Generated from protobuf field <code>int32 nanos = 2;</code>
  137. * @return int
  138. */
  139. public function getNanos()
  140. {
  141. return $this->nanos;
  142. }
  143. /**
  144. * Signed fractions of a second at nanosecond resolution of the span
  145. * of time. Durations less than one second are represented with a 0
  146. * `seconds` field and a positive or negative `nanos` field. For durations
  147. * of one second or more, a non-zero value for the `nanos` field must be
  148. * of the same sign as the `seconds` field. Must be from -999,999,999
  149. * to +999,999,999 inclusive.
  150. *
  151. * Generated from protobuf field <code>int32 nanos = 2;</code>
  152. * @param int $var
  153. * @return $this
  154. */
  155. public function setNanos($var)
  156. {
  157. GPBUtil::checkInt32($var);
  158. $this->nanos = $var;
  159. return $this;
  160. }
  161. }