Comments (11)
I have an idea about implementing typehanders that is versatile enough for your carbon usecase. The (optional) typehandlers that I will be including will only use native PHP though. Unfortunately I do not have that much time on my hands at the moment but I will try to get it done before the holiday season starts.
from exact-php-client.
I don't think automatically converting to DateTime would be a good option. Not everyone uses DateTime and it's an unnecessary performance hit to always convert the timestamp to an object.
We could add your function to the README to help people on their way to use the return values from Exact.
from exact-php-client.
Yes I agree with you. That is part of why I was in indecision. On one hand the value we get form Exact is useless. On the other we don't want an expensive and complex operation.
As Exact already documents it as DateTime and DateTime is the most versatile approach to date and time operations in PHP I don't agree with that part of your counter argument.
Perhaps what we are missing is a way to inject strategies. That way I could also have build the lazy loading as an addon without breaking compatibility. The downside is of course that the Model requires initialization and might become overly complex.
Thanks again for your time and free to add the function tot the documentation!
from exact-php-client.
I personally use Carbon a lot, which extends DateTime. In this case I would get a DateTime object and then create a Carbon object from that. I notice quite some devs use other libraries that extend the not so readable DateTime class of PHP.
If it is doable, we could make it an option for the client. We don't really have any option / configs yet, but it could be on the connection as this is injected for everything.
The excellent Excel library box/spout has this feature: https://github.com/box/spout#datetime-formatting
As a dev you can then choose to use DateTime or original values and only add the overhead of transforming the data if you choose so. This also keeps everything backwards compatible.
from exact-php-client.
public function __get($key)
{
if (isset($this->attributes[$key])) {
if (is_string($this->attributes[$key])
&& preg_match(
'(\/Date\(\d+\)\/)', $this->attributes[$key]
)
) {
return $this->exactToDateTime($this->attributes[$key]);
}
return $this->attributes[$key];
}
}
?
from exact-php-client.
@Pirabarlen-Cheenaramen That would work for you most likely but will break backward compatibility and we are looking for a more generic solution so we can handle any type of data flowing trough the model.
from exact-php-client.
Maybe even nicer to do something with injection:
$connection->setDateFormatter(callable $dateFormatter);
And in the model use:
return $this->connection->dateFormat($exact);
And in the connection.php:
private $dateFormatter;
public function setDateFormatter(callable $formatter)
{
$this->dateFormatter = $formatter;
}
public function getDateFormatter()
{
if (empty($this->dateFormatter)) {
$this->dateFormatter = function ($exact) {
$timestamp = substr($exact, 6, 10);
$date = new \DateTime();
$date->setTimestamp($timestamp);
return $date;
}
}
return $this->dateFormatter;
}
public function dateFormat($exact)
{
$formatter = $this->getDateFormatter();
return $formatter($exact);
}
from exact-php-client.
@silvant I have been a bit over allocated both at work and in private. I did draft a generic solution for typehandling but there are some issues I need to work out.
We have more Exact integration planned for the first quarter of this year. I can at least use some corporate time to do some testing and benchmarking.
from exact-php-client.
@kvij Want me to take a look at it? If you make a branch I can do. I usually have a few hours a week available for these kind of things (and a having paying customer who wants an Exact integration also helps 😃 )
from exact-php-client.
@silvant Sorry I missed this entirely 😞. I have made a working implementation, it's fairly complex with and has some issues. Most notably there is to large a performance impact and to much magic going on.
This all has everything to do with trying to do typehanding in a framework that loses all type information but comunitcates with a statically typed backed.
Therefore I am going to solve this by first restoring the type information in the entities (without losing backwards compatibility). And from there on workout the basics of the type-handling.
I will toss the current typehandler branch and create a new one. I will let you know when I am done with the basics so we can work together on this if you are still interested!
from exact-php-client.
Closing this for now, since there is nothing planned on date handling at the moment and no activity.
from exact-php-client.
Related Issues (20)
- Error 400: Expression of type 'System.Boolean' expected at position 0. HOT 1
- Format (of Guid) / (Required / Minimum) properties for GeneralJournalEntry HOT 2
- Exceptions without errors HOT 5
- Old refresh token used in loop HOT 2
- Issue with updating salesInvoice (PUT) HOT 1
- Cannot find GLAccount associated with Financial/TransactionLines HOT 1
- Switch to the new APIs before 1 June, 2023 HOT 6
- Question regarding error "Old refresh token used" HOT 5
- SalesOrderOrderChargeLines not available in bulk HOT 6
- Not able to Authorize HOT 1
- Requesting AccountItem results in 400 Bad Request - Error in query syntax HOT 2
- SalesOrderLines and SalesOrderOrderChargeLines HOT 2
- Client with identifier 'xxx-yyy-zzz' not found. HOT 5
- SalesEntry payments HOT 1
- What endpoint to get all articles?
- cURL error 77 HOT 4
- Provide a way to let exceptions bubble through to application HOT 6
- Picqer\Financials\Exact\Connection::upload() is missing optional parameters. HOT 1
- Referenced page is empty. Perhaps the endpoint is also removed? HOT 1
- PurchaseEntry approve for payment 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 exact-php-client.