Comments (10)
@gscscnd
Thank you for the pull request and contribution, but did you see the filter DateTimeFormatter
?
https://github.com/zendframework/zend-filter/blob/master/src/DateTimeFormatter.php
Originally posted by @froschdesign at zendframework/zend-filter#85 (comment)
from laminas-filter.
@froschdesign, it seems that DateTimeFormatter
returns a string, while I would like to receive DateTimeInterface
.
Originally posted by @gszy at zendframework/zend-filter#85 (comment)
from laminas-filter.
@gscscnd
You are right. (Never read on phone in the sun! 🤦♂️ )
The following filtering is support:
- string to
DateTime
- string to
DateTimeImmutable
DateTime
toDateTimeImmutable
DateTimeImmutable
toDateTime
Is this correct or did I forget something?
Originally posted by @froschdesign at zendframework/zend-filter#85 (comment)
from laminas-filter.
- string to
DateTime
- string to
DateTimeImmutable
Actually I don’t check if a string
was provided, just pass it to DateTime
/DateTimeImmutable
constructor.
DateTime
toDateTimeImmutable
DateTimeImmutable
toDateTime
Also DateTime
to DateTime
and similarly for immutable.
Originally posted by @gszy at zendframework/zend-filter#85 (comment)
from laminas-filter.
We have to explicitly define all possible values for the filtering - input and ouput. Otherwise, we can not write the full documentation and all required unit tests.
Also
DateTime
toDateTime
and similarly for immutable.
This means:
DateTime
toDateTime
(new object,$immutable === false
)DateTime
toDateTimeImmutable
(new object,$immutable === true
)DateTimeImmutable
toDateTime
(new object,$immutable === false
)DateTimeImmutable
toDateTimeImmutable
(new object,$immutable === true
)
Originally posted by @froschdesign at zendframework/zend-filter#85 (comment)
from laminas-filter.
We can throw an InvalidArgumentException
if the user provides something other than DateTimeInterface|string
. The user can provide a valid string that at the same time (ahem) is not a valid datetime, but it’s probably Date Validator’s responsibility.
Anyway:
DateTime
→DateTime
DateTime
→DateTimeImmutable
DateTimeImmutable
→DateTime
DateTimeImmutable
→DateTimeImmutable
string
→DateTime
string
→DateTimeImmutable
Originally posted by @gszy at zendframework/zend-filter#85 (comment)
from laminas-filter.
@gscscnd
We can throw an
InvalidArgumentException
if the user provides something other thanDateTimeInterface|string
.
No exceptions are allowed during the process of filtering. If the given value can not be handled by the filter, the value should be returned unfiltered.
DateTime
→DateTime
DateTimeImmutable
→DateTimeImmutable
Does the filter create a new object each time or will the same object returned?
Can you describe the typical use case for this filter? Thanks!
Originally posted by @froschdesign at zendframework/zend-filter#85 (comment)
from laminas-filter.
No exceptions are allowed during the process of filtering. If the given value can not be handled by the filter, the value should be returned unfiltered.
🆗, will fix that. (Current code doesn’t throw exceptions explicitly, but setting $value
to int
will surely cause the DateTime
constructor to throw.)
DateTime
→DateTime
DateTimeImmutable
→DateTimeImmutable
Does the filter create a new object each time or will the same object returned?
Returns the same instance.
Can you describe the typical use case for this filter? Thanks!
I’ve got a form (or any array of data, for that matter) with a datetime‑like input and an entity with a datetime‑like property. I setup an InputFilter with a Date validator and a DateTime filter. The input array contains 2019-04-25T08:02
(string
) and the (hydrated) output object has instance of DateTimeInterface
.
Originally posted by @gszy at zendframework/zend-filter#85 (comment)
from laminas-filter.
@gscscnd
The input array contains
2019-04-25T08:02
(string
) and the (hydrated) output object has instance ofDateTimeInterface
.
If you use zend-hydrator already then you can use Zend\Hydrator\Strategy\DateTimeFormatterStrategy
to get the desired result. Have you tried this strategy?
Originally posted by @froschdesign at zendframework/zend-filter#85 (comment)
from laminas-filter.
Well, I didn’t know about it. Thanks for the pointer!
Originally posted by @gszy at zendframework/zend-filter#85 (comment)
from laminas-filter.
Related Issues (20)
- [RFC]: Removal of `UriNormalizer` HOT 2
- v3 Docs: Improve documentation on change to final everywhere
- Test failure with OpenSSL 3.0 HOT 1
- RenameUpload filter breaks UploadFile validator HOT 1
- PHP 8.1 support HOT 3
- Non-string scalar types produce a fatal error with StripNewlines HOT 6
- Hydration of object attached to form with unfiltered values on submission HOT 1
- Is `DateTimeFormatter` filter missed in documentation? HOT 1
- Removal of `container-interop/container-interop`
- Problem with FileInput HOT 1
- Dependency Dashboard
- Declaration of Laminas\Filter\FilterPluginManager::get($name, ?array $options = NULL) must be compatible with Laminas\ServiceManager\AbstractPluginManager::get($name, $options = Array, $usePeeringServiceManagers = true) HOT 10
- Action Required: Fix Renovate Configuration HOT 3
- [RFC]: Deprecate Compression Adapters Lzf, Rar and Snappy HOT 1
- Remove Deprecated Compression Adapters HOT 1
- Remove Deprecated Encryption & Decryption Filters HOT 1
- Mark filters as attributes HOT 7
- `Boolean` filter should also accept `int-mask<self::CONSTANTS>` via `__construct`
- Check for an instance of the `DateTimeInterface` instead of `DateTime` in `DateTimeFormatter` HOT 4
- ToString filter missing? 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 laminas-filter.