bernhard Posted February 23, 2020 Author Share Posted February 23, 2020 How crazy is that piece of software called ProcessWire?? Exact matches are now possible using the string notation of date ranges. Writing this down and looking at the screenshot I realize that it would make a lot of sense to be consistant in the format when transforming a RockDaterange object into a string and vice versa. Amount of code necessary to support this? 10 Lines ? 2 Link to comment Share on other sites More sharing options...
bernhard Posted February 28, 2020 Author Share Posted February 28, 2020 On 2/23/2020 at 5:02 PM, bernhard said: Writing this down and looking at the screenshot I realize that it would make a lot of sense to be consistant in the format when transforming a RockDaterange object into a string and vice versa. I've put huge amounts of work into that module in the last few days. I had to take two steps back to take the next step forward: It turned out, that I needed a more robust and flexible setup when dealing with date ranges. And what I did is - thinking about it now - quite obvious: A RockDaterange now consists of two RockDatetimes. I've put a lot of effort into developing the RockDatetime module. It is already available on Github and has lots of examples and docs in the readme: https://github.com/BernhardBaumrock/RockDatetime Highlights: // calculating FROM/TO for RockDaterange case 'hour': $from = new RockDatetime("{$obj->date} {$obj->time}:00:00"); if($isTo) $to = $from; else $to = $from->copy()->move("+1 hour"); break; // check if FROM starts at 00:00 on that day if($this->from->equals($this->from->firstOfDay()) ... // formatting $d = new RockDatetime("25.02.2020 14:00"); echo $d->format(); // 25.02.2020 14:00 echo $d->format("%A, %d.%m.%y (%H:%M Uhr)"); // Dienstag, 25.02.20 (14:00 Uhr) echo $d->format(['time' => "%H|%M|%S"]); // 25.02.2020 14|30|00 I've also totally rebuilt the date parsing engine! Finding pages using the API $tpl = "template=event"; $pages->find("$tpl,range=2020"); // find all events in 2020 $pages->find("$tpl,range=2020-02"); // find all events in Feb 2020 $pages->find("$tpl,range=2020-02-26"); // find all events on 26. Feb 2020 // other possible selectors $pages->find("$tpl,range=2020-02-10 - 2020-02-20"); $pages->find("$tpl,range=2020-02-10 7:30 - 17:30"); $pages->find("$tpl,range=2020-02-10 7 - 9"); $pages->find("$tpl,range=2020-02-10 12:00 - 2020-02-20 18:00"); // find events in Feb 2020 sorted by range duration $pages->find("$tpl,range=2020-02, sort=-range.duration"); Creating pages using the API $p = new Page(); $p->setAndSave("range", "2020"); // from = 2020-01-01 00:00:00 // _to = 2020-12-31 23:59:59 // to = 2021-01-01 00:00:00 $p->setAndSave("range", "2020-12-24 16:00 - 18:00"); // from = 2020-12-24 16:00:00 // _to = 2020-12-24 17:59:59 // to = 2020-12-24 18:00:00 Formatting in action: // left column echo $range->format(['date' => "%A, %d.%m.%Y", 'time' => '']); // right column echo $range->format(['date' => "%a, %d.%m.%Y"]); Note that the last date does NOT show "07.03.2020 09:00 - 07.03.2020 12:00" - since the event ends on the same day as it starts we don't show that date again. RockDaterange will take care of all those tedious details! 4 2 Link to comment Share on other sites More sharing options...
gebeer Posted February 28, 2020 Share Posted February 28, 2020 1 hour ago, bernhard said: I've put a lot of effort into developing the RockDatetime module. It is already available on Github and has lots of examples and docs in the readme: https://github.com/BernhardBaumrock/RockDatetime Thank you so much for all your efforts in putting this together! I'll be using this soon to replace date range logic in 2 live projects that deal with events. 1 Link to comment Share on other sites More sharing options...
bernhard Posted February 28, 2020 Author Share Posted February 28, 2020 It would be very easy to create a RockDatetime field based on the core Datetime field but waking up having a RockDatetime object instead of a timestamp. Maybe you want to experiment with that and create a PR? Link to comment Share on other sites More sharing options...
gebeer Posted February 28, 2020 Share Posted February 28, 2020 54 minutes ago, bernhard said: t would be very easy to create a RockDatetime field based on the core Datetime field but waking up having a RockDatetime object instead of a timestamp. Maybe you want to experiment with that and create a PR? I thought I'd just use your new inputfield type ? Won't have time for implementing this before April. If I see room for improvement on your module, I am happy to make a PR. Thanks again! Link to comment Share on other sites More sharing options...
bernhard Posted February 28, 2020 Author Share Posted February 28, 2020 RockDatetime is not an Inputfield. It is just a PW module that returns a RockDatetime object you can use for whatever you want. You could use the core InputfieldDatetime though and turn it into a RockDatetime like this: $d = new RockDatetime($page->getUnformatted('datefield')); echo $d->format(); Range input/output is not part of RockDatetime! Link to comment Share on other sites More sharing options...
bernhard Posted March 1, 2020 Author Share Posted March 1, 2020 @d'Hinnisdaël mentioned in the recent new post that there's a library called "carbon" for managing date/times. I've put together a module to include that library into PW for quick testing if anybody is interested: https://github.com/BernhardBaumrock/RockCarbon Using this library handling timezones should be quite straightforward. Dates in the DB could be stored in UTC format and displayed based on the users/systems timezone: 1 Link to comment Share on other sites More sharing options...
DavidBerlin Posted March 14, 2020 Share Posted March 14, 2020 @bernhard I was playing around with your RockDatetime module and i have problems getting the right locale. I need german and the the results are all english. Do i have to set language somewhere else other than html lang="de"? $d = new RockDatetime($event->getUnformatted('event_startdate')); $format = "Jeden %A, %H:%M Uhr"; echo $d->format($format); // Jeden Thursday, 10:00 Uhr ! Link to comment Share on other sites More sharing options...
dragan Posted March 14, 2020 Share Posted March 14, 2020 1 hour ago, DavidBerlin said: Do i have to set language somewhere else other than html lang="de"? Well, that's in your HTML. PHP doesn't care about that, or even knows about it ? Set it somewhere in your template, at the top (if you have a multi-lang setup, you probably need to detect the user language first)https://www.php.net/manual/en/function.setlocale.php or globally in site/config.php 1 Link to comment Share on other sites More sharing options...
LuisM Posted March 24, 2020 Share Posted March 24, 2020 @bernhard I recently installed your RockDateTime module and noticed some strange Errors I'm sorry, couldnt investigate further for now. Link to comment Share on other sites More sharing options...
bernhard Posted March 24, 2020 Author Share Posted March 24, 2020 Hi @LuisM Thank you, that's a known issue https://github.com/BernhardBaumrock/RockDatetime/issues/1 and thx to @Jan Romero we already know the reason. I have some more important stuff to do at the moment and I think I'll refactor my module to use the https://carbon.nesbot.com/ library for handling single timestamps as it has everything already done and is well tested and maintained ? 1 Link to comment Share on other sites More sharing options...
michelangelo Posted July 26, 2020 Share Posted July 26, 2020 (edited) Hello @bernhard, this field looks great! Is it possible for us to use it as well? I would like to implement it in a current project and it seems like it will work perfectly. I saw the module on github but is the inputField also available? Edited July 26, 2020 by michelangelo didn't look through the end of the thread 1 Link to comment Share on other sites More sharing options...
gornycreative Posted October 20, 2022 Share Posted October 20, 2022 @bernhard Curious, do you still use this module/function? Is it something you plan on submitting as a module to the directory? Link to comment Share on other sites More sharing options...
bernhard Posted October 20, 2022 Author Share Posted October 20, 2022 Hi @gornycreative it's used in a production project but I don't have it where I want it to have. And I don't have use for it right now, so it's nothing to happen soon. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now