Giter Site home page Giter Site logo

Comments (2)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 19, 2024
Actually I think the problem is rather simple and works as follows.

"next monday" returns the next Monday from today.
"last monday" returns the previous Monday from today.

"monday" returns the Monday of the current week. 

Examples

// if today is monday
Date.parse('monday'); // returns today

// if today is tuesday
Date.parse('monday'); // returns yesterday

// if today is friday
Date.parse('monday'); // returns the last monday (4 days ago)

The tricky bit happen with "Sundays" because the first-day-of-the-week varies by
Culture/Language/Country. Usually the week either starts on Sunday or Monday.

Example

// if today is Friday, and the firstDayOfWeek (for the culture) is Sunday
Date.parse('sunday'); // returns "last sunday"

// if today is Friday, and the firstDayOfWeek (for the culture) is Monday
Date.parse('sunday'); // returns "next sunday"


The parser handles this all correctly. The parser knows the firstDayOfWeek from 
the
CultureInfo file. Date.CultureInfo.firstDayOfWeek.

You can also perform the same functionality in code with the API. 

Example

// if today is Friday, and the firstDayOfWeek (for the culture) is Sunday
Date.sunday(); // returns "last sunday"

// if today is Friday, and the firstDayOfWeek (for the culture) is Monday
Date.sunday(); // returns "next sunday"

Hope this helps.

Original comment by geoff%[email protected] on 28 Nov 2007 at 11:17

  • Changed state: Invalid

from datejs.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 19, 2024

Original comment by geoff%[email protected] on 27 Mar 2008 at 10:21

  • Changed title: [INVALID] Behaviour when typing a day name on its own is ambiguous

from datejs.

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.