123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?xml version="1.0" encoding="utf-8"?>
- <!--
-
- h t t :: / / t /
- h t t :: // // t //
- h ttttt ttttt ppppp sssss // // y y sssss ttttt //
- hhhh t t p p s // // y y s t //
- h hh t t ppppp sssss // // yyyyy sssss t //
- h h t t p s :: / / y .. s t .. /
- h h t t p sssss :: / / yyyyy .. sssss t .. /
-
- <https://y.st./>
- Copyright © 2016 Alex Yst <mailto:copyright@y.st>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org./licenses/>.
- -->
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <base href="https://y.st./en/weblog/2016/02-February/10.xhtml" />
- <title>The \DatePeriod class <https://y.st./en/weblog/2016/02-February/10.xhtml></title>
- <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
- <link rel="stylesheet" type="text/css" href="/link/basic.css" />
- <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
- <script type="text/javascript" src="/script/javascript.js" />
- <meta name="viewport" content="width=device-width" />
- </head>
- <body>
- <nav>
- <p>
- <a href="/en/">Home</a> |
- <a href="/en/a/about.xhtml">About</a> |
- <a href="/en/a/contact.xhtml">Contact</a> |
- <a href="/a/canary.txt">Canary</a> |
- <a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
- <a href="/en/opinion/">Opinions</a> |
- <a href="/en/coursework/">Coursework</a> |
- <a href="/en/law/">Law</a> |
- <a href="/en/a/links.xhtml">Links</a> |
- <a href="/en/weblog/2016/02-February/10.xhtml.asc">{this page}.asc</a>
- </p>
- <hr/>
- <p>
- Weblog index:
- <a href="/en/weblog/"><abbr title="American Standard Code for Information Interchange">ASCII</abbr> calendars</a> |
- <a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
- <a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
- </p>
- <hr/>
- <p>
- Jump to entry:
- <a href="/en/weblog/2015/03-March/07.xhtml"><<First</a>
- <a rel="prev" href="/en/weblog/2016/02-February/09.xhtml"><Previous</a>
- <a rel="next" href="/en/weblog/2016/02-February/11.xhtml">Next></a>
- <a href="/en/weblog/latest.xhtml">Latest>></a>
- </p>
- <hr/>
- </nav>
- <header>
- <h1>The \DatePeriod class</h1>
- <p>Day 00340: Wednesday, 2016 February 10</p>
- </header>
- <p>
- 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.
- 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.
- Because several date formats are accepted, dates that are outside the expected range are not handled correctly.
- 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.
- I imagine that these corner cases are not the only issue.
- 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.
- 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.
- 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.
- Now, everything just fell into place.
- Next, I worked on fixing my calendar function.
- It has now been upgraded to being a class and also extends my datetime class.
- While setting this class up, I found the <a href="https://secure.php.net/manual/en/class.dateperiod.php"><code>\DatePeriod</code> class</a>.
- As a function, <code>calendar()</code> returned a two-dimensional array to be iterated over by a pair of nested <code>foreach()</code> statements.
- 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.
- 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.
- Finally, I set to work on fixing up my <code>date_nav()</code> function.
- After staring at the code a while, I decided to scrap the function altogether.
- Its main advantage was that it did the leg work of timestamp manipulation for my navigation links.
- 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.
- 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.
- </p>
- <p>
- 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.
- 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.
- 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.
- </p>
- <p>
- I walked over to the local community college today for my appointment with a counselor about the credits that I transfered in.
- It seems that there was bad news.
- I had only one course left to complete to get my associate degree at my last school, but I have about a year'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.
- 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.
- I do not expect to be in the area beyond the end of next term, so I asked about the school's online options.
- That lead to even more grim news.
- Offline, I could earn a degree in a tech field, but online, the only options are general education degrees.
- I will speak with my mother after I return from Springfield.
- 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.
- My hair is still too long, so I would rather avoid getting photo <abbr title="identification">ID</abbr> right now.
- 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.
- I only just got the information on what courses I even need today.
- </p>
- <p>
- Tomorrow, I will be headed to Springfield to work on cleaning up and sorting things at our former residence.
- I think that I will be returning on Saturday.
- </p>
- <hr/>
- <p>
- Copyright © 2016 Alex Yst;
- 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's Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
- If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
- My address is in the source comments near the top of this document.
- This license also applies to embedded content such as images.
- For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
- </p>
- <p>
- <abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
- 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.
- </p>
- </body>
- </html>
|