Canonical ordering of days of weekSorting a list with secondary criterionSort strings by natural orderingWhy can't I remove Orderless from Plus?Sort matrix by columns and rows without changing themNon-canonical re-ordering of nested listsHow to sort colors properly?Sorting the words of a phrase by defined variables/associationsBin arbitrary data using canonical orderingOrdering a list of integers

What is the need of methods like GET and POST in the HTTP protocol?

How to deal with my team leader who keeps calling me about project updates even though I am on leave for personal reasons?

How can I repair this gas leak on my new range? Teflon tape isn't working

Canonical ordering of days of week

How to ask a man to not take up more than one seat on public transport while avoiding conflict?

What was the deeper meaning of Hermione wanting the cloak?

What benefits does the Power Word Kill spell have?

1, 2, 4, 8, 16, ... 33?

How use custom order in folder on Windows 7 and 10

What can a pilot do if an air traffic controller is incapacitated?

Is it possible to encode a message in such a way that can only be read by someone or something capable of seeing into the very near future?

Hilbert's hotel, why can't I repeat it infinitely many times?

As an employer, can I compel my employees to vote?

What is this utensil for?

Resolving moral conflict

delete object network in cisco ASA with packet tracert

Cut a cake into 3 equal portions with only a knife

What is the meaning of word 'crack' in chapter 33 of A Game of Thrones?

Do you need to hold concentration on a spell when you cast it with a spell scroll?

Are actors contractually obligated to certain things like going nude/ Sensual Scenes/ Gory Scenes?

What are these pixel-level discolored specks? How can I fix it?

Where does an unaligned creature's soul go after death?

What are these ingforms of learning?

Is It Possible to Have Different Sea Levels, Eventually Causing New Landforms to Appear?



Canonical ordering of days of week


Sorting a list with secondary criterionSort strings by natural orderingWhy can't I remove Orderless from Plus?Sort matrix by columns and rows without changing themNon-canonical re-ordering of nested listsHow to sort colors properly?Sorting the words of a phrase by defined variables/associationsBin arbitrary data using canonical orderingOrdering a list of integers






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








5












$begingroup$


The entities representing the days of the week sort alphabetically:



Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]

(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)


(Note that these are not strings.)



Is there a better way to sort than using the following?



SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]









share|improve this question









$endgroup$













  • $begingroup$
    Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
    $endgroup$
    – SHuisman
    10 hours ago










  • $begingroup$
    "Canonically" (i.e. according to the Bible) the first day was Sunday.
    $endgroup$
    – mikado
    1 hour ago

















5












$begingroup$


The entities representing the days of the week sort alphabetically:



Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]

(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)


(Note that these are not strings.)



Is there a better way to sort than using the following?



SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]









share|improve this question









$endgroup$













  • $begingroup$
    Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
    $endgroup$
    – SHuisman
    10 hours ago










  • $begingroup$
    "Canonically" (i.e. according to the Bible) the first day was Sunday.
    $endgroup$
    – mikado
    1 hour ago













5












5








5





$begingroup$


The entities representing the days of the week sort alphabetically:



Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]

(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)


(Note that these are not strings.)



Is there a better way to sort than using the following?



SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]









share|improve this question









$endgroup$




The entities representing the days of the week sort alphabetically:



Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]

(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)


(Note that these are not strings.)



Is there a better way to sort than using the following?



SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]






sorting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 11 hours ago









Stephen PowellStephen Powell

6673 silver badges12 bronze badges




6673 silver badges12 bronze badges














  • $begingroup$
    Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
    $endgroup$
    – SHuisman
    10 hours ago










  • $begingroup$
    "Canonically" (i.e. according to the Bible) the first day was Sunday.
    $endgroup$
    – mikado
    1 hour ago
















  • $begingroup$
    Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
    $endgroup$
    – SHuisman
    10 hours ago










  • $begingroup$
    "Canonically" (i.e. according to the Bible) the first day was Sunday.
    $endgroup$
    – mikado
    1 hour ago















$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago




$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago












$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago




$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago










3 Answers
3






active

oldest

votes


















3














$begingroup$

It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:



System`DateObjectDump`$dowAssociation



<|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
Friday -> 5, Saturday -> 6, Sunday -> 7|>




sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];


Examples:



sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday



Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday




sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]



Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday







share|improve this answer









