10.xhtml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. h t t :: / / t /
  4. h t t :: // // t //
  5. h ttttt ttttt ppppp sssss // // y y sssss ttttt //
  6. hhhh t t p p s // // y y s t //
  7. h hh t t ppppp sssss // // yyyyy sssss t //
  8. h h t t p s :: / / y .. s t .. /
  9. h h t t p sssss :: / / yyyyy .. sssss t .. /
  10. <https://y.st./>
  11. Copyright © 2016 Alex Yst <mailto:copyright@y.st>
  12. This program is free software: you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation, either version 3 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program. If not, see <https://www.gnu.org./licenses/>.
  22. -->
  23. <!DOCTYPE html>
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <base href="https://y.st./en/weblog/2016/02-February/10.xhtml" />
  27. <title>The \DatePeriod class &lt;https://y.st./en/weblog/2016/02-February/10.xhtml&gt;</title>
  28. <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
  29. <link rel="stylesheet" type="text/css" href="/link/basic.css" />
  30. <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
  31. <script type="text/javascript" src="/script/javascript.js" />
  32. <meta name="viewport" content="width=device-width" />
  33. </head>
  34. <body>
  35. <nav>
  36. <p>
  37. <a href="/en/">Home</a> |
  38. <a href="/en/a/about.xhtml">About</a> |
  39. <a href="/en/a/contact.xhtml">Contact</a> |
  40. <a href="/a/canary.txt">Canary</a> |
  41. <a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
  42. <a href="/en/opinion/">Opinions</a> |
  43. <a href="/en/coursework/">Coursework</a> |
  44. <a href="/en/law/">Law</a> |
  45. <a href="/en/a/links.xhtml">Links</a> |
  46. <a href="/en/weblog/2016/02-February/10.xhtml.asc">{this page}.asc</a>
  47. </p>
  48. <hr/>
  49. <p>
  50. Weblog index:
  51. <a href="/en/weblog/"><abbr title="American Standard Code for Information Interchange">ASCII</abbr> calendars</a> |
  52. <a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
  53. <a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
  54. </p>
  55. <hr/>
  56. <p>
  57. Jump to entry:
  58. <a href="/en/weblog/2015/03-March/07.xhtml">&lt;&lt;First</a>
  59. <a rel="prev" href="/en/weblog/2016/02-February/09.xhtml">&lt;Previous</a>
  60. <a rel="next" href="/en/weblog/2016/02-February/11.xhtml">Next&gt;</a>
  61. <a href="/en/weblog/latest.xhtml">Latest&gt;&gt;</a>
  62. </p>
  63. <hr/>
  64. </nav>
  65. <header>
  66. <h1>The \DatePeriod class</h1>
  67. <p>Day 00340: Wednesday, 2016 February 10</p>
  68. </header>
  69. <p>
  70. My project for today was to update my code to use the <a href="https://secure.php.net/manual/en/class.datetime.php"><code>\DateTime</code> class</a> instead of integer timestamps.
  71. While fixing up my day_number class, I quickly found the main problem with using the <code>\DateTime</code> class: it requires instantiation via a date in the form of a string.
  72. Because several date formats are accepted, dates that are outside the expected range are not handled correctly.
  73. For example, the year 7 is interpreted as being an alias of the year 2007, though this can be overcome by specifying the year as 0007; the year 10000 causes an error with no workaround.
  74. I imagine that these corner cases are not the only issue.
  75. Once a <code>\DateTime</code> object has been instantiated, the date can be modified using integers, so I extended the class and used this functionality to fix up the constructor method.
  76. Once I had a functional base class, I hound that my day_number class, which now extends my fixed datetime class, came together much more smoothly than when it was using timestamps.
  77. Due to the fact that telling the timestamp functions to ignore daylight savings time raises an error, I had been having to rely on hacky workarounds instead.
  78. Now, everything just fell into place.
  79. Next, I worked on fixing my calendar function.
  80. It has now been upgraded to being a class and also extends my datetime class.
  81. While setting this class up, I found the <a href="https://secure.php.net/manual/en/class.dateperiod.php"><code>\DatePeriod</code> class</a>.
  82. As a function, <code>calendar()</code> returned a two-dimensional array to be iterated over by a pair of nested <code>foreach()</code> statements.
  83. However, the <code>\DatePeriod</code> class, with zero modifications, took all the effort out of building the second dimension, allowing me to remove some somewhat kludgey code.
  84. Having the calendar class itself implement the <a href="https://secure.php.net/manual/en/class.iterator.php"><code>\Iterator</code> interface</a> made the outer iteratable code a bit less concise, but easer to read and understand.
  85. Finally, I set to work on fixing up my <code>date_nav()</code> function.
  86. After staring at the code a while, I decided to scrap the function altogether.
  87. Its main advantage was that it did the leg work of timestamp manipulation for my navigation links.
  88. However, making use of the <a href="https://secure.php.net/manual/en/class.datetimeimmutable.php"><code>\DateTimeImmutable</code> class</a> and the <a href="https://secure.php.net/manual/en/class.dateinterval.php"><code>\DateInterval</code> class</a>, this was a lot less necessary.
  89. Implementing this code as a function that made use of the date/time classes would have been messier than just using the date/time classes directly and implementing this code as a class would have been messier still.
  90. </p>
  91. <p>
  92. I was going to implement a similar feature for a descendant of the <code>\DateTimeImmutable</code> class as I did for a decedent of the <code>\DateTime</code> class, but I decided that it would be too kludgey for now.
  93. Due to these objects being immutable, at least in regards to their date and time, I could not use the same simple trick as I had used with the <code>\DateTime</code> class.
  94. It could be accomplished using either a non-class function or a static method, but until this functionality is required, I do not want to write such messy code.
  95. </p>
  96. <p>
  97. I walked over to the local community college today for my appointment with a counselor about the credits that I transfered in.
  98. It seems that there was bad news.
  99. I had only one course left to complete to get my associate degree at my last school, but I have about a year&apos;s worth of courses left to take at this school because so many of the credits did not transfer over like I was told that they would.
  100. Even most of the ones that did transfer over did not meet many of the specific requirements and are just being used to fill all of the elective requirements.
  101. I do not expect to be in the area beyond the end of next term, so I asked about the school&apos;s online options.
  102. That lead to even more grim news.
  103. Offline, I could earn a degree in a tech field, but online, the only options are general education degrees.
  104. I will speak with my mother after I return from Springfield.
  105. On the way out, I was offered a chance to get a school <abbr title="identification">ID</abbr> card, but I was not told that it required a photograph.
  106. My hair is still too long, so I would rather avoid getting photo <abbr title="identification">ID</abbr> right now.
  107. Luckily, there were technical difficulties, but even if there were not, it seems that the had left out another important piece of information: students cannot get their student <abbr title="identification">ID</abbr> cards until <strong>*after*</strong> enrolling for courses, and I have not done that yet.
  108. I only just got the information on what courses I even need today.
  109. </p>
  110. <p>
  111. Tomorrow, I will be headed to Springfield to work on cleaning up and sorting things at our former residence.
  112. I think that I will be returning on Saturday.
  113. </p>
  114. <hr/>
  115. <p>
  116. Copyright © 2016 Alex Yst;
  117. You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU&apos;s Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
  118. If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
  119. My address is in the source comments near the top of this document.
  120. This license also applies to embedded content such as images.
  121. For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
  122. </p>
  123. <p>
  124. <abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
  125. This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2016%2F02-February%2F10.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.1</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2016%2F02-February%2F10.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
  126. </p>
  127. </body>
  128. </html>