Coder Social home page Coder Social logo

Comments (3)

kylekatarnls avatar kylekatarnls commented on July 24, 2024

Hello,

Which timezone are you on? Because we are the 29th now in most places in the world. So maybe you just need to specify the timezone you want:

Carbon::parse('2024-02-29', '-13:00')->isFuture()

is true now, but anything less than -12:00 would be accurately false now.

For the record, it's binary past or future, there is no present and 2024-02-29 stands for 2024-02-29 00:00:00.000000, Carbon objects (like DateTime) are not representing a period but always an exact moment as you can see if you do:

Carbon::parse('2024-02-29')->format('Y-m-d H:i:s.u e')

You would see what the exact date-time and timezone that the object represents.

from carbon.

kylekatarnls avatar kylekatarnls commented on July 24, 2024

Documentation of the method explicitly state reference point is now, not Today, and examples using hours demonstrates the granularity of it:

Determines if the instance is in the future, ie. greater (after) than now.

Example:

Carbon::now()->addHours(5)->isFuture(); // true
Carbon::now()->subHours(5)->isFuture(); // false

Side note, you can easily exclude Today as a special case:

$february29Midnight = Carbon::parse('2024-02-29');

if ($february29Midnight->isToday()) {
  echo 'Happily working 1 more day this year :D';
} elseif ($february29Midnight->isFuture()) {
  echo "It's still after Today";
} else {
  echo "It's before Today";
}

from carbon.

Brenneisen avatar Brenneisen commented on July 24, 2024

Never mind. I thought today was 28.02. I'm sorry.

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.