datetime.bmx 88 KB

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