datetime.bmx 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295
  1. ' Copyright (c) 2007-2022 Bruce A Henderson
  2. ' All rights reserved.
  3. '
  4. ' Redistribution and use in source and binary forms, with or without
  5. ' modification, are permitted provided that the following conditions are met:
  6. ' * Redistributions of source code must retain the above copyright
  7. ' notice, this list of conditions and the following disclaimer.
  8. ' * Redistributions in binary form must reproduce the above copyright
  9. ' notice, this list of conditions and the following disclaimer in the
  10. ' documentation and/or other materials provided with the distribution.
  11. ' * Neither the name of the copyright holder nor the
  12. ' names of its contributors may be used to endorse or promote products
  13. ' derived from this software without specific prior written permission.
  14. '
  15. ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  16. ' EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. ' WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. ' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. ' DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. ' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. ' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. ' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. ' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. ' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. '
  26. SuperStrict
  27. Rem
  28. bbdoc: Date Time
  29. End Rem
  30. Module Boost.DateTime
  31. ModuleInfo "Version: 1.08"
  32. ModuleInfo "License: BSD"
  33. ModuleInfo "Copyright: Wrapper - 2007-2022 Bruce A Henderson"
  34. ModuleInfo "Modserver: BRL"
  35. ModuleInfo "History: 1.08"
  36. ModuleInfo "History: Refactored"
  37. ModuleInfo "History: 1.07"
  38. ModuleInfo "History: Updated to Boost 1.80"
  39. ModuleInfo "History: 1.06"
  40. ModuleInfo "History: Fixed glue bool/long usage."
  41. ModuleInfo "History: 1.05"
  42. ModuleInfo "History: Updated to Boost 1.67"
  43. ModuleInfo "History: 1.04"
  44. ModuleInfo "History: Updated to Boost 1.65.1"
  45. ModuleInfo "History: 1.03"
  46. ModuleInfo "History: Updated to boost 1.52"
  47. ModuleInfo "History: Added TTimeFacet, and format methods for TTime and TTimeDuration."
  48. ModuleInfo "History: Reworked format functionality to accept facets."
  49. ModuleInfo "History: Rewrote glue String handling."
  50. ModuleInfo "History: New BaH.BoostLocale requirement - for much improved localised date/time support."
  51. ModuleInfo "History: 1.02"
  52. ModuleInfo "History: Updated to boost 1.42"
  53. ModuleInfo "History: 1.01"
  54. ModuleInfo "History: Updated to boost 1.38"
  55. ModuleInfo "History: Improved exception handling."
  56. ModuleInfo "History: Fixed format() method for iterators."
  57. ModuleInfo "History: 1.00"
  58. ModuleInfo "History: Initial Release."
  59. ModuleInfo "CC_OPTS: -fexceptions"
  60. Import Boost.Locale
  61. ?Not Win32
  62. ModuleInfo "CC_OPTS: -DBOOST_LOCALE_NO_WINAPI_BACKEND -DBOOST_LOCALE_NO_STD_BACKEND -DBOOST_LOCALE_WITH_ICONV"
  63. ?Win32
  64. ModuleInfo "CC_OPTS: -DBOOST_LOCALE_NO_POSIX_BACKEND -DBOOST_LOCALE_NO_STD_BACKEND"
  65. ?macos
  66. Import "-liconv"
  67. ?
  68. Import "source.bmx"
  69. Rem
  70. bbdoc: The primary interface for date programming.
  71. about: In general, the date class is immutable once constructed although it does allow assignment
  72. from another date.
  73. End Rem
  74. Type TDate
  75. Field datePtr:Byte Ptr
  76. Private
  77. Method New(datePtr:Byte Ptr)
  78. Self.datePtr = datePtr
  79. End Method
  80. Public
  81. Method New()
  82. New(bmx_datetime_localday())
  83. End Method
  84. Rem
  85. bbdoc: Creates a new #TDate.
  86. about:
  87. <pre>
  88. SuperStrict
  89. Framework Boost.DateTime
  90. Import BRL.StandardIO
  91. Local d:TDate = New TDate(1984, 4, 23)
  92. Print d.toString()
  93. Print New TDate(1990, EMonth.March, 12).toString()
  94. </pre>
  95. <a href="../examples/tdate_create.bmx">Example source</a>
  96. End Rem
  97. Method New(year:Int, _month:Int, day:Int)
  98. New (bmx_datetime_newdate(year, _month, day))
  99. End Method
  100. Method New(year:Int, _month:EMonth, day:Int)
  101. New (bmx_datetime_newdate(year, Int(_month), day))
  102. End Method
  103. Method New(year:Int, _month:EMonth, day:ENthDay)
  104. New (bmx_datetime_newdate(year, Int(_month), Int(day)))
  105. End Method
  106. Method New(year:Int, _month:Int, day:ENthDay)
  107. New (bmx_datetime_newdate(year, _month, Int(day)))
  108. End Method
  109. Rem
  110. bbdoc: Creates a new #TDate for the current local time.
  111. about:
  112. <pre>
  113. SuperStrict
  114. Framework Boost.DateTime
  115. Import BRL.StandardIO
  116. Local d:TDate = TDate.localDay()
  117. Print d.toString()
  118. </pre>
  119. <a href="../examples/tdate_localDay.bmx">Example source</a>
  120. End Rem
  121. Function localDay:TDate()
  122. Return New TDate(bmx_datetime_localday())
  123. End Function
  124. Rem
  125. bbdoc: Creates a new #TDate for the current UCT time.
  126. End Rem
  127. Function universalDay:TDate()
  128. Return New TDate(bmx_datetime_universalday())
  129. End Function
  130. Rem
  131. bbdoc: From delimited date string where with order year-month-day eg: 2002-1-25
  132. returns: A #TDate of the string entered, or Null if the date was invalid.
  133. about:
  134. <pre>
  135. SuperStrict
  136. Framework Boost.DateTime
  137. Import BRL.StandardIO
  138. Local d:TDate = TDate.fromString("2004-09-25")
  139. Print d.toString()
  140. </pre>
  141. <a href="../examples/tdate_fromString.bmx">Example source</a>
  142. End Rem
  143. Function FromString:TDate(date:String)
  144. Return New TDate(bmx_datetime_fromstring(date))
  145. End Function
  146. Rem
  147. bbdoc: From iso type date string where with order year-month-day eg: 20020125
  148. about:
  149. <pre>
  150. SuperStrict
  151. Framework Boost.DateTime
  152. Import BRL.StandardIO
  153. Local d:TDate = TDate.fromUndelimitedString("19760130")
  154. Print d.toString()
  155. </pre>
  156. <a href="../examples/tdate_fromUndelimitedString.bmx">Example source</a>
  157. End Rem
  158. Function fromUndelimitedString:TDate(date:String)
  159. Return New TDate(bmx_datetime_fromundelimitedstring(date))
  160. End Function
  161. Rem
  162. bbdoc: Returns true if the date is before @when.
  163. End Rem
  164. Method isBefore:Int(when:TDate)
  165. Return bmx_datetime_before(datePtr, when.datePtr)
  166. End Method
  167. Rem
  168. bbdoc: Returns true if the date is after @when.
  169. End Rem
  170. Method isAfter:Int(when:TDate)
  171. Return bmx_datetime_after(datePtr, when.datePtr)
  172. End Method
  173. Rem
  174. bbdoc: Returns true if the two dates are equal.
  175. End Rem
  176. Method isEqual:Int(when:TDate)
  177. Return bmx_datetime_equals(datePtr, when.datePtr)
  178. End Method
  179. ' for sorting !
  180. Method compare:Int(obj:Object)
  181. If TDate(obj) Then
  182. If isBefore(TDate(obj)) Then Return -1
  183. If isEqual(TDate(obj)) Then Return 0
  184. Return 1
  185. End If
  186. Return Super.compare(obj)
  187. End Method
  188. Rem
  189. bbdoc: Returns the year part of the date.
  190. about:
  191. <pre>
  192. SuperStrict
  193. Framework Boost.DateTime
  194. Import BRL.StandardIO
  195. Local d:TDate = New TDate(2007, Jul, 17)
  196. Print d.year()
  197. </pre>
  198. <a href="../examples/tdate_year.bmx">Example source</a>
  199. End Rem
  200. Method year:Int()
  201. Return bmx_datetime_year(datePtr)
  202. End Method
  203. Rem
  204. bbdoc: Returns the month part of the date.
  205. about:
  206. <pre>
  207. SuperStrict
  208. Framework Boost.DateTime
  209. Import BRL.StandardIO
  210. Local d:TDate = New TDate(2007, Jul, 17)
  211. Print d.month()
  212. </pre>
  213. <a href="../examples/tdate_month.bmx">Example source</a>
  214. End Rem
  215. Method Month:Int()
  216. Return bmx_datetime_month(datePtr)
  217. End Method
  218. Rem
  219. bbdoc: Returns the day (of the month) part of the date.
  220. about:
  221. <pre>
  222. SuperStrict
  223. Framework Boost.DateTime
  224. Import BRL.StandardIO
  225. Local d:TDate = New TDate(2007, Jul, 17)
  226. Print d.day()
  227. </pre>
  228. <a href="../examples/tdate_day.bmx">Example source</a>
  229. End Rem
  230. Method day:Int()
  231. Return bmx_datetime_day(datePtr)
  232. End Method
  233. Rem
  234. bbdoc: Populates @year, @month and @day with the date parts.
  235. about:
  236. <pre>
  237. SuperStrict
  238. Framework Boost.DateTime
  239. Import BRL.StandardIO
  240. Local d:TDate = New TDate(2006, Dec, 24)
  241. Local year:Int, month:Int, day:Int
  242. d.ymd(year, month, day)
  243. Print year
  244. Print month
  245. Print day
  246. </pre>
  247. <a href="../examples/tdate_ymd.bmx">Example source</a>
  248. End Rem
  249. Method ymd(year:Int Var, _month:Int Var, day:Int Var)
  250. bmx_datetime_ymd(datePtr, Varptr year, Varptr _month, Varptr day)
  251. End Method
  252. Rem
  253. bbdoc: Get the day of the week.
  254. about: Sunday = 0, Monday = 1, etc.
  255. <pre>
  256. SuperStrict
  257. Framework Boost.DateTime
  258. Import BRL.StandardIO
  259. Local d:TDate = TDate.localDay()
  260. Print d.dayOfWeek()
  261. </pre>
  262. <a href="../examples/tdate_dayOfWeek.bmx">Example source</a>
  263. End Rem
  264. Method dayOfWeek:Int()
  265. Return bmx_datetime_day_of_week(datePtr)
  266. End Method
  267. Rem
  268. bbdoc: Get the weekday as a string.
  269. about: This is based on the current weekday format as specified by #TDateFacet.
  270. End Rem
  271. Method WeekDay:String()
  272. Return bmx_weekday_to_string(dayOfWeek())
  273. End Method
  274. Rem
  275. bbdoc: Get the day of the year.
  276. about: Number from 1 to 366.
  277. <pre>
  278. SuperStrict
  279. Framework Boost.DateTime
  280. Import BRL.StandardIO
  281. Local d:TDate = TDate.localDay()
  282. Print d.dayOfYear()
  283. </pre>
  284. <a href="../examples/tdate_dayOfYear.bmx">Example source</a>
  285. End Rem
  286. Method dayOfYear:Int()
  287. Return bmx_datetime_day_of_year(datePtr)
  288. End Method
  289. Rem
  290. bbdoc: Returns a #TDate object set to the last day of the calling objects current month.
  291. about:
  292. <pre>
  293. SuperStrict
  294. Framework Boost.DateTime
  295. Import BRL.StandardIO
  296. Local d:TDate = TDate.localDay()
  297. Local lastDay:TDate = d.lastDayOfMonth()
  298. Print lastDay.toString()
  299. </pre>
  300. <a href="../examples/tdate_lastDayOfMonth.bmx">Example source</a>
  301. End Rem
  302. Method lastDayOfMonth:TDate()
  303. Return New TDate(bmx_datetime_end_of_month(datePtr))
  304. End Method
  305. Rem
  306. bbdoc: Returns the ISO 8601 week number for the date.
  307. about:
  308. <pre>
  309. SuperStrict
  310. Framework Boost.DateTime
  311. Import BRL.StandardIO
  312. Local d:TDate = TDate.localDay()
  313. Print d.weekNumber()
  314. </pre>
  315. <a href="../examples/tdate_weekNumber.bmx">Example source</a>
  316. End Rem
  317. Method weekNumber:Int()
  318. Return bmx_datetime_week_number(datePtr)
  319. End Method
  320. Rem
  321. bbdoc: Return a #TDate adding a day offset.
  322. about:
  323. <pre>
  324. SuperStrict
  325. Framework Boost.DateTime
  326. Import BRL.StandardIO
  327. Local d:TDate = TDate.localDay()
  328. Print d.add(10).toString()
  329. </pre>
  330. <a href="../examples/tdate_add.bmx">Example source</a>
  331. End Rem
  332. Method add:TDate(days:Int)
  333. Return New TDate(bmx_datetime_date_add(datePtr, days))
  334. End Method
  335. Rem
  336. bbdoc: Return a #TDate by adding a day offset.
  337. about:
  338. <pre>
  339. SuperStrict
  340. Framework Boost.DateTime
  341. Import BRL.StandardIO
  342. Local d:TDate = TDate.localDay()
  343. Print d.subtract(14).toString()
  344. </pre>
  345. <a href="../examples/tdate_subtract.bmx">Example source</a>
  346. End Rem
  347. Method subtract:TDate(days:Int)
  348. Return New TDate(bmx_datetime_date_subtract(datePtr, days))
  349. End Method
  350. Rem
  351. bbdoc: Returns the number of days difference.
  352. about:
  353. <pre>
  354. SuperStrict
  355. Framework Boost.DateTime
  356. Import BRL.StandardIO
  357. Local d1:TDate = New TDate(2000, Jan, 1)
  358. Local d2:TDate = TDate.localDay()
  359. Print d2.subtractDate(d1)
  360. </pre>
  361. <a href="../examples/tdate_subtractDate.bmx">Example source</a>
  362. End Rem
  363. Method subtractDate:Int(date:TDate)
  364. Return bmx_datetime_date_subdate(datePtr, date.datePtr)
  365. End Method
  366. Rem
  367. bbdoc: To YYYY-mmm-DD string where mmm 3 char month name.
  368. End Rem
  369. Method toString:String()
  370. Return bmx_datetime_to_string(datePtr, currentDateFacet.localePtr, currentDateFacet.facetPtr)
  371. End Method
  372. Rem
  373. bbdoc: To YYYY-mmm-DD string where mmm 3 char month name.
  374. End Rem
  375. Method toSimpleString:String()
  376. Return bmx_datetime_to_simple_string(datePtr)
  377. End Method
  378. Rem
  379. bbdoc: To YYYYMMDD where all components are integers.
  380. End Rem
  381. Method toISOString:String()
  382. Return bmx_datetime_to_iso_string(datePtr)
  383. End Method
  384. Rem
  385. bbdoc: To YYYY-MM-DD where all components are integers.s
  386. End Rem
  387. Method toISOExtendedString:String()
  388. Return bmx_datetime_to_iso_extended_string(datePtr)
  389. End Method
  390. Rem
  391. bbdoc: Returns a #TDateDayIterator for this date.
  392. about: @offset is the number of days moved in each forward/backward.
  393. End Rem
  394. Method dayIterator:TDateDayIterator(offset:Int = 1)
  395. Return New TDateDayIterator(Self, offset)
  396. End Method
  397. Rem
  398. bbdoc: Returns a #TDateMonthIterator for this date.
  399. about: @offset is the number of months moved in each forward/backward.
  400. End Rem
  401. Method monthIterator:TDateMonthIterator(offset:Int = 1)
  402. Return New TDateMonthIterator(Self, offset)
  403. End Method
  404. Rem
  405. bbdoc: Returns a #TDateYearIterator for this date.
  406. about: @offset is the number of years moved in each forward/backward.
  407. End Rem
  408. Method yearIterator:TDateYearIterator(offset:Int = 1)
  409. Return New TDateYearIterator(Self, offset)
  410. End Method
  411. Rem
  412. bbdoc: Output the date in the specified format.
  413. about: Formatting characters are as follows :
  414. <table align="center" width="90%">
  415. <tr><th>Format Specifier</th><th>Description</th></tr>
  416. <tr><td>%a</td><td>Abbreviated weekday name</td></tr>
  417. <tr><td>%A</td><td>Long weekday name</td></tr>
  418. <tr><td>%b</td><td>Abbreviated month name</td></tr>
  419. <tr><td>%B</td><td>Full month name</td></tr>
  420. <tr><td>%c</td><td>The preferred date and time representation for the current locale.</td></tr>
  421. <tr><td>%C</td><td>The century number (year/100) as a 2-digit integer.</td></tr>
  422. <tr><td>%d</td><td>Day of the month as decimal 01 to 31</td></tr>
  423. <tr><td>%D</td><td>Equivalent to %m/%d/%y</td></tr>
  424. <tr><td>%e</td><td>Like %d, the day of the month as a decimal number, but a leading zero is replaced by a
  425. space</td></tr>
  426. <tr><td>%G</td><td>This has the same format and value as %y, except that if the ISO week number belongs to
  427. the previous or next year, that year is used instead.</td></tr>
  428. <tr><td>%g</td><td>Like %G, but without century.</td></tr>
  429. <tr><td>%h</td><td>Equivalent to %b</td></tr>
  430. <tr><td>%j</td><td>Day of year as decimal from 001 to 366 for leap years, 001 - 365 for non-leap years.</td></tr>
  431. <tr><td>%m</td><td>Month name as a decimal 01 to 12</td></tr>
  432. <tr><td>%u</td><td>The day of the week as a decimal, range 1 to 7, Monday being 1.</td></tr>
  433. <tr><td>%U</td><td>The week number of the current year as a decimal number, range 00 to 53, starting with the
  434. first Sunday as the first day of week 01. In 2005, Jan 1st falls on a Saturday, so therefore it falls within
  435. week 00 of 2005 (week 00 spans 2004-Dec-26 to 2005-Jan-01. This also happens to be week 53 of 2004).</td></tr>
  436. <tr><td>%V</td><td>The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53,
  437. where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first
  438. day of the week.</td></tr>
  439. <tr><td>%w</td><td>Weekday as decimal number 0 to 6</td></tr>
  440. <tr><td>%W</td><td>Week number 00 to 53 where Monday is first day of week 1</td></tr>
  441. <tr><td>%x</td><td>Implementation defined date format from the locale.</td></tr>
  442. <tr><td>%y</td><td>Two digit year</td></tr>
  443. <tr><td>%Y</td><td>Four digit year</td></tr>
  444. <tr><td>%Y-%b-%d</td><td>Default date format</td></tr>
  445. <tr><td>%Y%m%d</td><td>ISO format</td></tr>
  446. <tr><td>%Y-%m-%d</td><td>ISO extended format</td></tr>
  447. </table>
  448. <pre>
  449. SuperStrict
  450. Framework Boost.DateTime
  451. Import BRL.StandardIO
  452. Local d:TDate = TDate.localDay()
  453. Print d.format("This is day %d of month %m, of the year %G.")
  454. </pre>
  455. <a href="../examples/tdate_format.bmx">Example source</a>
  456. End Rem
  457. Method format:String(f:String, facet:TDateFacet = Null)
  458. If facet Then
  459. Return bmx_date_asformat(datePtr, f, facet.localePtr, facet.facetPtr)
  460. Else
  461. Return bmx_date_asformat(datePtr, f, currentDateFacet.localePtr, currentDateFacet.facetPtr)
  462. End If
  463. End Method
  464. ' deletes the date instance
  465. Method Delete()
  466. If datePtr Then
  467. bmx_datetime_free(datePtr)
  468. datePtr = Null
  469. End If
  470. End Method
  471. End Type
  472. Rem
  473. bbdoc: #TDatePeriod provides direct representation for ranges between two dates.
  474. about: The range is from the begin date up to, but not including, the end date.<br>
  475. A period that is created with beginning and end points being equal, or with a duration of zero,
  476. is known as a zero length period. Zero length periods are considered invalid (it is perfectly
  477. legal to construct an invalid period). For these periods, the last point will always be one unit less
  478. that the begin point.
  479. End Rem
  480. Type TDatePeriod
  481. Field datePeriodPtr:Byte Ptr
  482. Private
  483. Method New()
  484. End Method
  485. Method New(datePeriodPtr:Byte Ptr)
  486. Self.datePeriodPtr = datePeriodPtr
  487. End Method
  488. Public
  489. Rem
  490. bbdoc: Create a period as [beginDate, endDate].
  491. about: If endDate is <= beginDate then the period will be invalid.
  492. <pre>
  493. SuperStrict
  494. Framework Boost.DateTime
  495. Import BRL.StandardIO
  496. Local startDate:TDate = New TDate(2007, 1, 1)
  497. Local endDate:TDate = TDate.localDay()
  498. Local p:TDatePeriod = New TDatePeriod(startDate, endDate)
  499. Print p.toString()
  500. </pre>
  501. <a href="../examples/tdateperiod_create.bmx">Example source</a>
  502. End Rem
  503. Method New(beginDate:TDate, endDate:TDate)
  504. New(bmx_datetime_period_datedate(beginDate.datePtr, endDate.datePtr))
  505. End Method
  506. Rem
  507. bbdoc: Create a period as [beginDate, beginDate + length] where end point would be beginDate + length.
  508. about: If length is <= zero then the period will be defined as invalid.
  509. <pre>
  510. SuperStrict
  511. Framework Boost.DateTime
  512. Import BRL.StandardIO
  513. Local startDate:TDate = TDate.localDay()
  514. Local p:TDatePeriod = New TDatePeriod(startDate, 150)
  515. Print p.toString()
  516. </pre>
  517. <a href="../examples/tdateperiod_createWithDays.bmx">Example source</a>
  518. End Rem
  519. Method New(beginDate:TDate, length:Int)
  520. New(bmx_datetime_period_withdays(beginDate.datePtr, length))
  521. End Method
  522. Rem
  523. bbdoc: Add @days to both begin and end.
  524. about:
  525. <pre>
  526. SuperStrict
  527. Framework Boost.DateTime
  528. Import BRL.StandardIO
  529. Local startDate:TDate = New TDate(2007, Feb, 1)
  530. Local endDate:TDate = New TDate(2007, Mar, 1)
  531. Local p:TDatePeriod = New TDatePeriod(startDate, endDate)
  532. Print p.toString()
  533. p.shift(15)
  534. Print p.toString()
  535. </pre>
  536. <a href="../examples/tdateperiod_shift.bmx">Example source</a>
  537. End Rem
  538. Method shift(days:Int)
  539. bmx_datetime_period_shift(datePeriodPtr, days)
  540. End Method
  541. Rem
  542. bbdoc: Returns first day of period.
  543. about:
  544. <pre>
  545. SuperStrict
  546. Framework Boost.DateTime
  547. Import BRL.StandardIO
  548. Local startDate:TDate = TDate.localDay()
  549. Local p:TDatePeriod = New TDatePeriod(startDate, 100)
  550. Print p.begin().toString()
  551. </pre>
  552. <a href="../examples/tdateperiod_begin.bmx">Example source</a>
  553. End Rem
  554. Method begin:TDate()
  555. Return New TDate(bmx_datetime_period_begin(datePeriodPtr))
  556. End Method
  557. Rem
  558. bbdoc: Returns the last date in the period.
  559. about:
  560. <pre>
  561. SuperStrict
  562. Framework Boost.DateTime
  563. Import BRL.StandardIO
  564. Local startDate:TDate = TDate.localDay()
  565. Local p:TDatePeriod = New TDatePeriod(startDate, 100)
  566. Print p.last().toString()
  567. </pre>
  568. <a href="../examples/tdateperiod_last.bmx">Example source</a>
  569. End Rem
  570. Method last:TDate()
  571. Return New TDate(bmx_datetime_period_last(datePeriodPtr))
  572. End Method
  573. Rem
  574. bbdoc: Returns one past the last in the period.
  575. about:
  576. <pre>
  577. SuperStrict
  578. Framework Boost.DateTime
  579. Import BRL.StandardIO
  580. Local startDate:TDate = TDate.localDay()
  581. Local p:TDatePeriod = New TDatePeriod(startDate, 100)
  582. Print p.periodEnd().toString()
  583. </pre>
  584. <a href="../examples/tdateperiod_periodEnd.bmx">Example source</a>
  585. End Rem
  586. Method periodEnd:TDate()
  587. Return New TDate(bmx_datetime_period_end(datePeriodPtr))
  588. End Method
  589. Rem
  590. bbdoc: Returns the length (number of days) in the period.
  591. about:
  592. <pre>
  593. SuperStrict
  594. Framework Boost.DateTime
  595. Import BRL.StandardIO
  596. Local startDate:TDate = TDate.localDay()
  597. Local p:TDatePeriod = New TDatePeriod(startDate, 100)
  598. Print p.length()
  599. </pre>
  600. <a href="../examples/tdateperiod_length.bmx">Example source</a>
  601. End Rem
  602. Method length:Int()
  603. Return bmx_datetime_period_length(datePeriodPtr)
  604. End Method
  605. Rem
  606. bbdoc: True if period is not well formed.
  607. about: eg. end less than or equal to begin.
  608. <pre>
  609. SuperStrict
  610. Framework Boost.DateTime
  611. Import BRL.StandardIO
  612. Local p1:TDatePeriod = New TDatePeriod(New TDate(2007, 2, 1), New TDate(2007, 3, 1))
  613. Local p2:TDatePeriod = New TDatePeriod(New TDate(2007, 2, 1), New TDate(2007, 1, 1))
  614. Print p1.isNull()
  615. Print p2.isNull()
  616. </pre>
  617. <a href="../examples/tdateperiod_isNull.bmx">Example source</a>
  618. End Rem
  619. Method isNull:Int()
  620. Return bmx_datetime_period_isnull(datePeriodPtr)
  621. End Method
  622. Rem
  623. bbdoc: True if @date is within the period.
  624. about: Zero length periods cannot contain any points.
  625. <pre>
  626. SuperStrict
  627. Framework Boost.DateTime
  628. Import BRL.StandardIO
  629. Local p:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2007, 1, 1))
  630. Local goodDate:TDate = New TDate(2006, 6, 1)
  631. Local badDate:TDate = New TDate(2005, 1, 1)
  632. Print p.containsDate(goodDate)
  633. Print p.containsDate(badDate)
  634. </pre>
  635. <a href="../examples/tdateperiod_containsDate.bmx">Example source</a>
  636. End Rem
  637. Method containsDate:Int(date:TDate)
  638. Return bmx_datetime_period_containsdate(datePeriodPtr, date.datePtr)
  639. End Method
  640. Rem
  641. bbdoc: True if @period is within this period.
  642. about:
  643. <pre>
  644. SuperStrict
  645. Framework Boost.DateTime
  646. Import BRL.StandardIO
  647. Local p:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2007, 1, 1))
  648. Local pGood:TDatePeriod = New TDatePeriod(New TDate(2006, 4, 4), New TDate(2006, 5, 5))
  649. Local pBad:TDatePeriod = New TDatePeriod(New TDate(2006, 10, 1), New TDate(2007, 2, 1))
  650. Print p.contains(pGood)
  651. Print p.contains(pBad)
  652. </pre>
  653. <a href="../examples/tdateperiod_contains.bmx">Example source</a>
  654. End Rem
  655. Method contains:Int(period:TDatePeriod)
  656. Return bmx_datetime_period_contains(datePeriodPtr, period.datePeriodPtr)
  657. End Method
  658. Rem
  659. bbdoc: True if periods overlap.
  660. about:
  661. <pre>
  662. SuperStrict
  663. Framework Boost.DateTime
  664. Import BRL.StandardIO
  665. Local p:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2007, 1, 1))
  666. Local pGood:TDatePeriod = New TDatePeriod(New TDate(2006, 10, 1), New TDate(2007, 2, 1))
  667. Local pBad:TDatePeriod = New TDatePeriod(New TDate(2005, 1, 1), New TDate(2005, 12, 1))
  668. Print p.intersects(pGood)
  669. Print p.intersects(pBad)
  670. </pre>
  671. <a href="../examples/tdateperiod_intersects.bmx">Example source</a>
  672. End Rem
  673. Method intersects:Int(period:TDatePeriod)
  674. Return bmx_datetime_period_intersects(datePeriodPtr, period.datePeriodPtr)
  675. End Method
  676. Rem
  677. bbdoc: Calculates the intersection of 2 periods.
  678. about: Null if no intersection.
  679. <pre>
  680. SuperStrict
  681. Framework Boost.DateTime
  682. Import BRL.StandardIO
  683. Local p1:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2007, 1, 1))
  684. Local p2:TDatePeriod = New TDatePeriod(New TDate(2006, 10, 1), New TDate(2007, 2, 1))
  685. Local intersection:TDatePeriod = p1.intersection(p2)
  686. If intersection Then
  687. Print intersection.toString()
  688. End If
  689. </pre>
  690. <a href="../examples/tdateperiod_intersection.bmx">Example source</a>
  691. End Rem
  692. Method intersection:TDatePeriod(period:TDatePeriod)
  693. Return New TDatePeriod(bmx_datetime_period_intersection(datePeriodPtr, period.datePeriodPtr))
  694. End Method
  695. Rem
  696. bbdoc: Checks if two periods are adjacent, but not overlapping.
  697. about:
  698. <pre>
  699. SuperStrict
  700. Framework Boost.DateTime
  701. Import BRL.StandardIO
  702. Local p1:TDatePeriod = New TDatePeriod(New TDate(2006, 10, 1), New TDate(2007, 1, 1))
  703. Local p2:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2006, 10, 1))
  704. Local p3:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2006, 9, 1)) ' a gap here!
  705. Print p1.isAdjacent(p2)
  706. Print p1.isAdjacent(p3)
  707. </pre>
  708. <a href="../examples/tdateperiod_isAdjacent.bmx">Example source</a>
  709. End Rem
  710. Method isAdjacent:Int(period:TDatePeriod)
  711. Return bmx_datetime_period_adjacent(datePeriodPtr, period.datePeriodPtr)
  712. End Method
  713. Rem
  714. bbdoc: Determines if the period is after a given date.
  715. about:
  716. <pre>
  717. SuperStrict
  718. Framework Boost.DateTime
  719. Import BRL.StandardIO
  720. Local p:TDatePeriod = New TDatePeriod(New TDate(2006, 10, 1), New TDate(2007, 1, 1))
  721. Print p.isAfter(New TDate(2000, 1, 1))
  722. Print p.isAfter(New TDate(2008, 1, 1))
  723. </pre>
  724. <a href="../examples/tdateperiod_isAfter.bmx">Example source</a>
  725. End Rem
  726. Method isAfter:Int(date:TDate)
  727. Return bmx_datetime_period_after(datePeriodPtr, date.datePtr)
  728. End Method
  729. Rem
  730. bbdoc: Determines if the period is before a given date.
  731. about:
  732. <pre>
  733. SuperStrict
  734. Framework Boost.DateTime
  735. Import BRL.StandardIO
  736. Local p:TDatePeriod = New TDatePeriod(New TDate(2006, 10, 1), New TDate(2007, 1, 1))
  737. Print p.isBefore(New TDate(2000, 1, 1))
  738. Print p.isBefore(New TDate(2008, 1, 1))
  739. </pre>
  740. <a href="../examples/tdateperiod_isBefore.bmx">Example source</a>
  741. End Rem
  742. Method isBefore:Int(date:TDate)
  743. Return bmx_datetime_period_before(datePeriodPtr, date.datePtr)
  744. End Method
  745. Rem
  746. bbdoc: Returns union of two periods.
  747. about: Null if no intersection.
  748. <pre>
  749. SuperStrict
  750. Framework Boost.DateTime
  751. Import BRL.StandardIO
  752. Local p1:TDatePeriod = New TDatePeriod(New TDate(2006, 10, 1), New TDate(2007, 1, 1))
  753. Local p2:TDatePeriod = New TDatePeriod(New TDate(2006, 12, 1), New TDate(2007, 2, 1))
  754. Local p3:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2006, 5, 1)) ' doesn't overlap !
  755. Local merged:TDatePeriod = p1.merge(p2)
  756. If Not merged.isNull() Then
  757. Print merged.toString()
  758. End If
  759. merged = p1.merge(p3)
  760. If merged.isNull() Then
  761. Print p1.toString() + " and " + p3.toString() + " do NOT overlap!"
  762. End If
  763. </pre>
  764. <a href="../examples/tdateperiod_merge.bmx">Example source</a>
  765. End Rem
  766. Method merge:TDatePeriod(period:TDatePeriod)
  767. Return New TDatePeriod(bmx_datetime_period_merge(datePeriodPtr, period.datePeriodPtr))
  768. End Method
  769. Rem
  770. bbdoc: Combines two periods and any gap between them such that begin = min(begin, period.begin) and end = max(end , period.end)
  771. about:
  772. <pre>
  773. SuperStrict
  774. Framework Boost.DateTime
  775. Import BRL.StandardIO
  776. Local p1:TDatePeriod = New TDatePeriod(New TDate(2006, 1, 1), New TDate(2006, 10, 1))
  777. Local p2:TDatePeriod = New TDatePeriod(New TDate(2006, 12, 1), New TDate(2007, 2, 1))
  778. Local span:TDatePeriod = p1.span(p2)
  779. If Not span.isNull() Then
  780. Print span.toString()
  781. End If
  782. </pre>
  783. <a href="../examples/tdateperiod_span.bmx">Example source</a>
  784. End Rem
  785. Method span:TDatePeriod(period:TDatePeriod)
  786. Return New TDatePeriod(bmx_datetime_period_span(datePeriodPtr, period.datePeriodPtr))
  787. End Method
  788. Rem
  789. bbdoc: True if end is less than period.begin.
  790. End Rem
  791. Method isLess:Int(period:TDatePeriod)
  792. Return bmx_datetime_period_isless(datePeriodPtr, period.datePeriodPtr)
  793. End Method
  794. Rem
  795. bbdoc: True if begin greater than period.end
  796. End Rem
  797. Method isGreater:Int(period:TDatePeriod)
  798. Return bmx_datetime_period_isgreater(datePeriodPtr, period.datePeriodPtr)
  799. End Method
  800. Rem
  801. bbdoc: True if periods are the same.
  802. End Rem
  803. Method isEqual:Int(period:TDatePeriod)
  804. Return bmx_datetime_period_isequal(datePeriodPtr, period.datePeriodPtr)
  805. End Method
  806. ' for sorting !
  807. Method compare:Int(obj:Object)
  808. If TDatePeriod(obj) Then
  809. If isLess(TDatePeriod(obj)) Then Return -1
  810. If isEqual(TDatePeriod(obj)) Then Return 0
  811. Return 1
  812. End If
  813. Return Super.compare(obj)
  814. End Method
  815. Rem
  816. bbdoc: To [YYYY-mmm-DD/YYYY-mmm-DD] string where mmm is 3 char month name.
  817. End Rem
  818. Method toString:String()
  819. Return bmx_datetime_period_to_string(datePeriodPtr)
  820. End Method
  821. Method Delete()
  822. If datePeriodPtr Then
  823. bmx_datetime_period_free(datePeriodPtr)
  824. datePeriodPtr = Null
  825. End If
  826. End Method
  827. End Type
  828. Rem
  829. bbdoc: Base type for date iterators.
  830. about: The methods #forward and #backward will move along the time-line based on the size of the offset
  831. as defined when the iterator is created.
  832. See #TDateDayIterator, #TDateMonthIterator and #TDateYearIterator for implementations.
  833. End Rem
  834. Type TDateIterator Extends TDate Abstract
  835. Rem
  836. bbdoc: Move date forward one step.
  837. End Rem
  838. Method forward()
  839. bmx_datetime_iter_forward(datePtr)
  840. End Method
  841. Rem
  842. bbdoc: Move date backward one step.
  843. End Rem
  844. Method backward()
  845. bmx_datetime_iter_backward(datePtr)
  846. End Method
  847. ' following methods are overriden.... it's a tad messy, but it was the only way it would work.
  848. Method isBefore:Int(when:TDate)
  849. Return bmx_datetime_iter_before(datePtr, when.datePtr)
  850. End Method
  851. Method isAfter:Int(when:TDate)
  852. Return bmx_datetime_iter_after(datePtr, when.datePtr)
  853. End Method
  854. Method isEqual:Int(when:TDate)
  855. Return bmx_datetime_iter_equals(datePtr, when.datePtr)
  856. End Method
  857. Method year:Int()
  858. Return bmx_datetime_iter_year(datePtr)
  859. End Method
  860. Method Month:Int()
  861. Return bmx_datetime_iter_month(datePtr)
  862. End Method
  863. Method day:Int()
  864. Return bmx_datetime_iter_day(datePtr)
  865. End Method
  866. Method ymd(year:Int Var, _month:Int Var, day:Int Var)
  867. bmx_datetime_iter_ymd(datePtr,Varptr year,Varptr _month,Varptr day)
  868. End Method
  869. Method dayOfWeek:Int()
  870. Return bmx_datetime_iter_day_of_week(datePtr)
  871. End Method
  872. Method dayOfYear:Int()
  873. Return bmx_datetime_iter_day_of_year(datePtr)
  874. End Method
  875. Method lastDayOfMonth:TDate()
  876. Return New TDate(bmx_datetime_iter_end_of_month(datePtr))
  877. End Method
  878. Method weekNumber:Int()
  879. Return bmx_datetime_iter_week_number(datePtr)
  880. End Method
  881. Method add:TDate(duration:Int)
  882. Return New TDate(bmx_datetime_iter_date_add(datePtr, duration))
  883. End Method
  884. Method subtract:TDate(duration:Int)
  885. Return New TDate(bmx_datetime_iter_date_subtract(datePtr, duration))
  886. End Method
  887. Method subtractDate:Int(date:TDate)
  888. Return bmx_datetime_iter_date_subdate(datePtr, date.datePtr)
  889. End Method
  890. Method toString:String()
  891. Return bmx_datetime_iter_to_string(datePtr, currentDateFacet.localePtr, currentDateFacet.facetPtr)
  892. End Method
  893. Method toISOString:String()
  894. Return bmx_datetime_iter_to_iso_string(datePtr)
  895. End Method
  896. Method toISOExtendedString:String()
  897. Return bmx_datetime_iter_to_iso_extended_string(datePtr)
  898. End Method
  899. Method format:String(f:String, facet:TDateFacet = Null)
  900. If facet Then
  901. Return bmx_datetime_iter_asformat(datePtr, f, facet.localePtr, facet.facetPtr)
  902. Else
  903. Return bmx_datetime_iter_asformat(datePtr, f, currentDateFacet.localePtr, currentDateFacet.facetPtr)
  904. End If
  905. End Method
  906. Method Delete()
  907. If datePtr Then
  908. bmx_datetime_iter_free(datePtr)
  909. datePtr = Null
  910. End If
  911. End Method
  912. End Type
  913. Rem
  914. bbdoc: A #TDateIterator for stepping over days.
  915. End Rem
  916. Type TDateDayIterator Extends TDateIterator
  917. Rem
  918. bbdoc: Creates a new #TDateDayIterator from @date for the step size of @offset days.
  919. End Rem
  920. Method New(date:TDate, offset:Int = 1)
  921. datePtr = bmx_datetime_dayiter(date.datePtr, offset)
  922. End Method
  923. End Type
  924. Rem
  925. bbdoc: A #TDateIterator for stepping over months.
  926. End Rem
  927. Type TDateMonthIterator Extends TDateIterator
  928. Rem
  929. bbdoc: Creates a new #TDateMonthIterator from @date for the step size of @offset months.
  930. End Rem
  931. Method New(date:TDate, offset:Int = 1)
  932. datePtr = bmx_datetime_monthiter(date.datePtr, offset)
  933. End Method
  934. End Type
  935. Rem
  936. bbdoc: A #TDateIterator for stepping over years.
  937. End Rem
  938. Type TDateYearIterator Extends TDateIterator
  939. Rem
  940. bbdoc: Creates a new #TDateYearIterator from @date for the step size of @offset years.
  941. End Rem
  942. Method New(date:TDate, offset:Int = 1)
  943. datePtr = bmx_datetime_yeariter(date.datePtr, offset)
  944. End Method
  945. End Type
  946. Rem
  947. bbdoc: #TTime is the primary interface for time point manipulation.
  948. End Rem
  949. Type TTime
  950. Field ptimePtr:Byte Ptr
  951. Private
  952. Method New(ptimePtr:Byte Ptr)
  953. Self.ptimePtr = ptimePtr
  954. End Method
  955. Public
  956. Rem
  957. bbdoc: Get the local time, second level resolution, based on the time zone settings of the computer.
  958. about:
  959. <pre>
  960. SuperStrict
  961. Framework Boost.DateTime
  962. Import BRL.StandardIO
  963. Local t:TTime = New TTime()
  964. Print t.toString()
  965. </pre>
  966. <a href="../examples/ttime_createLocal.bmx">Example source</a>
  967. End Rem
  968. Method New()
  969. New(bmx_ptime_local_new())
  970. End Method
  971. Rem
  972. bbdoc: Constructs a new #TTime from a date and offset.
  973. about:
  974. <pre>
  975. SuperStrict
  976. Framework Boost.DateTime
  977. Import BRL.StandardIO
  978. Local d:TDate = New TDate(2002, Jan, 1)
  979. Local t:TTime = New TTime(d, TDHours(14))
  980. Print t.toString()
  981. </pre>
  982. <a href="../examples/ttime_create.bmx">Example source</a>
  983. End Rem
  984. Method New(date:TDate, offset:TTimeDuration)
  985. New(bmx_ptime_new(date.datePtr, offset.durationPtr))
  986. End Method
  987. Rem
  988. bbdoc: Get the UTC time.
  989. about:
  990. <pre>
  991. SuperStrict
  992. Framework Boost.DateTime
  993. Import BRL.StandardIO
  994. Local t:TTime = New TTimeUniversal()
  995. Print t.toString()
  996. </pre>
  997. <a href="../examples/ttime_createUniversal.bmx">Example source</a>
  998. End Rem
  999. Function Universal:TTime()
  1000. Return New TTime(bmx_ptime_universal_new())
  1001. End Function
  1002. Rem
  1003. bbdoc: Get the local time using a sub second resolution clock.
  1004. about: On Unix systems this is implemented using <tt>GetTimeOfDay</tt>.
  1005. On most Win32 platforms it is implemented using <tt>ftime</tt>. Win32 systems often do not achieve
  1006. microsecond resolution via this API. If higher resolution is critical to your application
  1007. test your platform to see the achieved resolution.
  1008. End Rem
  1009. Function LocalMS:TTime()
  1010. Return New TTime(bmx_ptime_local_microsecond_new())
  1011. End Function
  1012. Rem
  1013. bbdoc: Get the UTC time using a sub second resolution clock.
  1014. about: On Unix systems this is implemented using <tt>GetTimeOfDay</tt>. On most Win32 platforms it is
  1015. implemented using <tt>ftime</tt>. Win32 systems often do not achieve microsecond resolution via this API.
  1016. If higher resolution is critical to your application test your platform to see the achieved resolution.
  1017. End Rem
  1018. Function UniversalMS:TTime()
  1019. Return New TTime(bmx_ptime_universal_microsecond_new())
  1020. End Function
  1021. Rem
  1022. bbdoc: Converts a #FileTime value to a #TTime.
  1023. about: This value is the number of seconds from 1-Jan-1970.<br>
  1024. #FileTime returns the time at UTC, so you will need to apply your local offset to get
  1025. the correct local system time.
  1026. End Rem
  1027. Function FromFileTime:TTime(time:Int)
  1028. ' since the "proper" call didn't work, we do what it does internally, and add seconds to base date!
  1029. Return New TTime(New TDate(1970, 1, 1), TDSeconds(time))
  1030. End Function
  1031. Rem
  1032. bbdoc: Converts a time_t struct to a #TTime.
  1033. End Rem
  1034. Function FromTimeT:TTime(time:Byte Ptr)
  1035. ' since the "proper" call didn't work, we construct the date + time from the struct ourselves!
  1036. Local tm:Int Ptr = Int Ptr(time)
  1037. Return New TTime(New TDate(tm[5] + 1900, tm[4] + 1, tm[3]), TDHours(tm[2]).add(TDMinutes(tm[1])).add(TDSeconds(tm[0])))
  1038. End Function
  1039. Rem
  1040. bbdoc: Get the date part of a time.
  1041. about:
  1042. <pre>
  1043. SuperStrict
  1044. Framework Boost.DateTime
  1045. Import BRL.StandardIO
  1046. Local d:TDate = New TDate(2002, Jan, 10)
  1047. Local t:TTime = New TTime(d, TDHours(1))
  1048. Print t.date().toString()
  1049. </pre>
  1050. <a href="../examples/ttime_date.bmx">Example source</a>
  1051. End Rem
  1052. Method date:TDate()
  1053. Return New TDate(bmx_ptime_date(ptimePtr))
  1054. End Method
  1055. Rem
  1056. bbdoc: Get the time offset in the day.
  1057. about:
  1058. <pre>
  1059. SuperStrict
  1060. Framework Boost.DateTime
  1061. Import BRL.StandardIO
  1062. Local d:TDate = New TDate(2002, Jan, 10)
  1063. Local t:TTime = New TTime(d, TDHours(1))
  1064. Print t.timeOfDay().toString()
  1065. </pre>
  1066. <a href="../examples/ttime_timeOfDay.bmx">Example source</a>
  1067. End Rem
  1068. Method timeOfDay:TTimeDuration()
  1069. Return New TTimeDuration(bmx_ptime_time_of_day(ptimePtr))
  1070. End Method
  1071. Rem
  1072. bbdoc: To YYYY-mmm-DD HH:MM:SS.fffffffff string where mmm 3 char month name.
  1073. about: Fractional seconds only included if non-zero.
  1074. End Rem
  1075. Method toString:String()
  1076. Return bmx_ptime_to_string(ptimePtr, currentDateFacet.localePtr, currentDateFacet.facetPtr)
  1077. End Method
  1078. Rem
  1079. bbdoc: Convert to form YYYYMMDDTHHMMSS,fffffffff where T is the date-time separator.
  1080. End Rem
  1081. Method toISOString:String()
  1082. Return bmx_ptime_to_iso_string(ptimePtr)
  1083. End Method
  1084. Rem
  1085. bbdoc: Convert to form YYYY-MM-DDTHH:MM:SS,fffffffff where T is the date-time separator.
  1086. End Rem
  1087. Method toISOExtendedString:String()
  1088. Return bmx_ptime_to_iso_extended_string(ptimePtr)
  1089. End Method
  1090. Rem
  1091. bbdoc: Adds @days to time, returning a new #TTime.
  1092. about:
  1093. <pre>
  1094. SuperStrict
  1095. Framework Boost.DateTime
  1096. Import BRL.StandardIO
  1097. Local d:TDate = New TDate(2002, Jan, 1)
  1098. Local t:TTime = New TTime(d, TDMinutes(5))
  1099. Local t2:TTime = t.addDays(1)
  1100. Print t.toString()
  1101. Print t2.toString()
  1102. </pre>
  1103. <a href="../examples/ttime_addDays.bmx">Example source</a>
  1104. End Rem
  1105. Method addDays:TTime(days:Int)
  1106. Return New TTime(bmx_ptime_add_days(ptimePtr, days))
  1107. End Method
  1108. Rem
  1109. bbdoc: Subtracts @days from time, returning a new #TTime.
  1110. about:
  1111. <pre>
  1112. SuperStrict
  1113. Framework Boost.DateTime
  1114. Import BRL.StandardIO
  1115. Local d:TDate = New TDate(2002, Jan, 1)
  1116. Local t:TTime = New TTime(d, TDMinutes(5))
  1117. Local t2:TTime = t.subtractDays(1)
  1118. Print t.toString()
  1119. Print t2.toString()
  1120. </pre>
  1121. <a href="../examples/ttime_subtractDays.bmx">Example source</a>
  1122. End Rem
  1123. Method subtractDays:TTime(days:Int)
  1124. Return New TTime(bmx_ptime_subtract_days(ptimePtr, days))
  1125. End Method
  1126. Rem
  1127. bbdoc: Adds @duration to the time, returning a new #TTime.
  1128. about:
  1129. <pre>
  1130. SuperStrict
  1131. Framework Boost.DateTime
  1132. Import BRL.StandardIO
  1133. Local d:TDate = New TDate(2002, Jan, 1)
  1134. Local t:TTime = New TTime(d, TDMinutes(5))
  1135. Local t2:TTime = t.addDuration(TDHours(1).add(TDMinutes(2)))
  1136. Print t.toString()
  1137. Print t2.toString()
  1138. </pre>
  1139. <a href="../examples/ttime_addDuration.bmx">Example source</a>
  1140. End Rem
  1141. Method addDuration:TTime(duration:TTimeDuration)
  1142. Return New TTime(bmx_ptime_add_duration(ptimePtr, duration.durationPtr))
  1143. End Method
  1144. Rem
  1145. bbdoc: Subtracts @duration from the time, returning a new #TTime.
  1146. about:
  1147. <pre>
  1148. SuperStrict
  1149. Framework Boost.DateTime
  1150. Import BRL.StandardIO
  1151. Local d:TDate = New TDate(2002, Jan, 1)
  1152. Local t:TTime = New TTime(d, TDMinutes(5))
  1153. Local t2:TTime = t.subtractDuration(TDMinutes(2))
  1154. Print t.toString()
  1155. Print t2.toString()
  1156. </pre>
  1157. <a href="../examples/ttime_subtractDuration.bmx">Example source</a>
  1158. End Rem
  1159. Method subtractDuration:TTime(duration:TTimeDuration)
  1160. Return New TTime(bmx_ptime_subtract_duration(ptimePtr, duration.durationPtr))
  1161. End Method
  1162. Rem
  1163. bbdoc: Subtracts @time from the time, returning a #TTimeDuration
  1164. about:
  1165. <pre>
  1166. SuperStrict
  1167. Framework Boost.DateTime
  1168. Import BRL.StandardIO
  1169. Local d:TDate = New TDate(2002, Jan, 1)
  1170. Local t1:TTime = New TTime(d, TDMinutes(5))
  1171. Local t2:TTime = New TTime(d, TDMinutes(2))
  1172. Print t2.subtract(t1).toString() ' negative result
  1173. </pre>
  1174. <a href="../examples/ttime_subtract.bmx">Example source</a>
  1175. End Rem
  1176. Method subtract:TTimeDuration(time:TTime)
  1177. Return New TTimeDuration(bmx_ptime_subtract(ptimePtr, time.ptimePtr))
  1178. End Method
  1179. Rem
  1180. bbdoc: True if this time is less than the parameter.
  1181. End Rem
  1182. Method isLess:Int(time:TTime)
  1183. Return bmx_ptime_less(ptimePtr, time.ptimePtr)
  1184. End Method
  1185. Rem
  1186. bbdoc: True if this time is greater than the parameter.
  1187. End Rem
  1188. Method isGreater:Int(time:TTime)
  1189. Return bmx_ptime_greater(ptimePtr, time.ptimePtr)
  1190. End Method
  1191. Rem
  1192. bbdoc: True if the two times are equal.
  1193. End Rem
  1194. Method isEqual:Int(time:TTime)
  1195. Return bmx_ptime_equal(ptimePtr, time.ptimePtr)
  1196. End Method
  1197. Rem
  1198. bbdoc:
  1199. End Rem
  1200. Method format:String(f:String, facet:TTimeFacet = Null)
  1201. If facet Then
  1202. Return bmx_ptime_asformat(ptimePtr, f, facet.localePtr, facet.facetPtr)
  1203. Else
  1204. Return bmx_ptime_asformat(ptimePtr, f, currentTimeFacet.localePtr, currentTimeFacet.facetPtr)
  1205. End If
  1206. End Method
  1207. ' for sorting !
  1208. Method compare:Int(obj:Object)
  1209. If TTime(obj) Then
  1210. If isLess(TTime(obj)) Then Return -1
  1211. If isEqual(TTime(obj)) Then Return 0
  1212. Return 1
  1213. End If
  1214. Return Super.compare(obj)
  1215. End Method
  1216. Method Delete()
  1217. If ptimePtr Then
  1218. bmx_ptime_free(ptimePtr)
  1219. ptimePtr = Null
  1220. End If
  1221. End Method
  1222. End Type
  1223. Rem
  1224. bbdoc: Represents a length of time.
  1225. End Rem
  1226. Type TTimeDuration
  1227. Field durationPtr:Byte Ptr
  1228. Private
  1229. Method New()
  1230. End Method
  1231. Method New(durationPtr:Byte Ptr)
  1232. Self.durationPtr = durationPtr
  1233. End Method
  1234. Public
  1235. Rem
  1236. bbdoc: Creates a new #TTimeDuration from the counts.
  1237. about: The @fractions parameter is a number of units and is therefore affected by the resolution
  1238. the application is compiled with. If the @fractions argument exceeds the limit of the compiled
  1239. precision, the excess value will be "carried over" into the seconds field.<br>
  1240. Ths following is a technique using #TicksPerSecond for creating a resolution independent
  1241. fractions count :
  1242. <pre>
  1243. Local numberOfTenths:Int = 5
  1244. ' create a resolution independent count -- divide by 10 since there are 10 tenths in a second.
  1245. Local count:Int = numberOfTenths * (TicksPerSecond() / 10)
  1246. Local duration:TTimeDuration = New TTimeDuration(1, 2, 3, count) ' 01:02:03.5 - no matter the resolution settings
  1247. </pre>
  1248. End Rem
  1249. Method New(hours:Int = 0, minutes:Int = 0, seconds:Int = 0, fractions:Int = 0)
  1250. New(bmx_time_duration(hours, minutes, seconds, fractions))
  1251. End Method
  1252. Rem
  1253. bbdoc: Creates a new #TTimeDuration for the number of hours.
  1254. about:
  1255. <pre>
  1256. SuperStrict
  1257. Framework Boost.DateTime
  1258. Import BRL.StandardIO
  1259. Local td:TTimeDuration = TTimeDuration.Hour(10)
  1260. Print td.toString()
  1261. </pre>
  1262. <a href="../examples/ttimeduration_hour.bmx">Example source</a>
  1263. End Rem
  1264. Function Hour:TTimeDuration(hours:Int)
  1265. Return New TTimeDuration(bmx_time_duration_new_hours(hours))
  1266. End Function
  1267. Rem
  1268. bbdoc: Creates a new #TTimeDuration for the number of minutes.
  1269. about:
  1270. <pre>
  1271. SuperStrict
  1272. Framework Boost.DateTime
  1273. Import BRL.StandardIO
  1274. Local td:TTimeDuration = TTimeDuration.Minute(7)
  1275. Print td.toString()
  1276. </pre>
  1277. <a href="../examples/ttimeduration_minute.bmx">Example source</a>
  1278. End Rem
  1279. Function Minute:TTimeDuration(minutes:Int)
  1280. Return New TTimeDuration(bmx_time_duration_new_minutes(minutes))
  1281. End Function
  1282. Rem
  1283. bbdoc: Creates a new #TTimeDuration for the number of seconds.
  1284. about:
  1285. <pre>
  1286. SuperStrict
  1287. Framework Boost.DateTime
  1288. Import BRL.StandardIO
  1289. Local td:TTimeDuration = TTimeDuration.Second(45)
  1290. Print td.toString()
  1291. </pre>
  1292. <a href="../examples/ttimeduration_second.bmx">Example source</a>
  1293. End Rem
  1294. Function Second:TTimeDuration(seconds:Int)
  1295. Return New TTimeDuration(bmx_time_duration_new_seconds(seconds))
  1296. End Function
  1297. Rem
  1298. bbdoc: Creates a new #TTimeDuration for the number of milliseconds.
  1299. about:
  1300. <pre>
  1301. SuperStrict
  1302. Framework Boost.DateTime
  1303. Import BRL.StandardIO
  1304. Local td:TTimeDuration = TTimeDuration.Millisecond(180)
  1305. Print td.toString()
  1306. </pre>
  1307. <a href="../examples/ttimeduration_millisecond.bmx">Example source</a>
  1308. End Rem
  1309. Function Millisecond:TTimeDuration(milliseconds:Int)
  1310. Return New TTimeDuration(bmx_time_duration_new_milliseconds(milliseconds))
  1311. End Function
  1312. Rem
  1313. bbdoc: Get the number of normalized hours.
  1314. End Rem
  1315. Method hours:Int()
  1316. Return bmx_time_duration_hours(durationPtr)
  1317. End Method
  1318. Rem
  1319. bbdoc: Get the number of minutes normalized +/-(0..59).
  1320. End Rem
  1321. Method minutes:Int()
  1322. Return bmx_time_duration_minutes(durationPtr)
  1323. End Method
  1324. Rem
  1325. bbdoc: Get the normalized number of second +/-(0..59).
  1326. End Rem
  1327. Method seconds:Int()
  1328. Return bmx_time_duration_seconds(durationPtr)
  1329. End Method
  1330. Rem
  1331. bbdoc: Get the total number of seconds truncating any fractional seconds.
  1332. End Rem
  1333. Method totalSeconds:Int()
  1334. Return bmx_time_duration_total_seconds(durationPtr)
  1335. End Method
  1336. Rem
  1337. bbdoc: Get the total number of milliseconds truncating any remaining digits.
  1338. End Rem
  1339. Method totalMilliseconds:Int()
  1340. Return bmx_time_duration_total_milliseconds(durationPtr)
  1341. End Method
  1342. Rem
  1343. bbdoc: Get the number of fractional seconds.
  1344. End Rem
  1345. Method fractionalSeconds:Int()
  1346. Return bmx_time_duration_fractional_seconds(durationPtr)
  1347. End Method
  1348. Rem
  1349. bbdoc: True if duration is negative.
  1350. End Rem
  1351. Method isNegative:Int()
  1352. Return bmx_time_duration_is_negative(durationPtr)
  1353. End Method
  1354. Rem
  1355. bbdoc: Generate a new duration with the sign inverted.
  1356. about:
  1357. <pre>
  1358. SuperStrict
  1359. Framework Boost.DateTime
  1360. Import BRL.StandardIO
  1361. Local td:TTimeDuration = TDHours(12)
  1362. Print td.toString()
  1363. Print td.invertSign().toString()
  1364. </pre>
  1365. <a href="../examples/ttimeduration_invertSign.bmx">Example source</a>
  1366. End Rem
  1367. Method invertSign:TTimeDuration()
  1368. Return New TTimeDuration(bmx_time_duration_invert_sign(durationPtr))
  1369. End Method
  1370. Rem
  1371. bbdoc: To HH:MM:SS.fffffffff where fff is fractional seconds that are only included if non-zero.
  1372. End Rem
  1373. Method toString:String()
  1374. Return bmx_time_duration_to_string(durationPtr)
  1375. End Method
  1376. Rem
  1377. bbdoc: Converts to a string in the form HHMMSS,fffffffff.
  1378. End Rem
  1379. Method toISOString:String()
  1380. Return bmx_time_duration_to_iso_string(durationPtr)
  1381. End Method
  1382. Rem
  1383. bbdoc: Adds @duration to this duration, returning the result in a new #TTimeDuration
  1384. about:
  1385. <pre>
  1386. SuperStrict
  1387. Framework Boost.DateTime
  1388. Import BRL.StandardIO
  1389. Local td:TTimeDuration = TDHours(12).add(TDMinutes(35)).add(TDSeconds(12))
  1390. Print td.toString()
  1391. </pre>
  1392. <a href="../examples/ttimeduration_add.bmx">Example source</a>
  1393. End Rem
  1394. Method add:TTimeDuration(duration:TTimeDuration)
  1395. Return New TTimeDuration(bmx_time_duration_add(durationPtr, duration.durationPtr))
  1396. End Method
  1397. Rem
  1398. bbdoc: Subtracts @duration from this duration, returning the result in a new #TTimeDuration
  1399. about:
  1400. <pre>
  1401. SuperStrict
  1402. Framework Boost.DateTime
  1403. Import BRL.StandardIO
  1404. Local td1:TTimeDuration = New TTimeDuration(12, 30, 20)
  1405. Local td2:TTimeDuration = New TTimeDuration(1, 30, 20)
  1406. Print td1.subtract(td2).toString()
  1407. </pre>
  1408. <a href="../examples/ttimeduration_subtract.bmx">Example source</a>
  1409. End Rem
  1410. Method subtract:TTimeDuration(duration:TTimeDuration)
  1411. Return New TTimeDuration(bmx_time_duration_subtract(durationPtr, duration.durationPtr))
  1412. End Method
  1413. Rem
  1414. bbdoc: Divides the length of the duration by @value.
  1415. about: Discards any remainder.
  1416. <pre>
  1417. SuperStrict
  1418. Framework Boost.DateTime
  1419. Import BRL.StandardIO
  1420. Local td:TTimeDuration = New TTimeDuration(18, 30) ' 18 hours and 30 mins
  1421. Print td.divide(2).toString() ' 9 hours and 15 mins
  1422. </pre>
  1423. <a href="../examples/ttimeduration_divide.bmx">Example source</a>
  1424. End Rem
  1425. Method divide:TTimeDuration(value:Int)
  1426. Return New TTimeDuration(bmx_time_duration_divide(durationPtr, value))
  1427. End Method
  1428. Rem
  1429. bbdoc: Multiplies the length of the duration by @value.
  1430. about:
  1431. <pre>
  1432. SuperStrict
  1433. Framework Boost.DateTime
  1434. Import BRL.StandardIO
  1435. Local td:TTimeDuration = New TTimeDuration(4, 10, 6)
  1436. Print td.multiply(3).toString()
  1437. </pre>
  1438. <a href="../examples/ttimeduration_multiply.bmx">Example source</a>
  1439. End Rem
  1440. Method multiply:TTimeDuration(value:Int)
  1441. Return New TTimeDuration(bmx_time_duration_multiply(durationPtr, value))
  1442. End Method
  1443. Rem
  1444. bbdoc: True if this duration is less than the parameter.
  1445. End Rem
  1446. Method isLess:Int(duration:TTimeDuration)
  1447. Return bmx_time_duration_less(durationPtr, duration.durationPtr)
  1448. End Method
  1449. Rem
  1450. bbdoc: True if this duration is greater than the parameter.
  1451. End Rem
  1452. Method isGreater:Int(duration:TTimeDuration)
  1453. Return bmx_time_duration_greater(durationPtr, duration.durationPtr)
  1454. End Method
  1455. Rem
  1456. bbdoc: True if the durations are equal.
  1457. End Rem
  1458. Method isEqual:Int(duration:TTimeDuration)
  1459. Return bmx_time_duration_equal(durationPtr, duration.durationPtr)
  1460. End Method
  1461. Rem
  1462. bbdoc:
  1463. End Rem
  1464. Method format:String(f:String, facet:TTimeFacet = Null)
  1465. If facet Then
  1466. Return bmx_time_duration_asformat(durationPtr, f, facet.localePtr, facet.facetPtr)
  1467. Else
  1468. Return bmx_time_duration_asformat(durationPtr, f, currentTimeFacet.localePtr, currentTimeFacet.facetPtr)
  1469. End If
  1470. End Method
  1471. ' for sorting !
  1472. Method compare:Int(obj:Object)
  1473. If TTimeDuration(obj) Then
  1474. If isLess(TTimeDuration(obj)) Then Return -1
  1475. If isEqual(TTimeDuration(obj)) Then Return 0
  1476. Return 1
  1477. End If
  1478. Return Super.compare(obj)
  1479. End Method
  1480. Method Delete()
  1481. If durationPtr Then
  1482. bmx_time_duration_free(durationPtr)
  1483. durationPtr = Null
  1484. End If
  1485. End Method
  1486. End Type
  1487. Rem
  1488. bbdoc: #TimePeriod provides direct representation for ranges between two times.
  1489. about: Periods provide the ability to simplify some types of calculations by simplifying the
  1490. conditional logic of the program.<br>
  1491. A period that is created with beginning and end points being equal, or with a duration of zero,
  1492. is known as a zero length period. Zero length periods are considered invalid (it is perfectly legal to
  1493. construct an invalid period). For these periods, the last point will always be one unit less that the
  1494. begin point.
  1495. End Rem
  1496. Type TTimePeriod
  1497. Field timePeriodPtr:Byte Ptr
  1498. Private
  1499. Method New()
  1500. End Method
  1501. Method New(timePeriodPtr:Byte Ptr)
  1502. Self.timePeriodPtr = timePeriodPtr
  1503. End Method
  1504. Public
  1505. Rem
  1506. bbdoc: Create a period as [begin, end).
  1507. about: If end is <= begin then the period will be defined as invalid.
  1508. End Rem
  1509. Method New(beginTime:TTime, endTime:TTime)
  1510. New(bmx_time_period_timetime(beginTime.ptimePtr, endTime.ptimePtr))
  1511. End Method
  1512. Rem
  1513. bbdoc: Create a period as [begin, begin + duration) where end would be begin + duration.
  1514. about: If duration is <= zero then the period will be defined as invalid.
  1515. End Rem
  1516. Method New(beginTime:TTime, duration:TTimeDuration)
  1517. New(bmx_time_period_withduration(beginTime.ptimePtr, duration.durationPtr))
  1518. End Method
  1519. Rem
  1520. bbdoc: Add @duration to both begin and end.
  1521. End Rem
  1522. Method shift(duration:TTimeDuration)
  1523. bmx_time_period_shift(timePeriodPtr, duration.durationPtr)
  1524. End Method
  1525. Rem
  1526. bbdoc: Return first time of period.
  1527. End Rem
  1528. Method begin:TTime()
  1529. Return New TTime(bmx_time_period_begin(timePeriodPtr))
  1530. End Method
  1531. Rem
  1532. bbdoc: Return last time in the period
  1533. End Rem
  1534. Method last:TTime()
  1535. Return New TTime(bmx_time_period_last(timePeriodPtr))
  1536. End Method
  1537. Rem
  1538. bbdoc: Return one past the last in period
  1539. End Rem
  1540. Method periodEnd:TTime()
  1541. Return New TTime(bmx_time_period_end(timePeriodPtr))
  1542. End Method
  1543. Rem
  1544. bbdoc: Return the length of the time period.
  1545. End Rem
  1546. Method length:TTimeDuration()
  1547. Return New TTimeDuration(bmx_time_period_length(timePeriodPtr))
  1548. End Method
  1549. Rem
  1550. bbdoc: True if period is not well formed.
  1551. about: eg. end is less than or equal to begin.
  1552. End Rem
  1553. Method isNull:Int()
  1554. Return bmx_time_period_is_null(timePeriodPtr)
  1555. End Method
  1556. Rem
  1557. bbdoc: True if @time is within the period.
  1558. about: Zero length periods cannot contain any points.
  1559. End Rem
  1560. Method contains:Int(time:TTime)
  1561. Return bmx_time_period_contains(timePeriodPtr, time.ptimePtr)
  1562. End Method
  1563. Rem
  1564. bbdoc: True if @period is within the period
  1565. End Rem
  1566. Method containsPeriod:Int(period:TTimePeriod)
  1567. Return bmx_time_period_containsPeriod(timePeriodPtr, period.timePeriodPtr)
  1568. End Method
  1569. Rem
  1570. bbdoc: True if periods overlap.
  1571. End Rem
  1572. Method intersects:Int(period:TTimePeriod)
  1573. Return bmx_time_period_intersects(timePeriodPtr, period.timePeriodPtr)
  1574. End Method
  1575. Rem
  1576. bbdoc: Calculate the intersection of 2 periods.
  1577. about: Null if no intersection.
  1578. End Rem
  1579. Method intersection:TTimePeriod(period:TTimePeriod)
  1580. Return New TTimePeriod(bmx_time_period_intersection(timePeriodPtr, period.timePeriodPtr))
  1581. End Method
  1582. Rem
  1583. bbdoc: Returns union of two periods.
  1584. about: Null if no intersection.
  1585. End Rem
  1586. Method merge:TTimePeriod(period:TTimePeriod)
  1587. Return New TTimePeriod(bmx_time_period_merge(timePeriodPtr, period.timePeriodPtr))
  1588. End Method
  1589. Rem
  1590. bbdoc: Combines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).
  1591. End Rem
  1592. Method span:TTimePeriod(period:TTimePeriod)
  1593. Return New TTimePeriod(bmx_time_period_span(timePeriodPtr, period.timePeriodPtr))
  1594. End Method
  1595. Rem
  1596. bbdoc: To [YYYY-mmm-DD hh:mm:ss.fffffffff/YYYY-mmm-DD hh:mm:ss.fffffffff] string where mmm is 3 char month name.
  1597. End Rem
  1598. Method toString:String()
  1599. Return bmx_time_period_to_simple_string(timePeriodPtr)
  1600. End Method
  1601. Rem
  1602. bbdoc: True if end is less than period.begin.
  1603. End Rem
  1604. Method isLess:Int(period:TTimePeriod)
  1605. Return bmx_time_period_isless(timePeriodPtr, period.timePeriodPtr)
  1606. End Method
  1607. Rem
  1608. bbdoc: True if begin greater than period.end
  1609. End Rem
  1610. Method isGreater:Int(period:TTimePeriod)
  1611. Return bmx_time_period_isgreater(timePeriodPtr, period.timePeriodPtr)
  1612. End Method
  1613. Rem
  1614. bbdoc: True if periods are the same.
  1615. End Rem
  1616. Method isEqual:Int(period:TTimePeriod)
  1617. Return bmx_time_period_isequal(timePeriodPtr, period.timePeriodPtr)
  1618. End Method
  1619. ' for sorting !
  1620. Method compare:Int(obj:Object)
  1621. If TTimePeriod(obj) Then
  1622. If isLess(TTimePeriod(obj)) Then Return -1
  1623. If isEqual(TTimePeriod(obj)) Then Return 0
  1624. Return 1
  1625. End If
  1626. Return Super.compare(obj)
  1627. End Method
  1628. Method Delete()
  1629. If timePeriodPtr Then
  1630. bmx_time_period_free(timePeriodPtr)
  1631. timePeriodPtr = Null
  1632. End If
  1633. End Method
  1634. End Type
  1635. Rem
  1636. bbdoc: The Time Zone Database (#TTZDatabase) is a store of time zone information.
  1637. about: The specifications for many time zones (377 at this time) are provided.
  1638. These specifications are based on data found in the
  1639. <a href="http://www.twinsun.com/tz/tz-link.htm">zoneinfo database</a>. The specifications are stored in
  1640. the file: <tt>data/date_time_zonespec.csv</tt>
  1641. End Rem
  1642. Type TTZDatabase
  1643. Field tzDatabasePtr:Byte Ptr
  1644. Private
  1645. Method New(tzDatabasePtr:Byte Ptr)
  1646. Self.tzDatabasePtr = tzDatabasePtr
  1647. End Method
  1648. Public
  1649. Rem
  1650. bbdoc: Creates an empty #TTZDatabase.
  1651. End Rem
  1652. Method New()
  1653. New(bmx_tz_database())
  1654. End Method
  1655. Rem
  1656. bbdoc: Creates and populates a #TTZDatabase with time zone records found in the zone spec file.
  1657. End Rem
  1658. Function LoadFromFile:TTZDatabase(filename:String)
  1659. Return New TTZDatabase(bmx_tz_load_from_file(filename))
  1660. End Function
  1661. Rem
  1662. bbdoc: Adds a time zone, to the database.
  1663. about: @id is the region name for this zone (e.g. "America/Phoenix").
  1664. End Rem
  1665. Method addRecord(id:String, zone:TTimeZone)
  1666. bmx_tz_database_add_record(tzDatabasePtr, id, zone.timeZonePtr)
  1667. End Method
  1668. Rem
  1669. bbdoc: Returns a time zone that matches the region listed in the data file.
  1670. returns: a #TTimeZone or Null if not found.
  1671. End Rem
  1672. Method timeZoneFromRegion:TTimeZone(id:String)
  1673. Return New TTimeZone(bmx_tz_time_zone_from_region(tzDatabasePtr, id))
  1674. End Method
  1675. Rem
  1676. bbdoc: Returns an array of strings that holds all the region ID strings from the database.
  1677. End Rem
  1678. Method regionList:String[]()
  1679. Return bmx_tz_database_region_list(tzDatabasePtr)
  1680. End Method
  1681. Method Delete()
  1682. If tzDatabasePtr Then
  1683. bmx_tz_database_free(tzDatabasePtr)
  1684. tzDatabasePtr = Null
  1685. End If
  1686. End Method
  1687. End Type
  1688. Rem
  1689. bbdoc: A #TLocalDateTime object is a point in time and an associated time zone.
  1690. about: The time is represented internally as UTC.
  1691. End Rem
  1692. Type TLocalDateTime
  1693. Field localDateTimePtr:Byte Ptr
  1694. Private
  1695. Method New()
  1696. End Method
  1697. Method New(localDateTimePtr:Byte Ptr)
  1698. Self.localDateTimePtr = localDateTimePtr
  1699. End Method
  1700. Public
  1701. Method New(zone:TTimeZone)
  1702. New(bmx_local_date_time_new_sec_clock(zone.timeZonePtr))
  1703. End Method
  1704. Rem
  1705. bbdoc:
  1706. abtou: The given time is expected to be UTC. Therefore, the given time will be adjusted
  1707. according to the offset described in the time zone.
  1708. End Rem
  1709. Method New(time:TTime, zone:TTimeZone)
  1710. New(bmx_local_date_time_new_time(time.ptimePtr, zone.timeZonePtr))
  1711. End Method
  1712. Rem
  1713. bbdoc: Returns associated #TTimeZone object.
  1714. End Rem
  1715. Method zone:TTimeZone()
  1716. Return New TTimeZone(bmx_local_date_time_zone(localDateTimePtr))
  1717. End Method
  1718. Rem
  1719. bbdoc: Determines if time value is in DST for associated zone.
  1720. End Rem
  1721. Method isDST:Int()
  1722. Return bmx_local_date_time_is_dst(localDateTimePtr)
  1723. End Method
  1724. Rem
  1725. bbdoc: Converts the local time value to a UTC value.
  1726. about:
  1727. <pre>
  1728. SuperStrict
  1729. Framework Boost.DateTime
  1730. Import BRL.StandardIO
  1731. Local pt:TTime = New TTime(New TDate(2004, Nov, 5), TDHours(10))
  1732. Local zone:TTimeZone = New TTimeZone("MST-07")
  1733. Local az:TLocalDateTime = TLocalDateTime.CreateFromTime(pt, zone)
  1734. Print az.UTCTime().toString()
  1735. </pre>
  1736. <a href="../examples/tlocaldatetime_UTCTime.bmx">Example source</a>
  1737. End Rem
  1738. Method UTCTime:TTime()
  1739. Return New TTime(bmx_local_date_time_utc_time(localDateTimePtr))
  1740. End Method
  1741. Rem
  1742. bbdoc: Returns the local time for this object (Wall-clock).
  1743. about:
  1744. <pre>
  1745. SuperStrict
  1746. Framework Boost.DateTime
  1747. Import BRL.StandardIO
  1748. Local pt:TTime = New TTime(New TDate(2004, Nov, 5), TDHours(10))
  1749. Local zone:TTimeZone = New TTimeZone("MST-07")
  1750. Local az:TLocalDateTime = TLocalDateTime.CreateFromTime(pt, zone)
  1751. Print az.UTCTime().toString()
  1752. Print az.localTime().toString()
  1753. </pre>
  1754. <a href="../examples/tlocaldatetime_localTime.bmx">Example source</a>
  1755. End Rem
  1756. Method localTime:TTime()
  1757. Return New TTime(bmx_local_date_time_local_time(localDateTimePtr))
  1758. End Method
  1759. Method toString:String()
  1760. Return bmx_local_date_time_to_string(localDateTimePtr)
  1761. End Method
  1762. Rem
  1763. bbdoc: True if this local date time is less than the parameter.
  1764. End Rem
  1765. Method isLess:Int(ldt:TLocalDateTime)
  1766. Return bmx_local_date_time_less(localDateTimePtr, ldt.localDateTimePtr)
  1767. End Method
  1768. Rem
  1769. bbdoc: True if this local date time is greater than the parameter.
  1770. End Rem
  1771. Method isGreater:Int(ldt:TLocalDateTime)
  1772. Return bmx_local_date_time_greater(localDateTimePtr, ldt.localDateTimePtr)
  1773. End Method
  1774. Rem
  1775. bbdoc: True if the two local date times are equal.
  1776. End Rem
  1777. Method isEqual:Int(ldt:TLocalDateTime)
  1778. Return bmx_local_date_time_equal(localDateTimePtr, ldt.localDateTimePtr)
  1779. End Method
  1780. ' for sorting !
  1781. Method compare:Int(obj:Object)
  1782. If TLocalDateTime(obj) Then
  1783. If isLess(TLocalDateTime(obj)) Then Return -1
  1784. If isEqual(TLocalDateTime(obj)) Then Return 0
  1785. Return 1
  1786. End If
  1787. Return Super.compare(obj)
  1788. End Method
  1789. Rem
  1790. bbdoc: Adds @days to local date time, returning a new #TLocalDateTime.
  1791. End Rem
  1792. Method addDays:TLocalDateTime(days:Int)
  1793. Return New TLocalDateTime(bmx_local_date_time_add_days(localDateTimePtr, days))
  1794. End Method
  1795. Rem
  1796. bbdoc: Adds @months to local date time, returning a new #TLocalDateTime.
  1797. End Rem
  1798. Method addMonths:TLocalDateTime(months:Int)
  1799. Return New TLocalDateTime(bmx_local_date_time_add_months(localDateTimePtr, months))
  1800. End Method
  1801. Rem
  1802. bbdoc: Adds @years to local date time, returning a new #TLocalDateTime.
  1803. End Rem
  1804. Method addYears:TLocalDateTime(years:Int)
  1805. Return New TLocalDateTime(bmx_local_date_time_add_years(localDateTimePtr, years))
  1806. End Method
  1807. Rem
  1808. bbdoc: Subtracts @days from local date time, returning a new #TLocalDateTime.
  1809. End Rem
  1810. Method subtractDays:TLocalDateTime(days:Int)
  1811. Return New TLocalDateTime(bmx_local_date_time_subtract_days(localDateTimePtr, days))
  1812. End Method
  1813. Rem
  1814. bbdoc: Subtracts @months from local date time, returning a new #TLocalDateTime.
  1815. End Rem
  1816. Method subtractMonths:TLocalDateTime(months:Int)
  1817. Return New TLocalDateTime(bmx_local_date_time_subtract_months(localDateTimePtr, months))
  1818. End Method
  1819. Rem
  1820. bbdoc: Subtracts @years from local date time, returning a new #TLocalDateTime.
  1821. End Rem
  1822. Method subtractYears:TLocalDateTime(years:Int)
  1823. Return New TLocalDateTime(bmx_local_date_time_subtract_years(localDateTimePtr, years))
  1824. End Method
  1825. Rem
  1826. bbdoc: Adds @duration to the local date time, returning a new #TLocalDateTime.
  1827. End Rem
  1828. Method addDuration:TLocalDateTime(duration:TTimeDuration)
  1829. Return New TLocalDateTime(bmx_local_date_time_add_duration(localDateTimePtr, duration.durationPtr))
  1830. End Method
  1831. Rem
  1832. bbdoc: Subtracts @duration from the local date time, returning a new #TLocalDateTime.
  1833. End Rem
  1834. Method subtractDuration:TLocalDateTime(duration:TTimeDuration)
  1835. Return New TLocalDateTime(bmx_local_date_time_subtract_duration(localDateTimePtr, duration.durationPtr))
  1836. End Method
  1837. Method Delete()
  1838. If localDateTimePtr Then
  1839. bmx_local_date_time_free(localDateTimePtr)
  1840. localDateTimePtr = Null
  1841. End If
  1842. End Method
  1843. End Type
  1844. Rem
  1845. bbdoc: #TLocalTimePeriod provides direct representation for ranges between two local times.
  1846. about: Periods provide the ability to simplify some types of calculations by simplifying the
  1847. conditional logic of the program.
  1848. End Rem
  1849. Type TLocalTimePeriod
  1850. Field localTimePeriodPtr:Byte Ptr
  1851. Private
  1852. Method New()
  1853. End Method
  1854. Method New(localTimePeriodPtr:Byte Ptr)
  1855. Self.localTimePeriodPtr = localTimePeriodPtr
  1856. End Method
  1857. Public
  1858. Rem
  1859. bbdoc: Create a period as [begin, end).
  1860. about: If end is <= begin then the period will be defined as invalid.
  1861. End Rem
  1862. Method New(beginTime:TLocalDateTime, endTime:TLocalDateTime)
  1863. New(bmx_local_time_period_new(beginTime.localDateTimePtr, endTime.localDateTimePtr))
  1864. End Method
  1865. Rem
  1866. bbdoc: Create a period as [begin, begin + duration) where end would be begin + duration.
  1867. about: If duration is <= zero then the period will be defined as invalid.
  1868. End Rem
  1869. Method New(beginTime:TLocalDateTime, duration:TTimeDuration)
  1870. New(bmx_local_time_period_new_duration(beginTime.localDateTimePtr, duration.durationPtr))
  1871. End Method
  1872. Rem
  1873. bbdoc: Return first local date time of the period.
  1874. End Rem
  1875. Method begin:TLocalDateTime()
  1876. Return New TLocalDateTime(bmx_local_time_period_begin(localTimePeriodPtr))
  1877. End Method
  1878. Rem
  1879. bbdoc: Return last local date time in the period.
  1880. End Rem
  1881. Method last:TLocalDateTime()
  1882. Return New TLocalDateTime(bmx_local_time_period_last(localTimePeriodPtr))
  1883. End Method
  1884. Rem
  1885. bbdoc: Return one past the last in period.
  1886. End Rem
  1887. Method periodEnd:TLocalDateTime()
  1888. Return New TLocalDateTime(bmx_local_time_period_end(localTimePeriodPtr))
  1889. End Method
  1890. Rem
  1891. bbdoc: Return the length of the local time period.
  1892. End Rem
  1893. Method length:TTimeDuration()
  1894. Return New TTimeDuration(bmx_local_time_period_length(localTimePeriodPtr))
  1895. End Method
  1896. Rem
  1897. bbdoc: True if period is not well formed.
  1898. about: eg. end less than or equal to begin.
  1899. End Rem
  1900. Method isNull:Int()
  1901. Return bmx_local_time_period_is_null(localTimePeriodPtr)
  1902. End Method
  1903. Rem
  1904. bbdoc: True if @time is within the period.
  1905. about: Zero length periods cannot contain any points.
  1906. End Rem
  1907. Method containsTime:Int(time:TLocalDateTime)
  1908. Return bmx_local_time_period_contains_time(localTimePeriodPtr, time.localDateTimePtr)
  1909. End Method
  1910. Rem
  1911. bbdoc: True if @period is within the period.
  1912. End Rem
  1913. Method contains:Int(period:TLocalTimePeriod)
  1914. Return bmx_local_time_period_contains(localTimePeriodPtr, period.localTimePeriodPtr)
  1915. End Method
  1916. Rem
  1917. bbdoc: True if periods overlap.
  1918. End Rem
  1919. Method intersects:Int(period:TLocalTimePeriod)
  1920. Return bmx_local_time_period_intersects(localTimePeriodPtr, period.localTimePeriodPtr)
  1921. End Method
  1922. Rem
  1923. bbdoc: Calculate the intersection of 2 periods.
  1924. about: Null if no intersection.
  1925. End Rem
  1926. Method intersection:TLocalTimePeriod(period:TLocalTimePeriod)
  1927. Return New TLocalTimePeriod(bmx_local_time_period_intersection(localTimePeriodPtr, period.localTimePeriodPtr))
  1928. End Method
  1929. Rem
  1930. bbdoc: Returns union of two periods.
  1931. about: Null if no intersection.
  1932. End Rem
  1933. Method merge:TLocalTimePeriod(period:TLocalTimePeriod)
  1934. Return New TLocalTimePeriod(bmx_local_time_period_merge(localTimePeriodPtr, period.localTimePeriodPtr))
  1935. End Method
  1936. Rem
  1937. bbdoc: Combines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).
  1938. End Rem
  1939. Method span:TLocalTimePeriod(period:TLocalTimePeriod)
  1940. Return New TLocalTimePeriod(bmx_local_time_period_span(localTimePeriodPtr, period.localTimePeriodPtr))
  1941. End Method
  1942. Rem
  1943. bbdoc: Add duration to both begin and end.
  1944. End Rem
  1945. Method shift(duration:TTimeDuration)
  1946. bmx_local_time_period_shift(localTimePeriodPtr, duration.durationPtr)
  1947. End Method
  1948. Rem
  1949. bbdoc: True if this local time period is less than the parameter.
  1950. End Rem
  1951. Method isLess:Int(period:TLocalTimePeriod)
  1952. Return bmx_local_time_period_less(localTimePeriodPtr, period.localTimePeriodPtr)
  1953. End Method
  1954. Rem
  1955. bbdoc: True if this local time period is greater than the parameter.
  1956. End Rem
  1957. Method isGreater:Int(period:TLocalTimePeriod)
  1958. Return bmx_local_time_period_greater(localTimePeriodPtr, period.localTimePeriodPtr)
  1959. End Method
  1960. Rem
  1961. bbdoc: True if the two local time periods are equal.
  1962. about: Periods are equal if ltp1.begin = ltp2.begin and ltp1.last = ltp2.last
  1963. End Rem
  1964. Method isEqual:Int(period:TLocalTimePeriod)
  1965. Return bmx_local_time_period_equal(localTimePeriodPtr, period.localTimePeriodPtr)
  1966. End Method
  1967. ' for sorting !
  1968. Method compare:Int(obj:Object)
  1969. If TLocalTimePeriod(obj) Then
  1970. If isLess(TLocalTimePeriod(obj)) Then Return -1
  1971. If isEqual(TLocalTimePeriod(obj)) Then Return 0
  1972. Return 1
  1973. End If
  1974. Return Super.compare(obj)
  1975. End Method
  1976. Method Delete()
  1977. If localTimePeriodPtr Then
  1978. bmx_local_time_period_free(localTimePeriodPtr)
  1979. localTimePeriodPtr = Null
  1980. End If
  1981. End Method
  1982. End Type
  1983. Rem
  1984. bbdoc: A posix #TTimeZone is a set of data and rules that provide information about a time zone.
  1985. about: Information includes the offset from UTC, its name and abbreviation, as well as daylight
  1986. savings rules.
  1987. <p>A posix time zone is unique in that the object is created from a Posix time zone string
  1988. (IEEE Std 1003.1). A POSIX time zone string takes the form of:
  1989. </p>
  1990. <pre> "std offset dst [offset],start[/time],end[/time]" (with no spaces).</pre>
  1991. <p>'std' specifies the abbrev of the time zone. 'offset' is the offset from UTC. 'dst' specifies the
  1992. abbrev of the time zone during daylight savings time. The second offset is how many hours changed during
  1993. DST. 'start' and 'end' are the dates when DST goes into (and out of) effect. 'offset' takes the form of:
  1994. </p>
  1995. <pre> [+|-]hh[:mm[:ss]] {h=0-23, m/s=0-59}</pre>
  1996. <p>'time' and 'offset' take the same form. 'start' and 'end' can be one of three forms:
  1997. </p>
  1998. <pre>
  1999. Mm.w.d {month=1-12, week=1-5 (5 is always last), day=0-6}
  2000. Jn {n=1-365 Feb29 is never counted}
  2001. n {n=0-365 Feb29 is counted in leap years}
  2002. </pre>
  2003. <p>Exceptions will be thrown under the following conditions: </p>
  2004. <ul type="disc">
  2005. <li>An exception will be thrown for an invalid date spec (see
  2006. <a href="gregorian.html#date_time.gregorian.date_class" title="Date">date class</a>).</li>
  2007. <li>A boost::local_time::bad_offset exception will be thrown for:</li>
  2008. <li>A DST start or end offset that is negative or more than 24 hours.</li>
  2009. <li>A UTC zone that is greater than +12 or less than -12 hours.</li>
  2010. <li>A boost::local_time::bad_adjustment exception will be thrown for a DST adjustment that is 24 hours or
  2011. more (positive or negative)</li>
  2012. </ul>
  2013. <p>As stated above, the 'offset' and '/time' portions of the string are not required. If they are not
  2014. given they default to 01:00 for 'offset', and 02:00 for both occurrences of '/time'.
  2015. </p>
  2016. <p>
  2017. Some examples are:</p>
  2018. <pre>
  2019. "PST-8PDT01:00:00,M4.1.0/02:00:00,M10.1.0/02:00:00"
  2020. "PST-8PDT,M4.1.0,M10.1.0"
  2021. </pre>
  2022. <p>These two are actually the same specification (defaults were used in the second string).
  2023. This zone lies eight hours west of GMT and makes a one hour shift forward during daylight savings
  2024. time. Daylight savings for this zone starts on the first Sunday of April at 2am, and ends
  2025. on the first Sunday of October at 2am.
  2026. </p>
  2027. <pre> "MST-7"</pre>
  2028. <p>This zone is as simple as it gets. This zone lies seven hours west of GMT and has no daylight savings.
  2029. </p>
  2030. <pre> "EST10EDT,M10.5.0,M3.5.0/03"</pre>
  2031. <p>This string describes the time zone for Sydney Australia. It lies ten hours east of GMT and makes
  2032. a one hour shift forward during daylight savings. Being located in the southern hemisphere, daylight
  2033. savings begins on the last Sunday in October at 2am and ends on the last Sunday in March at 3am.
  2034. </p>
  2035. <pre>"FST+3FDT02:00,J60/00,J304/02"</pre>
  2036. <p>This specification describes a fictitious zone that lies three hours east of GMT. It makes a two hour
  2037. shift forward for daylight savings which begins on March 1st at midnight, and ends on October 31st at
  2038. 2am. The 'J' designation in the start/end specs signifies that counting starts at one and February
  2039. 29th is never counted.
  2040. </p>
  2041. <pre>"FST+3FDT,59,304"</pre>
  2042. <p>This specification is significant because of the '59'. The lack of 'J' for the start and end dates,
  2043. indicates that the Julian day-count begins at zero and ends at 365. If you do the math, you'll see
  2044. that allows for a total of 366 days. This is fine in leap years, but in non-leap years '59' (Feb-29)
  2045. does not exist. This will construct a valid posix_time_zone object but an exception will be thrown if
  2046. the date of '59' is accessed in a non-leap year. Ex:
  2047. </p>
  2048. <pre>posix_time_zone leap_day(std::string("FST+3FDT,59,304"));
  2049. leap_day.dst_local_start_time(2004); // ok
  2050. leap_day.dst_local_start_time(2003); // Exception thrown
  2051. </pre>
  2052. End Rem
  2053. Type TTimeZone
  2054. Field timeZonePtr:Byte Ptr
  2055. Private
  2056. Method New()
  2057. End Method
  2058. Method New(timeZonePtr:Byte Ptr)
  2059. Self.timeZonePtr = timeZonePtr
  2060. End Method
  2061. Public
  2062. Rem
  2063. bbdoc:
  2064. End Rem
  2065. Method New(description:String)
  2066. New(bmx_posix_time_zone(description))
  2067. End Method
  2068. Rem
  2069. bbdoc: Returns the daylight savings abbreviation for the represented time zone.
  2070. End Rem
  2071. Method DSTZoneAbbrev:String()
  2072. Return bmx_time_zone_dst_zone_abbrev(timeZonePtr)
  2073. End Method
  2074. Rem
  2075. bbdoc: Returns the standard abbreviation for the represented time zone.
  2076. End Rem
  2077. Method STDZoneAbbrev:String()
  2078. Return bmx_time_zone_std_zone_abbrev(timeZonePtr)
  2079. End Method
  2080. Rem
  2081. bbdoc: Returns the daylight savings name for the represented time zone.
  2082. End Rem
  2083. Method DSTZoneName:String()
  2084. Return bmx_time_zone_dst_zone_name(timeZonePtr)
  2085. End Method
  2086. Rem
  2087. bbdoc: Returns the standard name for the represented time zone.
  2088. End Rem
  2089. Method STDZoneName:String()
  2090. Return bmx_time_zone_std_zone_name(timeZonePtr)
  2091. End Method
  2092. Rem
  2093. bbdoc: Returns True if this time zone makes a daylight savings shift.
  2094. End Rem
  2095. Method hasDST:Int()
  2096. Return bmx_time_zone_has_dst(timeZonePtr)
  2097. End Method
  2098. Rem
  2099. bbdoc: The date and time daylight savings time begins in given year.
  2100. End Rem
  2101. Method DSTLocalStartTime:TTime(year:Int)
  2102. Return New TTime(bmx_time_zone_dst_local_start_time(timeZonePtr, year))
  2103. End Method
  2104. Rem
  2105. bbdoc: The date and time daylight savings time ends in given year.
  2106. End Rem
  2107. Method DSTLocalEndTime:TTime(year:Int)
  2108. Return New TTime(bmx_time_zone_dst_local_end_time(timeZonePtr, year))
  2109. End Method
  2110. Rem
  2111. bbdoc: The amount of time offset from UTC (typically in hours).
  2112. End Rem
  2113. Method baseUTCOffset:TTimeDuration()
  2114. Return New TTimeDuration(bmx_time_zone_base_utc_offset(timeZonePtr))
  2115. End Method
  2116. Rem
  2117. bbdoc: The amount of time shifted during daylight savings.
  2118. End Rem
  2119. Method DSTOffset:TTimeDuration()
  2120. Return New TTimeDuration(bmx_time_zone_dst_offset(timeZonePtr))
  2121. End Method
  2122. Rem
  2123. bbdoc: Returns a posix time zone string representation of this time zone object.
  2124. End Rem
  2125. Method toString:String()
  2126. Return bmx_time_zone_to_posix_string(timeZonePtr)
  2127. End Method
  2128. Method Delete()
  2129. If timeZonePtr Then
  2130. bmx_time_zone_free(timeZonePtr)
  2131. timeZonePtr = Null
  2132. End If
  2133. End Method
  2134. End Type
  2135. Rem
  2136. bbdoc: Date Generator base type for #TLastDayOfWeekInMonth, #TFirstDayOfWeekInMonth, #TNthDayOfWeekInMonth and #TPartialDate.
  2137. End Rem
  2138. Type TYearBasedGenerator Abstract
  2139. Field ybgPtr:Byte Ptr
  2140. Rem
  2141. bbdoc: Returns the date for the specified @year.
  2142. End Rem
  2143. Method getDate:TDate(year:Int) Abstract
  2144. End Type
  2145. Rem
  2146. bbdoc: Date Generator for a partial date.
  2147. End Rem
  2148. Type TPartialDate Extends TYearBasedGenerator
  2149. Private
  2150. Method New()
  2151. End Method
  2152. Public
  2153. Rem
  2154. bbdoc: Creates a new #TPartialDate for the given day and month.
  2155. End Rem
  2156. Method New(day:Int, _month:Int)
  2157. ybgPtr = bmx_partial_date_new(day, _month)
  2158. End Method
  2159. Method New(day:ENthDay, _month:Int)
  2160. ybgPtr = bmx_partial_date_new(Int(day), _month)
  2161. End Method
  2162. Method New(day:ENthDay, _month:EMonth)
  2163. ybgPtr = bmx_partial_date_new(Int(day), Int(_month))
  2164. End Method
  2165. Method New(day:Int, _month:EMonth)
  2166. ybgPtr = bmx_partial_date_new(day, Int(_month))
  2167. End Method
  2168. Method getDate:TDate(year:Int)
  2169. Return New TDate(bmx_partial_date_get_date(ybgPtr, year))
  2170. End Method
  2171. Method Delete()
  2172. If ybgPtr Then
  2173. bmx_partial_date_free(ybgPtr)
  2174. ybgPtr = Null
  2175. End If
  2176. End Method
  2177. End Type
  2178. Rem
  2179. bbdoc: Date Generator for last day of the week in month.
  2180. End Rem
  2181. Type TLastDayOfWeekInMonth Extends TYearBasedGenerator
  2182. Private
  2183. Method New()
  2184. End Method
  2185. Public
  2186. Rem
  2187. bbdoc: Creates a new #TLastDayOfWeekInMonth for the given weekday and month.
  2188. about: A weekday may be one of #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2189. #EWeekday.Friday or #EWeekday.Saturday.<br>
  2190. Month may be one of #EMonth.January, #EMonth.February, #EMonth.March, #EMonth.April, #EMonth.May, #EMonth.June, #EMonth.July,
  2191. #EMonth.August, #EMonth.September, #EMonth.October, #EMonth.November or #EMonth.December.
  2192. End Rem
  2193. Method New(_weekday:Int, _month:Int)
  2194. ybgPtr = bmx_last_day_of_week_in_month_new(_weekday, _month)
  2195. End Method
  2196. Method New(_weekday:EWeekday, _month:Int)
  2197. ybgPtr = bmx_last_day_of_week_in_month_new(Int(_weekday), _month)
  2198. End Method
  2199. Method New(_weekday:EWeekday, _month:EMonth)
  2200. ybgPtr = bmx_last_day_of_week_in_month_new(Int(_weekday), Int(_month))
  2201. End Method
  2202. Method New(_weekday:Int, _month:EMonth)
  2203. ybgPtr = bmx_last_day_of_week_in_month_new(_weekday, Int(_month))
  2204. End Method
  2205. Method getDate:TDate(year:Int)
  2206. Return New TDate(bmx_last_day_of_week_in_month_get_date(ybgPtr, year))
  2207. End Method
  2208. Method Delete()
  2209. If ybgPtr Then
  2210. bmx_last_day_of_week_in_month_free(ybgPtr)
  2211. ybgPtr = Null
  2212. End If
  2213. End Method
  2214. End Type
  2215. Rem
  2216. bbdoc: Date Generator for first day of the week in month.
  2217. End Rem
  2218. Type TFirstDayOfWeekInMonth Extends TYearBasedGenerator
  2219. Private
  2220. Method New()
  2221. End Method
  2222. Public
  2223. Rem
  2224. bbdoc: Creates a new #TFirstDayOfWeekInMonth for the given weekday and month.
  2225. about: A weekday may be one of #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2226. #EWeekday.Friday or #EWeekday.Saturday.<br>
  2227. Month may be one of #EMonth.January, #EMonth.February, #EMonth.March, #EMonth.April, #EMonth.May, #EMonth.June, #EMonth.July,
  2228. #EMonth.August, #EMonth.September, #EMonth.October, #EMonth.November or #EMonth.December.
  2229. End Rem
  2230. Method New(_weekday:Int, _month:Int)
  2231. ybgPtr = bmx_first_day_of_week_in_month_new(_weekday, _month)
  2232. End Method
  2233. Method New(_weekday:EWeekday, _month:Int)
  2234. ybgPtr = bmx_first_day_of_week_in_month_new(Int(_weekday), _month)
  2235. End Method
  2236. Method New(_weekday:EWeekday, _month:EMonth)
  2237. ybgPtr = bmx_first_day_of_week_in_month_new(Int(_weekday), Int(_month))
  2238. End Method
  2239. Method New(_weekday:Int, _month:EMonth)
  2240. ybgPtr = bmx_first_day_of_week_in_month_new(_weekday, Int(_month))
  2241. End Method
  2242. Method getDate:TDate(year:Int)
  2243. Return New TDate(bmx_first_day_of_week_in_month_get_date(ybgPtr, year))
  2244. End Method
  2245. Method Delete()
  2246. If ybgPtr Then
  2247. bmx_first_day_of_week_in_month_free(ybgPtr)
  2248. ybgPtr = Null
  2249. End If
  2250. End Method
  2251. End Type
  2252. Rem
  2253. bbdoc: Date Generator for nth day of the week in month.
  2254. about: Calculate something like first Monday of January, second Tuesday of March, Third Sunday
  2255. of December, etc.
  2256. End Rem
  2257. Type TNthDayOfWeekInMonth Extends TYearBasedGenerator
  2258. Private
  2259. Method New()
  2260. End Method
  2261. Public
  2262. Rem
  2263. bbdoc: Creates a new #TNthDayOfWeekInMonth for the given nth, weekday and month.
  2264. about: Nth may be one of #ENthDay.First, #ENthDay.Second, #ENthDay.Third, #ENthDay.Fourth, or #ENthDay.Fifth (1-5).
  2265. A weekday may be one of #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2266. #EWeekday.Friday or #EWeekday.Saturday (0-6).<br>
  2267. Month may be one of #EMonth.January, #EMonth.February, #EMonth.March, #EMonth.April, #EMonth.May, #EMonth.June, #EMonth.July,
  2268. #EMonth.August, #EMonth.September, #EMonth.October, #EMonth.November or #EMonth.December (1-12).
  2269. End Rem
  2270. Method New(nth:Int, _weekday:Int, _month:Int)
  2271. ybgPtr = bmx_nth_day_of_week_in_month_new(nth, _weekday, _month)
  2272. End Method
  2273. Method New(nth:ENthDay, _weekday:Int, _month:Int)
  2274. ybgPtr = bmx_nth_day_of_week_in_month_new(Int(nth), _weekday, _month)
  2275. End Method
  2276. Method New(nth:ENthDay, _weekday:EWeekday, _month:Int)
  2277. ybgPtr = bmx_nth_day_of_week_in_month_new(Int(nth), Int(_weekday), _month)
  2278. End Method
  2279. Method New(nth:ENthDay, _weekday:EWeekday, _month:EMonth)
  2280. ybgPtr = bmx_nth_day_of_week_in_month_new(Int(nth), Int(_weekday), Int(_month))
  2281. End Method
  2282. Method New(nth:Int, _weekday:EWeekday, _month:EMonth)
  2283. ybgPtr = bmx_nth_day_of_week_in_month_new(nth, Int(_weekday), Int(_month))
  2284. End Method
  2285. Method New(nth:Int, _weekday:Int, _month:EMonth)
  2286. ybgPtr = bmx_nth_day_of_week_in_month_new(nth, _weekday, Int(_month))
  2287. End Method
  2288. Method New(nth:Int, _weekday:EWeekday, _month:Int)
  2289. ybgPtr = bmx_nth_day_of_week_in_month_new(nth, Int(_weekday), _month)
  2290. End Method
  2291. Method getDate:TDate(year:Int)
  2292. Return New TDate(bmx_nth_day_of_week_in_month_get_date(ybgPtr, year))
  2293. End Method
  2294. Method Delete()
  2295. If ybgPtr Then
  2296. bmx_nth_day_of_week_in_month_free(ybgPtr)
  2297. ybgPtr = Null
  2298. End If
  2299. End Method
  2300. End Type
  2301. Rem
  2302. bbdoc: Date Generator for first day of the week after a date.
  2303. about: Calculate something like First Sunday after Jan 1,2002.
  2304. End Rem
  2305. Type TFirstDayOfWeekAfter
  2306. Private
  2307. Method New()
  2308. End Method
  2309. Public
  2310. Field ybgPtr:Byte Ptr
  2311. Rem
  2312. bbdoc: Creates a new #TFirstDayOfWeekAfter for the given weekday.
  2313. about: A weekday may be one of #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2314. #EWeekday.Friday or #EWeekday.Saturday (0-6).
  2315. End Rem
  2316. Method New(_weekday:Int)
  2317. ybgPtr = bmx_first_day_of_week_after_new(_weekday)
  2318. End Method
  2319. Method New(_weekday:EWeekday)
  2320. ybgPtr = bmx_first_day_of_week_after_new(Int(_weekday))
  2321. End Method
  2322. Rem
  2323. bbdoc: Returns the date for the first day after the specified @date.
  2324. End Rem
  2325. Method getDate:TDate(date:TDate)
  2326. Return New TDate(bmx_first_day_of_week_after_get_date(ybgPtr, date.datePtr))
  2327. End Method
  2328. Method Delete()
  2329. If ybgPtr Then
  2330. bmx_first_day_of_week_after_free(ybgPtr)
  2331. ybgPtr = Null
  2332. End If
  2333. End Method
  2334. End Type
  2335. Rem
  2336. bbdoc: Date Generator for first day of the week before a date.
  2337. about: Calculate something like First Monday before Feb 1,2002
  2338. End Rem
  2339. Type TFirstDayOfWeekBefore
  2340. Private
  2341. Method New()
  2342. End Method
  2343. Public
  2344. Field ybgPtr:Byte Ptr
  2345. Rem
  2346. bbdoc: Creates a new #TFirstDayOfWeekBefore for the given weekday.
  2347. about: A weekday may be one of #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2348. #EWeekday.Friday or #EWeekday.Saturday (0-6).
  2349. End Rem
  2350. Method New(_weekday:Int)
  2351. ybgPtr = bmx_first_day_of_week_before_new(_weekday)
  2352. End Method
  2353. Method New(_weekday:EWeekday)
  2354. ybgPtr = bmx_first_day_of_week_before_new(Int(_weekday))
  2355. End Method
  2356. Rem
  2357. bbdoc: Returns the date for the first day before the specified @date.
  2358. End Rem
  2359. Method getDate:TDate(date:TDate)
  2360. Return New TDate(bmx_first_day_of_week_before_get_date(ybgPtr, date.datePtr))
  2361. End Method
  2362. Method Delete()
  2363. If ybgPtr Then
  2364. bmx_first_day_of_week_before_free(ybgPtr)
  2365. ybgPtr = Null
  2366. End If
  2367. End Method
  2368. End Type
  2369. Rem
  2370. bbdoc: The default date facet
  2371. End Rem
  2372. Global defaultDateFacet:TDateFacet = New TDateFacet()
  2373. Rem
  2374. bbdoc: The current date facet (for use with toString() type formatting)
  2375. End Rem
  2376. Global currentDateFacet:TDateFacet = defaultDateFacet
  2377. Rem
  2378. bbdoc: The default time facet
  2379. End Rem
  2380. Global defaultTimeFacet:TTimeFacet = New TTimeFacet()
  2381. Rem
  2382. bbdoc: The current time facet (for use with toString() type formatting)
  2383. End Rem
  2384. Global currentTimeFacet:TTimeFacet = defaultTimeFacet
  2385. 'SetCurrentDateFacet(defaultDateFacet)
  2386. 'SetCurrentTimeFacet(defaultTimeFacet)
  2387. Type TLocaleFacet
  2388. ?linux
  2389. Global defaultLocale:String = "en_US"
  2390. ?win32
  2391. Global defaultLocale:String = "English United States"
  2392. ?macos
  2393. Global defaultLocale:String = "en_US"
  2394. ?
  2395. Field localePtr:Byte Ptr
  2396. Field facetPtr:Byte Ptr
  2397. Field locale:String
  2398. Global generator:TBLGenerator
  2399. Method New()
  2400. If Not generator Then
  2401. generator = New TBLGenerator()
  2402. End If
  2403. End Method
  2404. End Type
  2405. Rem
  2406. bbdoc: The #TDateFacet enables users to have significant control over the output of dates (and other gregorian objects).
  2407. End Rem
  2408. Type TDateFacet Extends TLocaleFacet
  2409. Method New()
  2410. New(TLocaleFacet.defaultLocale)
  2411. End Method
  2412. Method New(locale:String)
  2413. Self.facetPtr = bmx_datefacet_new()
  2414. Self.localePtr = bmx_locale_new(facetPtr, generator.genPtr, locale)
  2415. Self.locale = locale
  2416. End Method
  2417. Rem
  2418. bbdoc: Set the format for dates.
  2419. End Rem
  2420. Method format(fmt:String)
  2421. bmx_date_facet_format(facetPtr, fmt)
  2422. End Method
  2423. Rem
  2424. bbdoc: Sets the date format to ISO.
  2425. End Rem
  2426. Method setISOFormat()
  2427. bmx_date_facet_set_iso_format(facetPtr)
  2428. End Method
  2429. Rem
  2430. bbdoc: Sets the date format to ISO Extended.
  2431. End Rem
  2432. Method setISOExtendedFormat()
  2433. bmx_date_facet_set_iso_extended_format(facetPtr)
  2434. End Method
  2435. Rem
  2436. bbdoc: Set the format for months when they are output individually.
  2437. End Rem
  2438. Method monthFormat(fmt:String)
  2439. bmx_date_facet_month_format(facetPtr, fmt)
  2440. End Method
  2441. Rem
  2442. bbdoc: Set the format for weekdays when they are output individually.
  2443. End Rem
  2444. Method weekdayFormat(fmt:String)
  2445. bmx_date_facet_weekday_format(facetPtr, fmt)
  2446. End Method
  2447. Rem
  2448. bbdoc: Replace strings used when outputting short months.
  2449. End Rem
  2450. Method setShortMonthNames(names:String[])
  2451. Assert names, "short names array cannot be null"
  2452. Assert names.length = 12, "short names array requires 12 entries"
  2453. bmx_date_facet_short_month_names(facetPtr, names)
  2454. End Method
  2455. Rem
  2456. bbdoc: Replace strings used when outputting long months.
  2457. End Rem
  2458. Method setLongMonthNames(names:String[])
  2459. Assert names, "names array cannot be null"
  2460. Assert names.length = 12, "names array requires 12 entries"
  2461. bmx_date_facet_long_month_names(facetPtr, names)
  2462. End Method
  2463. Rem
  2464. bbdoc: Replace strings used when outputting short weekdays.
  2465. End Rem
  2466. Method setShortWeekdayNames(names:String[])
  2467. Assert names, "short weekday names array cannot be null"
  2468. Assert names.length = 7, "short weekday names array requires 12 entries"
  2469. bmx_date_facet_short_weekday_names(facetPtr, names)
  2470. End Method
  2471. Rem
  2472. bbdoc: Replace strings used when outputting long weekdays.
  2473. End Rem
  2474. Method setLongWeekdayNames(names:String[])
  2475. Assert names, "weekday names array cannot be null"
  2476. Assert names.length = 7, "weekday names array requires 7 entries"
  2477. bmx_date_facet_long_weekday_names(facetPtr, names)
  2478. End Method
  2479. End Type
  2480. Type TTimeFacet Extends TDateFacet
  2481. Method New()
  2482. New(defaultLocale)
  2483. End Method
  2484. Method New(locale:String)
  2485. Self.facetPtr = bmx_timefacet_new()
  2486. Self.localePtr = bmx_locale_new(facetPtr, generator.genPtr, locale)
  2487. Self.locale = locale
  2488. End Method
  2489. Rem
  2490. bbdoc: Set the format for dates.
  2491. End Rem
  2492. Method format(fmt:String)
  2493. bmx_time_facet_format(facetPtr, fmt)
  2494. End Method
  2495. Rem
  2496. bbdoc: Sets the date format to ISO.
  2497. End Rem
  2498. Method setISOFormat()
  2499. bmx_time_facet_set_iso_format(facetPtr)
  2500. End Method
  2501. Rem
  2502. bbdoc: Sets the date format to ISO Extended.
  2503. End Rem
  2504. Method setISOExtendedFormat()
  2505. bmx_time_facet_set_iso_extended_format(facetPtr)
  2506. End Method
  2507. Rem
  2508. bbdoc: Set the format for months when they are output individually.
  2509. End Rem
  2510. Method monthFormat(fmt:String)
  2511. bmx_time_facet_month_format(facetPtr, fmt)
  2512. End Method
  2513. Rem
  2514. bbdoc: Set the format for weekdays when they are output individually.
  2515. End Rem
  2516. Method weekdayFormat(fmt:String)
  2517. bmx_time_facet_weekday_format(facetPtr, fmt)
  2518. End Method
  2519. Rem
  2520. bbdoc: Sets the time_duration format.
  2521. about: The time duration format has the ability to display the sign of the duration.
  2522. The '%+' flag will always display the sign. The '%-' will only display if the sign is negative. Currently the '-' and '+' characters are used to denote the sign.
  2523. End Rem
  2524. Method timeDurationFormat(fmt:String)
  2525. bmx_time_facet_time_duration_format(facetPtr, fmt)
  2526. End Method
  2527. End Type
  2528. Rem
  2529. bbdoc: Convenience function for TTimeDuration.Hour().
  2530. End Rem
  2531. Function TDHours:TTimeDuration(amount:Int)
  2532. Return TTimeDuration.Hour(amount)
  2533. End Function
  2534. Rem
  2535. bbdoc: Convenience function for TTimeDuration.Minute().
  2536. End Rem
  2537. Function TDMinutes:TTimeDuration(amount:Int)
  2538. Return TTimeDuration.Minute(amount)
  2539. End Function
  2540. Rem
  2541. bbdoc: Convenience function for TTimeDuration.Second().
  2542. End Rem
  2543. Function TDSeconds:TTimeDuration(amount:Int)
  2544. Return TTimeDuration.Second(amount)
  2545. End Function
  2546. Rem
  2547. bbdoc: Sets the current date facet.
  2548. about: This controls the appearance of date information.
  2549. End Rem
  2550. Function SetCurrentDateFacet(facet:TDateFacet)
  2551. currentDateFacet = facet
  2552. End Function
  2553. Rem
  2554. bbdoc: Sets the current time facet.
  2555. about: This controls the appearance of time and time duration information.
  2556. End Rem
  2557. Function SetCurrentTimeFacet(facet:TTimeFacet)
  2558. currentTimeFacet = facet
  2559. End Function
  2560. Rem
  2561. bbdoc: Return the number of ticks in a second.
  2562. about: For example, if the duration supports nanoseconds then the returned result will be 1,000,000,000 (1e+9).
  2563. End Rem
  2564. Function TicksPerSecond:Int()
  2565. Return bmx_time_ticks_per_second()
  2566. End Function
  2567. Rem
  2568. bbdoc: Returns the number of fractional digits the time resolution has.
  2569. about: 9 for nano, 6 for micro, etc.
  2570. End Rem
  2571. Function NumFractionalDigits:Int()
  2572. Return bmx_time_num_fractional_digits()
  2573. End Function
  2574. Rem
  2575. bbdoc: Get the weekday text for the specified @weekday (0 - 6).
  2576. about: This is based on the current weekday format as specified by #TDateFacet.<br>
  2577. Valid weekdays include #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2578. #EWeekday.Friday, #EWeekday.Saturday (0-6).
  2579. End Rem
  2580. Function WeekDay:String(_weekday:Int)
  2581. Return bmx_weekday_to_string(_weekday)
  2582. End Function
  2583. Function WeekDay:String(_weekday:EWeekday)
  2584. Return bmx_weekday_to_string(Int(_weekday))
  2585. EndFunction
  2586. Rem
  2587. bbdoc: Get the month text for the specified @month (1 - 12).
  2588. about: This is based on the current month format as specified by #TDateFacet.
  2589. End Rem
  2590. Function Month:String(_month:Int)
  2591. Return bmx_month_to_string(_month)
  2592. End Function
  2593. Function Month:String(_month:EMonth)
  2594. Return bmx_month_to_string(Int(_month))
  2595. End Function
  2596. Rem
  2597. bbdoc: Calculates the number of days from given date until given @weekday.
  2598. about: Valid weekdays include #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2599. #EWeekday.Friday, #EWeekday.Saturday (0-6).
  2600. End Rem
  2601. Function DaysUntilWeekday:Int(date:TDate, _weekday:Int)
  2602. Return bmx_days_until_weekday(date.datePtr, _weekday)
  2603. End Function
  2604. Function DaysUntilWeekday:Int(date:TDate, _weekday:EWeekday)
  2605. Return bmx_days_until_weekday(date.datePtr, Int(_weekday))
  2606. End Function
  2607. Rem
  2608. bbdoc: Calculates the number of day from given date to previous given @weekday.
  2609. about: Valid weekdays include #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2610. #EWeekday.Friday, #EWeekday.Saturday (0-6).
  2611. End Rem
  2612. Function DaysBeforeWeekday:Int(date:TDate, _weekday:Int)
  2613. Return bmx_days_before_weekday(date.datePtr, _weekday)
  2614. End Function
  2615. Function DaysBeforeWeekday:Int(date:TDate, _weekday:EWeekday)
  2616. Return bmx_days_before_weekday(date.datePtr, Int(_weekday))
  2617. End Function
  2618. Rem
  2619. bbdoc: Generates a #TDate object representing the date of the following @weekday from the given @date.
  2620. about: Valid weekdays include #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2621. #EWeekday.Friday, #EWeekday.Saturday (0-6).
  2622. End Rem
  2623. Function NextWeekday:TDate(date:TDate, _weekday:Int)
  2624. Return New TDate(bmx_next_weekday(date.datePtr, _weekday))
  2625. End Function
  2626. Function NextWeekday:TDate(date:TDate, _weekday:EWeekday)
  2627. Return New TDate(bmx_next_weekday(date.datePtr, Int(_weekday)))
  2628. End Function
  2629. Rem
  2630. bbdoc: Generates a #TDate object representing the date of the previous @weekday from the given @date.
  2631. about: Valid weekdays include #EWeekday.Sunday, #EWeekday.Monday, #EWeekday.Tuesday, #EWeekday.Wednesday, #EWeekday.Thursday,
  2632. #EWeekday.Friday, #EWeekday.Saturday (0-6).
  2633. End Rem
  2634. Function PreviousWeekday:TDate(date:TDate, _weekday:Int)
  2635. Return New TDate(bmx_previous_weekday(date.datePtr, _weekday))
  2636. End Function
  2637. Function PreviousWeekday:TDate(date:TDate, _weekday:EWeekday)
  2638. Return New TDate(bmx_previous_weekday(date.datePtr, Int(_weekday)))
  2639. End Function
  2640. Rem
  2641. bbdoc:
  2642. End Rem
  2643. Function EndOfMonthDay:Int(year:Int, _month:Int)
  2644. Return bmx_end_of_month_day(year, _month)
  2645. End Function
  2646. Function EndOfMonthDay:Int(year:Int, _month:EMonth)
  2647. Return bmx_end_of_month_day(year, Int(_month))
  2648. End Function
  2649. Rem
  2650. bbdoc: Weekday
  2651. EndRem
  2652. Enum EWeekday:Int
  2653. Sunday
  2654. Monday
  2655. Tuesday
  2656. Wednesday
  2657. Thursday
  2658. Friday
  2659. Saturday
  2660. EndEnum
  2661. Rem
  2662. bbdoc: Month
  2663. EndRem
  2664. Enum EMonth:Int
  2665. January = 1
  2666. February
  2667. March
  2668. April
  2669. May
  2670. June
  2671. July
  2672. August
  2673. September
  2674. October
  2675. November
  2676. December
  2677. EndEnum
  2678. Rem
  2679. bbdoc: Nth Day
  2680. EndRem
  2681. Enum ENthDay:Int
  2682. First = 1
  2683. Second
  2684. Third
  2685. Fourth
  2686. Fifth
  2687. EndEnum