GithubHelp home page GithubHelp logo

Function Valid::date for timestamp about core HOT 1 OPEN

mati1986 avatar mati1986 commented on August 15, 2024
Function Valid::date for timestamp

from core.

Comments (1)

acoulton avatar acoulton commented on August 15, 2024

Thanks for reporting this. There's not really any active Kohana development any longer, though if you want to PR a fix we'd take a look.

Personally, I don't think Valid::date should ever have been accepting timestamp arguments : strtotime's parsing of them is not what you'd expect:

php > $str = 1500422400;
php > print date('Y-m-d H:i:s', $str)."\n";
2017-07-19 01:00:00
php > print strtotime($str)."\n";
13586799642
php > print date('Y-m-d H:i:s', strtotime($str))."\n";
2400-07-19 15:00:42
php > print_r(new \DateTime($str));
DateTime Object
(
    [date] => 2400-07-19 15:00:42
    [timezone_type] => 3
    [timezone] => Europe/London
)

It's not recognising it as a timestamp, but as a time followed by a partial date. The 1499385600 fails because 14:99 isn't a valid time.

So, even if Valid::date accepted timestamps reliably, it wouldn't be safe to handle them in your application unless you knew that's what they were and treated them differently to a date string.

If you actually want to accept only timestamps then I'd suggest validating as an integer within a suitable range, and explicitly treating as a timestamp in your application code.

If you want to accept date strings, then potentially it's better to use a custom date validator that's more restrictive about the formats it accepts.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.