$endgroup$






















    2














    $begingroup$

    As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:



    SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
    Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
    (* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)


    This works by converting the day types into actual dates. This is done in three steps:



    • Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)

    • Find the date of the first Monday/... after that point

    • Sort these dates





    share|improve this answer









    $endgroup$






















      0














      $begingroup$

      You could define your own special sorting function. Like so:



      With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
      With[indexed = PositionIndex[ordered],
      sortByDay[data_] := SortBy[data, indexed[#] &]]]


      Tests



      sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday



      Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday




      sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday



      Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday







      share|improve this answer









      $endgroup$

















        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "387"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206489%2fcanonical-ordering-of-days-of-week%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3














        $begingroup$

        It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:



        System`DateObjectDump`$dowAssociation



        <|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
        Friday -> 5, Saturday -> 6, Sunday -> 7|>




        sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];


        Examples:



        sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday



        Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday




        sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]



        Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday







        share|improve this answer









        $endgroup$



















          3














          $begingroup$

          It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:



          System`DateObjectDump`$dowAssociation



          <|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
          Friday -> 5, Saturday -> 6, Sunday -> 7|>




          sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];


          Examples:



          sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday



          Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday




          sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]



          Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday







          share|improve this answer









          $endgroup$

















            3














            3










            3







            $begingroup$

            It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:



            System`DateObjectDump`$dowAssociation



            <|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
            Friday -> 5, Saturday -> 6, Sunday -> 7|>




            sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];


            Examples:



            sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday



            Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday




            sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]



            Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday







            share|improve this answer









            $endgroup$



            It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:



            System`DateObjectDump`$dowAssociation



            <|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
            Friday -> 5, Saturday -> 6, Sunday -> 7|>




            sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];


            Examples:



            sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday



            Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday




            sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]



            Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 4 hours ago









            kglrkglr

            217k10 gold badges247 silver badges498 bronze badges




            217k10 gold badges247 silver badges498 bronze badges


























                2














                $begingroup$

                As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:



                SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
                Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
                (* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)


                This works by converting the day types into actual dates. This is done in three steps:



                • Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)

                • Find the date of the first Monday/... after that point

                • Sort these dates





                share|improve this answer









                $endgroup$



















                  2














                  $begingroup$

                  As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:



                  SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
                  Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
                  (* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)


                  This works by converting the day types into actual dates. This is done in three steps:



                  • Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)

                  • Find the date of the first Monday/... after that point

                  • Sort these dates





                  share|improve this answer









                  $endgroup$

















                    2














                    2










                    2







                    $begingroup$

                    As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:



                    SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
                    Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
                    (* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)


                    This works by converting the day types into actual dates. This is done in three steps:



                    • Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)

                    • Find the date of the first Monday/... after that point

                    • Sort these dates





                    share|improve this answer









                    $endgroup$



                    As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:



                    SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
                    Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
                    (* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)


                    This works by converting the day types into actual dates. This is done in three steps:



                    • Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)

                    • Find the date of the first Monday/... after that point

                    • Sort these dates






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 11 hours ago









                    Lukas LangLukas Lang

                    9,7591 gold badge13 silver badges36 bronze badges




                    9,7591 gold badge13 silver badges36 bronze badges
























                        0














                        $begingroup$

                        You could define your own special sorting function. Like so:



                        With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
                        With[indexed = PositionIndex[ordered],
                        sortByDay[data_] := SortBy[data, indexed[#] &]]]


                        Tests



                        sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday



                        Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday




                        sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday



                        Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday







                        share|improve this answer









                        $endgroup$



















                          0














                          $begingroup$

                          You could define your own special sorting function. Like so:



                          With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
                          With[indexed = PositionIndex[ordered],
                          sortByDay[data_] := SortBy[data, indexed[#] &]]]


                          Tests



                          sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday



                          Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday




                          sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday



                          Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday







                          share|improve this answer









                          $endgroup$

















                            0














                            0










                            0







                            $begingroup$

                            You could define your own special sorting function. Like so:



                            With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
                            With[indexed = PositionIndex[ordered],
                            sortByDay[data_] := SortBy[data, indexed[#] &]]]


                            Tests



                            sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday



                            Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday




                            sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday



                            Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday







                            share|improve this answer









                            $endgroup$



                            You could define your own special sorting function. Like so:



                            With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
                            With[indexed = PositionIndex[ordered],
                            sortByDay[data_] := SortBy[data, indexed[#] &]]]


                            Tests



                            sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday



                            Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday




                            sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday



                            Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday








                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 10 hours ago









                            m_goldbergm_goldberg

                            91.6k8 gold badges75 silver badges209 bronze badges




                            91.6k8 gold badges75 silver badges209 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to Mathematica Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                Use MathJax to format equations. MathJax reference.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206489%2fcanonical-ordering-of-days-of-week%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480