GithubHelp home page GithubHelp logo

Comments (3)

 avatar commented on June 11, 2024 1

Yes, you guessed right!

Anyway... is there any built-in isValid method?
Something to use in order to verify that a date is valid like:

$date = Carbon::createFromFormat('Y-m-d', '0000-00-00');
$date->isValid() ? $date->day : Carbon::now()->day;

Thanks

from carbon.

briannesbitt avatar briannesbitt commented on June 11, 2024

You get the same thing if you do var_dump(DateTime::createFromFormat('Y-m-d', '0000-00-00')); which is the base implementation.

Since the valid month and day values are from 1 - 12 and 1 - 31 I think it is setting the month and day to current'ish values -1. So month is Dec - 1 ... ie Nov. Date is 0 which is invalid so its defaulted to 1 - 1 which would be Dec 1 - 1 ...ie 30. Same thing for year. Just guessing.

You get what you get when you pass in invalid parameters ?!?
http://php.net/manual/en/datetime.createfromformat.php

BTW, it throws an InvalidArgumentException if you do something really bad like Carbon::createFromFormat('Y-m-d', '0000-0-000');

from carbon.

briannesbitt avatar briannesbitt commented on June 11, 2024

No. If you pass in an invalid date it will throw an InvalidArgumentException :-)

Your date is valid, not commonly used, but valid none the less. -0001 is just 1 year BC.

http://en.wikipedia.org/wiki/Gregorian_calendar#Proleptic_Gregorian_calendar
For dates before the year 1, unlike the proleptic Gregorian calendar used in the international standard ISO 8601, the traditional proleptic Gregorian calendar (like the Julian calendar) does not have a year 0 and instead uses the ordinal numbers 1, 2, … both for years AD and BC. Thus the traditional time line is 2 BC, 1 BC, AD 1, and AD 2. ISO 8601 uses astronomical year numbering which includes a year 0 and negative numbers before it. Thus the ISO 8601 time line is −0001, 0000, 0001, and 0002.

from carbon.

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.