GithubHelp home page GithubHelp logo

Comments (14)

docksteaderluke avatar docksteaderluke commented on May 12, 2024

Here's my test code:

$timestamp = strtotime("2014-01-02");
echo date("nS", $timestamp);    // month number
echo date("jS", $timestamp);    // day-of-month
echo date("zS", $timestamp);    // day-of-year
echo date("wS", $timestamp);    // day-of-week
echo date("WS", $timestamp);    // week-number-of-year

from moment.php.

docksteaderluke avatar docksteaderluke commented on May 12, 2024

One last thing:
'DDDD' should convert to 'z' not 'zS'

from moment.php.

fightbulc avatar fightbulc commented on May 12, 2024

Hey there.

Thanks for the note. I'll have a look for the correct transformations but that wont happen until next week. Would be great if you could figure out the correct formats and push them - in case you have some time.

Cheers
Tino

from moment.php.

docksteaderluke avatar docksteaderluke commented on May 12, 2024

I'll see what I can do. Unfortunately there aren't any ordinal suffixes for anything but the day-of-the-month in PHP (as far as I can tell) so they (the suffixes) may have to be dropped during the conversion.

from moment.php.

fightbulc avatar fightbulc commented on May 12, 2024
echo date('dS M Y'); // 13th May 2014

Thats what u want, right?

from moment.php.

fightbulc avatar fightbulc commented on May 12, 2024

Ah, I see. U want something like:

265th day of the year

correct?

from moment.php.

docksteaderluke avatar docksteaderluke commented on May 12, 2024

Well, it's not so much that I want it but rather that Moment.js supports that and PHP doesn't so you can't convert between the two. The 'S' in PHP is for day-of-the-month ONLY. There are no ordinal suffixes for day-of-the-year. This means that the aforementioned conversions don't work.

from moment.php.

docksteaderluke avatar docksteaderluke commented on May 12, 2024

But yes, it seems (as far as I can tell) getting something like:
265th day of the year
... is impossible in PHP using date formats.

from moment.php.

DavidGagne avatar DavidGagne commented on May 12, 2024

You can do this with PHP.

If you know it's the 265th day of the year you want, you really only care about the 5 to get the correct S value.

To get "th" you can use:
date( 'S', strtotime( '2014-01-05' ) );

If you wanted to get an "st" you can use:
date( 'S', strtotime( '2014-01-01' ) );

from moment.php.

fightbulc avatar fightbulc commented on May 12, 2024

Thats what we want then:
https://gist.github.com/mnbayazit/6195925

from moment.php.

docksteaderluke avatar docksteaderluke commented on May 12, 2024

Perhaps I'm missing something, but that doesn't seem to solve the issue because we don't know what day it is. This issue is dealing with converting a moment.js date format string to a PHP date format string.
i.e.
Mo -> nS
The problem with this is that 'nS' won't give you the correct ordinal suffix (at least not always, see OP).

from moment.php.

fightbulc avatar fightbulc commented on May 12, 2024

Ok, I am just shooting quickly here but we have to do some logic here.

If the user requests something with "o" I know that he wants some ordinal shizzle.
"Mo" goes for the ordinal month. So if we parse for these formats we know what we need to deliver and can simply service it, right?

"Mo" stands for month so we run in php "m" through the aforementioned function which would result in "05th" instead of only giving us back "05".

Again, I am really just going by feeling right now since I am busy with some other stuff.
Looks cool to me at the moment. What u think?

Cheers from Berlin

from moment.php.

docksteaderluke avatar docksteaderluke commented on May 12, 2024

Yes, if you want ordinal suffixes for anything other than day-of-month you need extra logic. But that seems out of scope for the MomentJS.php class since it only handles format strings and not the dates themselves.

SO, with regard to the MomentJS.php class: what should these conversions be?

Moment.js PHP
Mo ???
Do jS
DDDo ???
do ???
wo ???
Wo ???

from moment.php.

fightbulc avatar fightbulc commented on May 12, 2024

version 1.5.0 has this now. just released it.

from moment.php.

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.