周期
| 284 | |
| 285 | |
| 286 | class Period(object): |
| 287 | """ 周期 """ |
| 288 | #class Type(Enum): |
| 289 | #MilliSeconds = "MilliSeconds" |
| 290 | #Seconds = "Seconds" |
| 291 | #Minutes = "Minutes" |
| 292 | #Hours = "Hours" |
| 293 | #Days = "Days" |
| 294 | #Months = "Months" |
| 295 | #Seasons = "Seasons" |
| 296 | #Years = "Years" |
| 297 | periods = ["MilliSecond", "Second", "Minute", "Hour", |
| 298 | "Day", "Month", "Season", "Year"] |
| 299 | |
| 300 | def __init__(self, str_period): |
| 301 | period = str_period.split('.') |
| 302 | if len(period) == 2: |
| 303 | unit_count = int(period[0]) |
| 304 | time_unit = period[1] |
| 305 | else: |
| 306 | raise PeriodTypeError |
| 307 | if time_unit not in self.periods: |
| 308 | raise PeriodTypeError |
| 309 | |
| 310 | self._type = time_unit |
| 311 | self._length = unit_count |
| 312 | |
| 313 | @property |
| 314 | def type(self): |
| 315 | """ |
| 316 | 时间单位。 |
| 317 | """ |
| 318 | return self._type |
| 319 | |
| 320 | @property |
| 321 | def length(self): |
| 322 | """ |
| 323 | 时间长度。 |
| 324 | """ |
| 325 | return self._length |
| 326 | |
| 327 | def __str__(self): |
| 328 | return "%d.%s" % (self._length, self._type) |
| 329 | |
| 330 | def __hash__(self): |
| 331 | if hasattr(self, '_hash'): |
| 332 | return self._hash |
| 333 | else: |
| 334 | self._hash = hash(self.__str__()) |
| 335 | return self._hash |
| 336 | |
| 337 | |
| 338 | class PContract(object): |