normalDate.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. #!/usr/bin/env python
  2. # normalDate.py - version 1.0 - 20000717
  3. #hacked by Robin Becker 10/Apr/2001
  4. #major changes include
  5. # using Types instead of type(0) etc
  6. # BusinessDate class
  7. # __radd__, __rsub__ methods
  8. # formatMS stuff
  9. # derived from an original version created
  10. # by Jeff Bauer of Rubicon Research and used
  11. # with his kind permission
  12. __version__='3.3.18'
  13. __doc__="Jeff Bauer's lightweight date class, extended by us. Predates Python's datetime module."
  14. _bigBangScalar = -4345732 # based on (-9999, 1, 1) BC/BCE minimum
  15. _bigCrunchScalar = 2958463 # based on (9999,12,31) AD/CE maximum
  16. _daysInMonthNormal = [31,28,31,30,31,30,31,31,30,31,30,31]
  17. _daysInMonthLeapYear = [31,29,31,30,31,30,31,31,30,31,30,31]
  18. _dayOfWeekName = '''Monday Tuesday Wednesday Thursday Friday Saturday Sunday'''
  19. _dayOfWeekNameLower = _dayOfWeekName.lower().split()
  20. _dayOfWeekName = _dayOfWeekName.split()
  21. _monthName = '''January February March April May June
  22. July August September October November December'''
  23. _monthNameLower = _monthName.lower().split()
  24. _monthName = _monthName.split()
  25. from reportlab import cmp
  26. import re, time, datetime
  27. from .utils import isStr
  28. if hasattr(time,'struct_time'):
  29. _DateSeqTypes = (list,tuple,time.struct_time)
  30. else:
  31. _DateSeqTypes = (list,tuple)
  32. _fmtPat = re.compile('\\{(m{1,5}|yyyy|yy|d{1,4})\\}',re.MULTILINE|re.IGNORECASE)
  33. _iso_re = re.compile(r'(\d\d\d\d|\d\d)-(\d\d)-(\d\d)')
  34. def getStdMonthNames():
  35. return _monthNameLower
  36. def getStdShortMonthNames():
  37. return [x[:3] for x in getStdMonthNames()]
  38. def getStdDayNames():
  39. return _dayOfWeekNameLower
  40. def getStdShortDayNames():
  41. return [x[:3] for x in getStdDayNames()]
  42. def isLeapYear(year):
  43. """determine if specified year is leap year, returns Python boolean"""
  44. if year < 1600:
  45. if year % 4:
  46. return 0
  47. else:
  48. return 1
  49. elif year % 4 != 0:
  50. return 0
  51. elif year % 100 != 0:
  52. return 1
  53. elif year % 400 != 0:
  54. return 0
  55. else:
  56. return 1
  57. class NormalDateException(Exception):
  58. """Exception class for NormalDate"""
  59. pass
  60. class NormalDate:
  61. """
  62. NormalDate is a specialized class to handle dates without
  63. all the excess baggage (time zones, daylight savings, leap
  64. seconds, etc.) of other date structures. The minimalist
  65. strategy greatly simplifies its implementation and use.
  66. Internally, NormalDate is stored as an integer with values
  67. in a discontinuous range of -99990101 to 99991231. The
  68. integer value is used principally for storage and to simplify
  69. the user interface. Internal calculations are performed by
  70. a scalar based on Jan 1, 1900.
  71. Valid NormalDate ranges include (-9999,1,1) B.C.E. through
  72. (9999,12,31) C.E./A.D.
  73. 1.0
  74. No changes, except the version number. After 3 years of use by
  75. various parties I think we can consider it stable.
  76. 0.8
  77. Added Prof. Stephen Walton's suggestion for a range method
  78. - module author resisted the temptation to use lambda <0.5 wink>
  79. 0.7
  80. Added Dan Winkler's suggestions for __add__, __sub__ methods
  81. 0.6
  82. Modifications suggested by Kevin Digweed to fix:
  83. - dayOfWeek, dayOfWeekAbbrev, clone methods
  84. - Permit NormalDate to be a better behaved superclass
  85. 0.5
  86. Minor tweaking
  87. 0.4
  88. - Added methods __cmp__, __hash__
  89. - Added Epoch variable, scoped to the module
  90. - Added setDay, setMonth, setYear methods
  91. 0.3
  92. Minor touch-ups
  93. 0.2
  94. - Fixed bug for certain B.C.E leap years
  95. - Added Jim Fulton's suggestions for short alias class name =ND
  96. and __getstate__, __setstate__ methods
  97. Special thanks: Roedy Green
  98. """
  99. def __init__(self, normalDate=None):
  100. """
  101. Accept 1 of 4 values to initialize a NormalDate:
  102. 1. None - creates a NormalDate for the current day
  103. 2. integer in yyyymmdd format
  104. 3. string in yyyymmdd format
  105. 4. tuple in (yyyy, mm, dd) - localtime/gmtime can also be used
  106. 5. string iso date format see _iso_re above
  107. 6. datetime.datetime or datetime.date
  108. """
  109. if normalDate is None:
  110. self.setNormalDate(time.localtime(time.time()))
  111. else:
  112. self.setNormalDate(normalDate)
  113. def add(self, days):
  114. """add days to date; use negative integers to subtract"""
  115. if not isinstance(days,int):
  116. raise NormalDateException( \
  117. 'add method parameter must be integer type')
  118. self.normalize(self.scalar() + days)
  119. def __add__(self, days):
  120. """add integer to normalDate and return a new, calculated value"""
  121. if not isinstance(days,int):
  122. raise NormalDateException( \
  123. '__add__ parameter must be integer type')
  124. cloned = self.clone()
  125. cloned.add(days)
  126. return cloned
  127. def __radd__(self,days):
  128. '''for completeness'''
  129. return self.__add__(days)
  130. def clone(self):
  131. """return a cloned instance of this normalDate"""
  132. return self.__class__(self.normalDate)
  133. def __lt__(self,other):
  134. if not hasattr(other,'normalDate'):
  135. return False
  136. return self.normalDate < other.normalDate
  137. def __le__(self,other):
  138. if not hasattr(other,'normalDate'):
  139. return False
  140. return self.normalDate <= other.normalDate
  141. def __eq__(self,other):
  142. if not hasattr(other,'normalDate'):
  143. return False
  144. return self.normalDate == other.normalDate
  145. def __ne__(self,other):
  146. if not hasattr(other,'normalDate'):
  147. return True
  148. return self.normalDate != other.normalDate
  149. def __ge__(self,other):
  150. if not hasattr(other,'normalDate'):
  151. return True
  152. return self.normalDate >= other.normalDate
  153. def __gt__(self,other):
  154. if not hasattr(other,'normalDate'):
  155. return True
  156. return self.normalDate > other.normalDate
  157. def day(self):
  158. """return the day as integer 1-31"""
  159. return int(repr(self.normalDate)[-2:])
  160. def dayOfWeek(self):
  161. """return integer representing day of week, Mon=0, Tue=1, etc."""
  162. return dayOfWeek(*self.toTuple())
  163. @property
  164. def __day_of_week_name__(self):
  165. return getattr(self,'_dayOfWeekName',_dayOfWeekName)
  166. def dayOfWeekAbbrev(self):
  167. """return day of week abbreviation for current date: Mon, Tue, etc."""
  168. return self.__day_of_week_name__[self.dayOfWeek()][:3]
  169. def dayOfWeekName(self):
  170. """return day of week name for current date: Monday, Tuesday, etc."""
  171. return self.__day_of_week_name__[self.dayOfWeek()]
  172. def dayOfYear(self):
  173. """day of year"""
  174. if self.isLeapYear():
  175. daysByMonth = _daysInMonthLeapYear
  176. else:
  177. daysByMonth = _daysInMonthNormal
  178. priorMonthDays = 0
  179. for m in range(self.month() - 1):
  180. priorMonthDays = priorMonthDays + daysByMonth[m]
  181. return self.day() + priorMonthDays
  182. def daysBetweenDates(self, normalDate):
  183. """
  184. return value may be negative, since calculation is
  185. self.scalar() - arg
  186. """
  187. if isinstance(normalDate,NormalDate):
  188. return self.scalar() - normalDate.scalar()
  189. else:
  190. return self.scalar() - NormalDate(normalDate).scalar()
  191. def equals(self, target):
  192. if isinstance(target,NormalDate):
  193. if target is None:
  194. return self.normalDate is None
  195. else:
  196. return self.normalDate == target.normalDate
  197. else:
  198. return 0
  199. def endOfMonth(self):
  200. """returns (cloned) last day of month"""
  201. return self.__class__(self.__repr__()[-8:-2]+str(self.lastDayOfMonth()))
  202. def firstDayOfMonth(self):
  203. """returns (cloned) first day of month"""
  204. return self.__class__(self.__repr__()[-8:-2]+"01")
  205. def formatUS(self):
  206. """return date as string in common US format: MM/DD/YY"""
  207. d = self.__repr__()
  208. return "%s/%s/%s" % (d[-4:-2], d[-2:], d[-6:-4])
  209. def formatUSCentury(self):
  210. """return date as string in 4-digit year US format: MM/DD/YYYY"""
  211. d = self.__repr__()
  212. return "%s/%s/%s" % (d[-4:-2], d[-2:], d[-8:-4])
  213. def _fmtM(self):
  214. return str(self.month())
  215. def _fmtMM(self):
  216. return '%02d' % self.month()
  217. def _fmtMMM(self):
  218. return self.monthAbbrev()
  219. def _fmtMMMM(self):
  220. return self.monthName()
  221. def _fmtMMMMM(self):
  222. return self.monthName()[0]
  223. def _fmtD(self):
  224. return str(self.day())
  225. def _fmtDD(self):
  226. return '%02d' % self.day()
  227. def _fmtDDD(self):
  228. return self.dayOfWeekAbbrev()
  229. def _fmtDDDD(self):
  230. return self.dayOfWeekName()
  231. def _fmtYY(self):
  232. return '%02d' % (self.year()%100)
  233. def _fmtYYYY(self):
  234. return str(self.year())
  235. def formatMS(self,fmt):
  236. '''format like MS date using the notation
  237. {YY} --> 2 digit year
  238. {YYYY} --> 4 digit year
  239. {M} --> month as digit
  240. {MM} --> 2 digit month
  241. {MMM} --> abbreviated month name
  242. {MMMM} --> monthname
  243. {MMMMM} --> first character of monthname
  244. {D} --> day of month as digit
  245. {DD} --> 2 digit day of month
  246. {DDD} --> abrreviated weekday name
  247. {DDDD} --> weekday name
  248. '''
  249. r = fmt[:]
  250. f = 0
  251. while 1:
  252. m = _fmtPat.search(r,f)
  253. if m:
  254. y = getattr(self,'_fmt'+(m.group()[1:-1].upper()))()
  255. i, j = m.span()
  256. r = (r[0:i] + y) + r[j:]
  257. f = i + len(y)
  258. else:
  259. return r
  260. def __getstate__(self):
  261. """minimize persistent storage requirements"""
  262. return self.normalDate
  263. def __hash__(self):
  264. return hash(self.normalDate)
  265. def __int__(self):
  266. return self.normalDate
  267. def isLeapYear(self):
  268. """
  269. determine if specified year is leap year, returning true (1) or
  270. false (0)
  271. """
  272. return isLeapYear(self.year())
  273. def _isValidNormalDate(self, normalDate):
  274. """checks for date validity in [-]yyyymmdd format"""
  275. if not isinstance(normalDate,int):
  276. return 0
  277. if len(repr(normalDate)) > 9:
  278. return 0
  279. if normalDate < 0:
  280. dateStr = "%09d" % normalDate
  281. else:
  282. dateStr = "%08d" % normalDate
  283. if len(dateStr) < 8:
  284. return 0
  285. elif len(dateStr) == 9:
  286. if (dateStr[0] != '-' and dateStr[0] != '+'):
  287. return 0
  288. year = int(dateStr[:-4])
  289. if year < -9999 or year > 9999 or year == 0:
  290. return 0 # note: zero (0) is not a valid year
  291. month = int(dateStr[-4:-2])
  292. if month < 1 or month > 12:
  293. return 0
  294. if isLeapYear(year):
  295. maxDay = _daysInMonthLeapYear[month - 1]
  296. else:
  297. maxDay = _daysInMonthNormal[month - 1]
  298. day = int(dateStr[-2:])
  299. if day < 1 or day > maxDay:
  300. return 0
  301. if year == 1582 and month == 10 and day > 4 and day < 15:
  302. return 0 # special case of 10 days dropped: Oct 5-14, 1582
  303. return 1
  304. def lastDayOfMonth(self):
  305. """returns last day of the month as integer 28-31"""
  306. if self.isLeapYear():
  307. return _daysInMonthLeapYear[self.month() - 1]
  308. else:
  309. return _daysInMonthNormal[self.month() - 1]
  310. def localeFormat(self):
  311. """override this method to use your preferred locale format"""
  312. return self.formatUS()
  313. def month(self):
  314. """returns month as integer 1-12"""
  315. return int(repr(self.normalDate)[-4:-2])
  316. @property
  317. def __month_name__(self):
  318. return getattr(self,'_monthName',_monthName)
  319. def monthAbbrev(self):
  320. """returns month as a 3-character abbreviation, i.e. Jan, Feb, etc."""
  321. return self.__month_name__[self.month() - 1][:3]
  322. def monthName(self):
  323. """returns month name, i.e. January, February, etc."""
  324. return self.__month_name__[self.month() - 1]
  325. def normalize(self, scalar):
  326. """convert scalar to normalDate"""
  327. if scalar < _bigBangScalar:
  328. msg = "normalize(%d): scalar below minimum" % \
  329. _bigBangScalar
  330. raise NormalDateException(msg)
  331. if scalar > _bigCrunchScalar:
  332. msg = "normalize(%d): scalar exceeds maximum" % \
  333. _bigCrunchScalar
  334. raise NormalDateException(msg)
  335. from math import floor
  336. if scalar >= -115860:
  337. year = 1600 + int(floor((scalar + 109573) / 365.2425))
  338. elif scalar >= -693597:
  339. year = 4 + int(floor((scalar + 692502) / 365.2425))
  340. else:
  341. year = -4 + int(floor((scalar + 695058) / 365.2425))
  342. days = scalar - firstDayOfYear(year) + 1
  343. if days <= 0:
  344. year = year - 1
  345. days = scalar - firstDayOfYear(year) + 1
  346. daysInYear = 365
  347. if isLeapYear(year):
  348. daysInYear = daysInYear + 1
  349. if days > daysInYear:
  350. year = year + 1
  351. days = scalar - firstDayOfYear(year) + 1
  352. # add 10 days if between Oct 15, 1582 and Dec 31, 1582
  353. if (scalar >= -115860 and scalar <= -115783):
  354. days = days + 10
  355. if isLeapYear(year):
  356. daysByMonth = _daysInMonthLeapYear
  357. else:
  358. daysByMonth = _daysInMonthNormal
  359. dc = 0; month = 12
  360. for m in range(len(daysByMonth)):
  361. dc = dc + daysByMonth[m]
  362. if dc >= days:
  363. month = m + 1
  364. break
  365. # add up the days in prior months
  366. priorMonthDays = 0
  367. for m in range(month - 1):
  368. priorMonthDays = priorMonthDays + daysByMonth[m]
  369. day = days - priorMonthDays
  370. self.setNormalDate((year, month, day))
  371. def range(self, days):
  372. """Return a range of normalDates as a list. Parameter
  373. may be an int or normalDate."""
  374. if not isinstance(days,int):
  375. days = days - self # if not int, assume arg is normalDate type
  376. r = []
  377. for i in range(days):
  378. r.append(self + i)
  379. return r
  380. def __repr__(self):
  381. """print format: [-]yyyymmdd"""
  382. # Note: When disassembling a NormalDate string, be sure to
  383. # count from the right, i.e. epochMonth = int(repr(Epoch)[-4:-2]),
  384. # or the slice won't work for dates B.C.
  385. if self.normalDate < 0:
  386. return "%09d" % self.normalDate
  387. else:
  388. return "%08d" % self.normalDate
  389. def scalar(self):
  390. """days since baseline date: Jan 1, 1900"""
  391. (year, month, day) = self.toTuple()
  392. days = firstDayOfYear(year) + day - 1
  393. if self.isLeapYear():
  394. for m in range(month - 1):
  395. days = days + _daysInMonthLeapYear[m]
  396. else:
  397. for m in range(month - 1):
  398. days = days + _daysInMonthNormal[m]
  399. if year == 1582:
  400. if month > 10 or (month == 10 and day > 4):
  401. days = days - 10
  402. return days
  403. def setDay(self, day):
  404. """set the day of the month"""
  405. maxDay = self.lastDayOfMonth()
  406. if day < 1 or day > maxDay:
  407. msg = "day is outside of range 1 to %d" % maxDay
  408. raise NormalDateException(msg)
  409. (y, m, d) = self.toTuple()
  410. self.setNormalDate((y, m, day))
  411. def setMonth(self, month):
  412. """set the month [1-12]"""
  413. if month < 1 or month > 12:
  414. raise NormalDateException('month is outside range 1 to 12')
  415. (y, m, d) = self.toTuple()
  416. self.setNormalDate((y, month, d))
  417. def setNormalDate(self, normalDate):
  418. """
  419. accepts date as scalar string/integer (yyyymmdd) or tuple
  420. (year, month, day, ...)"""
  421. if isinstance(normalDate,int):
  422. self.normalDate = normalDate
  423. elif isStr(normalDate):
  424. try:
  425. self.normalDate = int(normalDate)
  426. except:
  427. m = _iso_re.match(normalDate)
  428. if m:
  429. self.setNormalDate(m.group(1)+m.group(2)+m.group(3))
  430. else:
  431. raise NormalDateException("unable to setNormalDate(%s)" % repr(normalDate))
  432. elif isinstance(normalDate,_DateSeqTypes):
  433. self.normalDate = int("%04d%02d%02d" % normalDate[:3])
  434. elif isinstance(normalDate,NormalDate):
  435. self.normalDate = normalDate.normalDate
  436. elif isinstance(normalDate,(datetime.datetime,datetime.date)):
  437. self.normalDate = (normalDate.year*100+normalDate.month)*100+normalDate.day
  438. else:
  439. self.normalDate = None
  440. if not self._isValidNormalDate(self.normalDate):
  441. raise NormalDateException("unable to setNormalDate(%s)" % repr(normalDate))
  442. def setYear(self, year):
  443. if year == 0:
  444. raise NormalDateException('cannot set year to zero')
  445. elif year < -9999:
  446. raise NormalDateException('year cannot be less than -9999')
  447. elif year > 9999:
  448. raise NormalDateException('year cannot be greater than 9999')
  449. (y, m, d) = self.toTuple()
  450. self.setNormalDate((year, m, d))
  451. __setstate__ = setNormalDate
  452. def __sub__(self, v):
  453. if isinstance(v,int):
  454. return self.__add__(-v)
  455. return self.scalar() - v.scalar()
  456. def __rsub__(self,v):
  457. if isinstance(v,int):
  458. return NormalDate(v) - self
  459. else:
  460. return v.scalar() - self.scalar()
  461. def toTuple(self):
  462. """return date as (year, month, day) tuple"""
  463. return (self.year(), self.month(), self.day())
  464. def year(self):
  465. """return year in yyyy format, negative values indicate B.C."""
  466. return int(repr(self.normalDate)[:-4])
  467. ################# Utility functions #################
  468. def bigBang():
  469. """return lower boundary as a NormalDate"""
  470. return NormalDate((-9999, 1, 1))
  471. def bigCrunch():
  472. """return upper boundary as a NormalDate"""
  473. return NormalDate((9999, 12, 31))
  474. def dayOfWeek(y, m, d):
  475. """return integer representing day of week, Mon=0, Tue=1, etc."""
  476. if m == 1 or m == 2:
  477. m = m + 12
  478. y = y - 1
  479. return (d + 2*m + 3*(m+1)//5 + y + y//4 - y//100 + y//400) % 7
  480. def firstDayOfYear(year):
  481. """number of days to the first of the year, relative to Jan 1, 1900"""
  482. if not isinstance(year,int):
  483. msg = "firstDayOfYear() expected integer, got %s" % type(year)
  484. raise NormalDateException(msg)
  485. if year == 0:
  486. raise NormalDateException('first day of year cannot be zero (0)')
  487. elif year < 0: # BCE calculation
  488. firstDay = (year * 365) + int((year - 1) / 4) - 693596
  489. else: # CE calculation
  490. leapAdjust = int((year + 3) / 4)
  491. if year > 1600:
  492. leapAdjust = leapAdjust - int((year + 99 - 1600) / 100) + \
  493. int((year + 399 - 1600) / 400)
  494. firstDay = year * 365 + leapAdjust - 693963
  495. if year > 1582:
  496. firstDay = firstDay - 10
  497. return firstDay
  498. def FND(d):
  499. '''convert to ND if required'''
  500. return isinstance(d,NormalDate) and d or ND(d)
  501. Epoch=bigBang()
  502. ND=NormalDate
  503. BDEpoch=ND(15821018)
  504. BDEpochScalar = -115857
  505. class BusinessDate(NormalDate):
  506. """
  507. Specialised NormalDate
  508. """
  509. def add(self, days):
  510. """add days to date; use negative integers to subtract"""
  511. if not isinstance(days,int):
  512. raise NormalDateException('add method parameter must be integer')
  513. self.normalize(self.scalar() + days)
  514. def __add__(self, days):
  515. """add integer to BusinessDate and return a new, calculated value"""
  516. if not isinstance(days,int):
  517. raise NormalDateException('__add__ parameter must be integer')
  518. cloned = self.clone()
  519. cloned.add(days)
  520. return cloned
  521. def __sub__(self, v):
  522. return isinstance(v,int) and self.__add__(-v) or self.scalar() - v.scalar()
  523. def asNormalDate(self):
  524. return ND(self.normalDate)
  525. def daysBetweenDates(self, normalDate):
  526. return self.asNormalDate.daysBetweenDates(normalDate)
  527. def _checkDOW(self):
  528. if self.dayOfWeek()>4: raise NormalDateException("%r isn't a business day" % self.normalDate)
  529. def normalize(self, i):
  530. i = int(i)
  531. NormalDate.normalize(self,(i//5)*7+i%5+BDEpochScalar)
  532. def scalar(self):
  533. d = self.asNormalDate()
  534. i = d - BDEpoch #luckily BDEpoch is a Monday so we don't have a problem
  535. #concerning the relative weekday
  536. return 5*(i//7) + i%7
  537. def setNormalDate(self, normalDate):
  538. NormalDate.setNormalDate(self,normalDate)
  539. self._checkDOW()
  540. if __name__ == '__main__':
  541. today = NormalDate()
  542. print("NormalDate test:")
  543. print(" Today (%s) is: %s %s" % (today, today.dayOfWeekAbbrev(), today.localeFormat()))
  544. yesterday = today - 1
  545. print(" Yesterday was: %s %s" % (yesterday.dayOfWeekAbbrev(), yesterday.localeFormat()))
  546. tomorrow = today + 1
  547. print(" Tomorrow will be: %s %s" % (tomorrow.dayOfWeekAbbrev(), tomorrow.localeFormat()))
  548. print(" Days between tomorrow and yesterday: %d" % (tomorrow - yesterday))
  549. print(today.formatMS('{d}/{m}/{yy}'))
  550. print(today.formatMS('{dd}/{m}/{yy}'))
  551. print(today.formatMS('{ddd} {d}/{m}/{yy}'))
  552. print(today.formatMS('{dddd} {d}/{m}/{yy}'))
  553. print(today.formatMS('{d}/{mm}/{yy}'))
  554. print(today.formatMS('{d}/{mmm}/{yy}'))
  555. print(today.formatMS('{d}/{mmmm}/{yy}'))
  556. print(today.formatMS('{d}/{m}/{yyyy}'))
  557. b = BusinessDate('20010116')
  558. print('b=',b,'b.scalar()', b.scalar())