Comments (11)
@brendt to do what you are requesting it means at least adding a Sequence class to the package which I'm working on right now. the PR for it will hopefully land on separate branch once the code is stable. If you want I can make it public rigth now but the tests are no quite finish.
For now I can tell you that it will have the basic methods from a Sequence object with two additional methods which are Sequence::getGaps
and Sequence::getIntersections
which should return the gaps and intersections inside a collection of Period objects. Does that sound good for you ?
Do you want me to publish in a separate branch the work in progress on the Sequence
class to see if it meets your requirements ? Any input is welcomed 😉
from period.
@nyamsprod great to hear! I'll definitely want to take a look!
from period.
you can find it here now https://github.com/thephpleague/period/blob/feature/add-sequence/src/Sequence.php ... again the implementation is not done so yes if you want to improve it be my guess 😉
from period.
Thanks! There's one thing I'm wondering about: if you sort the intervals by start date to calculate the gaps, is the following scenario covered?
sequence:
0) [==================]
1) [====]
2) [=====]
expected gap:
[==]
resulting gap:
[============]
I haven't run the code yet, but from reading it, I wonder how this would work if you're relying on a sorted set 🤔
from period.
@brendt this is a first implementation and tests are missing ... So yeah it is more than possible that your test will not work yet
from period.
i've just tested you assumption and I do get the expected result 👍
<?php
use League\Period;
use League\Period\Sequence;
echo "<pre>", PHP_EOL;
$today = Period\day('2018-11-29');
$week = Period\interval_around('2018-11-29', '4 DAYS');
$next = Period\interval_after('2018-11-29 + 7 DAYS', '1 DAY');
$sequence = new Sequence($week, $today, $next);
$gaps = $sequence->getGaps();
var_export([
'nb sequence' => count($sequence),
'nb gaps' => count($gaps),
'gap' => $gaps->get(0)->format('Y-m-d'),
]);
result
array (
'nb sequence' => 3,
'nb gaps' => 1,
'gap' => '[2018-12-03, 2018-12-06)',
)
from period.
but I'll confess that Sequence::getIntersections
is still a mess of a implementation 😭
from period.
@brendt I've added some of your package tests to the sequence testsuite as well as your example for the getGaps tests and after some fixes seems that my two methods do exactly what you are looking for. Of course more tests are welcomed to complete the testsuite 😉
from period.
Oh that's great! Guess I can close this issue now 👍
from period.
@brendt the Sequence class has landed on the master branch and you can already see its documentation on the website If all goes as planned 4.1 should be released next week 😉
from period.
That's great! I'll do my best to try it out in one of our projects!
from period.
Related Issues (20)
- Period::split() return Sequence HOT 1
- Is v3.x still stable and secure for PHP >=5.6 compatible environments (WP Plugins) HOT 1
- Can the lib handle periods without/ignoring year? HOT 3
- Number of (over)nights HOT 3
- Possible to determine the end of a duration in a sequence? HOT 2
- Navigation on docs page seems broken HOT 2
- Upgrade from 4.11 to 4.12 getDatePeriod returns DateTimeImmutable instead of Datepoints? HOT 2
- Quotation marks in Iso80000 range cause an exception HOT 2
- Missing tests HOT 4
- Add support for PHP8.2
- Type hinting `|Type[]` returns, when not a technical possibility HOT 2
- Sequence has multiple same period ,call the intersections func ,result is error HOT 5
- Adding the boundaryType to Period named constructors ?
- Period without end HOT 3
- Add ability to associate additional custom data to a Period HOT 12
- Create from ISO8601 string HOT 11
- Merge sequences. (Logical OR similar to subtract which is logical NOT) HOT 1
- Missing Period in Sequence intersections. HOT 5
- sequence subtraction bug HOT 1
- Merge Bakame/Period-Visualizer codebase to the Period repo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from period.