Coder Social home page Coder Social logo

Comments (3)

richardtallent avatar richardtallent commented on July 22, 2024

Hi @MarsZone,

When you provide a string date to JavaScript in ISO 8601 form (yyyy-mm-dd), JavaScript interprets it as midnight UTC. It then converts it to the local time zone of the browser, and the calendar uses the local year, month, and day of that date(ignoring the time and time zone) for display.

So, when you use 2017-12-28, the calendar component doesn't necessarily see December 28, it sees the 27th, 28th, or 29th, depending where the user is located, and also sees a time component that resulted from the time zone conversion (which it ignores).

Because of this, dates should be provided as Date objects (e.g., new Date(2017,11,27) for December 27--be sure to use a 0-based month).

One thing I think I'd like to do is change the component to not let JavaScript convert strings to dates automatically, and to instead do its own conversion when startDate or endDate are provided in a simplified ISO string form (basically modifying the dateOnly method and using map() along with filter() in getWeekEvents() to convert the dates once for each event). I think that will be necessary if we're going to support events times in the future (which I'd like to do).

from vue-simple-calendar.

richardtallent avatar richardtallent commented on July 22, 2024

See this SO answer for more details on the problems of using strings for dates:
https://stackoverflow.com/questions/33908299/javascript-parse-a-string-to-date-as-local-time-zone

from vue-simple-calendar.

MarsZone avatar MarsZone commented on July 22, 2024

Very useful. I got it.
I just use new Date(2017,11,27) give the date objects to startdate.
It works fine and you may provide the options(eg. like different date format) to chose if convert to UTC time or not?

from vue-simple-calendar.

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.