Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'S' is the ordinal suffix for day-of-the-month only. #8

Closed
docksteaderluke opened this issue May 12, 2014 · 14 comments
Closed

'S' is the ordinal suffix for day-of-the-month only. #8

docksteaderluke opened this issue May 12, 2014 · 14 comments
Labels

Comments

@docksteaderluke
Copy link

In MomentJs.php you have listed conversions for the following momentJS format strings to their appropriate php format strings:

Moment.js PHP Example (2014-01-02)
Mo nS 1nd ✖
Do jS 2nd ✓
DDDo zS 1nd ✖
do wS 4nd ✖
wo WS 1nd ✖
Wo WS 1nd ✖

The only one of the above conversions that is correct is the 'Do' -> 'jS' conversion. According to the PHP docs, 'S' is the English ordinal suffix for the day of the month only.

Sources:
http://php.net/manual/en/function.date.php

@docksteaderluke
Copy link
Author

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

@docksteaderluke
Copy link
Author

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

@fightbulc
Copy link
Owner

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

@docksteaderluke
Copy link
Author

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.

@fightbulc
Copy link
Owner

echo date('dS M Y'); // 13th May 2014

Thats what u want, right?

@fightbulc
Copy link
Owner

Ah, I see. U want something like:

265th day of the year

correct?

@docksteaderluke
Copy link
Author

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.

@docksteaderluke
Copy link
Author

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.

@DavidGagne
Copy link

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' ) );

@fightbulc
Copy link
Owner

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

@docksteaderluke
Copy link
Author

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).

@fightbulc
Copy link
Owner

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

@docksteaderluke
Copy link
Author

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 ???

@fightbulc
Copy link
Owner

version 1.5.0 has this now. just released it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants