Fuzzy Humanize date using Moment.js for datatable searching The 2019 Stack Overflow Developer Survey Results Are InFinding image by dateDate formatter for javascriptApproximating Date for a D3.js timelineDate Comparison ScriptConfiguring a date picker with support for disabled datesAdd WeekDays to DateBuilding a 2D array “month view” for a given dateHumanDate for easier date calculationsDate class for Budgeting AppCompute end date for project

Does it makes sense to buy a new cycle to learn riding?

Is there a general name for the setup in which payoffs are not known exactly but players try to influence each other's perception of the payoffs?

How is the Antim Sanskar of married Hindu women done?

Why do some words that are not inflected have an umlaut?

Is it true that “A.D.” is traditionally placed before the year number?

aging parents with no investments

Unbreakable Formation vs. Cry of the Carnarium

Is this food a bread or a loaf?

Understanding the implication of what "well-defined" means for the operation in quotient group

What is the best strategy for white in this position?

How was Skylab's orbit inclination chosen?

Patience, young "Padovan"

When to use the root test. Is this not a good situation to use it?

Should I use my personal or workplace e-mail when registering to external websites for work purpose?

Inflated grade on resume at previous job, might former employer tell new employer?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Why isn't airport relocation done gradually?

Is "plugging out" electronic devices an American expression?

How can I fix this gap between bookcases I made?

Is domain driven design an anti-SQL pattern?

What is the use of option -o in the useradd command?

Where does the "burst of radiance" from Holy Weapon originate?

Why don't Unix/Linux systems traverse through directories until they find the required version of a linked library?

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?



Fuzzy Humanize date using Moment.js for datatable searching



The 2019 Stack Overflow Developer Survey Results Are InFinding image by dateDate formatter for javascriptApproximating Date for a D3.js timelineDate Comparison ScriptConfiguring a date picker with support for disabled datesAdd WeekDays to DateBuilding a 2D array “month view” for a given dateHumanDate for easier date calculationsDate class for Budgeting AppCompute end date for project



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








1












$begingroup$


In my JS project, I am using datatable plugin to show data where I have a date column which users can filter/search.



In order to help users to search using a logical string such as today, thismonth , lastweek I am writting a fucntion which uses MomentJs.



I am looking at the most efficient way of writing this fuzzyDate function.






function fuzzyDate(mydate)
var fuzzy1 = ''; var fuzzy2 = ''; var fuzzy3 = '';

var todaydt = moment(moment().format('YYYY-MM-DD'));
var daydiff = mydate.diff(todaydt,'day');
if (daydiff==-1)fuzzy1='Yesterday'
if (daydiff==0)fuzzy1='Today'
if (daydiff==1)fuzzy1='Tomorrow'

var weekdiff = mydate.diff(todaydt,'week');
if (weekdiff==-1)fuzzy2='LastWeek'
if (weekdiff==0)fuzzy2='ThisWeek'
if (weekdiff==1)fuzzy2='NextWeek'

var monthdiff = mydate.diff(todaydt,'month');
if (monthdiff==-1)fuzzy3='LastMonth'
if (monthdiff==0)fuzzy3='ThisMonth'
if (monthdiff==1)fuzzy3='NextMonth'

return fuzzy1 + ' ' + fuzzy2 + ' ' + fuzzy3;


console.log( '2018-06-01 - ', fuzzyDate(moment('2018-06-01','YYYY-MM-DD')) ) ;
console.log( '2018-07-01 - ', fuzzyDate(moment('2018-07-01','YYYY-MM-DD')) ) ;
console.log( '2018-07-07 - ', fuzzyDate(moment('2018-07-07','YYYY-MM-DD')) ) ;
console.log( '2018-07-10 - ', fuzzyDate(moment('2018-07-10','YYYY-MM-DD')) ) ;
console.log( '2018-07-11 - ', fuzzyDate(moment('2018-07-11','YYYY-MM-DD')) ) ;
console.log( '2018-07-12 - ', fuzzyDate(moment('2018-07-12','YYYY-MM-DD')) ) ;
console.log( '2018-07-13 - ', fuzzyDate(moment('2018-07-13','YYYY-MM-DD')) ) ;
console.log( '2018-07-15 - ', fuzzyDate(moment('2018-07-15','YYYY-MM-DD')) ) ;
console.log( '2018-07-30 - ', fuzzyDate(moment('2018-07-30','YYYY-MM-DD')) ) ;
console.log( '2018-08-30 - ', fuzzyDate(moment('2018-08-30','YYYY-MM-DD')) ) ;

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>





Output of the above function



2018-06-01 - LastMonth
2018-07-01 - LastWeek ThisMonth
2018-07-07 - ThisWeek ThisMonth
2018-07-10 - ThisWeek ThisMonth
2018-07-11 - Yesterday ThisWeek ThisMonth
2018-07-12 - Today ThisWeek ThisMonth
2018-07-13 - Tomorrow ThisWeek ThisMonth
2018-07-15 - ThisWeek ThisMonth
2018-07-30 - ThisMonth
2018-08-30 - NextMonth









share|improve this question









$endgroup$




bumped to the homepage by Community♦ 2 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





















    1












    $begingroup$


    In my JS project, I am using datatable plugin to show data where I have a date column which users can filter/search.



    In order to help users to search using a logical string such as today, thismonth , lastweek I am writting a fucntion which uses MomentJs.



    I am looking at the most efficient way of writing this fuzzyDate function.






    function fuzzyDate(mydate)
    var fuzzy1 = ''; var fuzzy2 = ''; var fuzzy3 = '';

    var todaydt = moment(moment().format('YYYY-MM-DD'));
    var daydiff = mydate.diff(todaydt,'day');
    if (daydiff==-1)fuzzy1='Yesterday'
    if (daydiff==0)fuzzy1='Today'
    if (daydiff==1)fuzzy1='Tomorrow'

    var weekdiff = mydate.diff(todaydt,'week');
    if (weekdiff==-1)fuzzy2='LastWeek'
    if (weekdiff==0)fuzzy2='ThisWeek'
    if (weekdiff==1)fuzzy2='NextWeek'

    var monthdiff = mydate.diff(todaydt,'month');
    if (monthdiff==-1)fuzzy3='LastMonth'
    if (monthdiff==0)fuzzy3='ThisMonth'
    if (monthdiff==1)fuzzy3='NextMonth'

    return fuzzy1 + ' ' + fuzzy2 + ' ' + fuzzy3;


    console.log( '2018-06-01 - ', fuzzyDate(moment('2018-06-01','YYYY-MM-DD')) ) ;
    console.log( '2018-07-01 - ', fuzzyDate(moment('2018-07-01','YYYY-MM-DD')) ) ;
    console.log( '2018-07-07 - ', fuzzyDate(moment('2018-07-07','YYYY-MM-DD')) ) ;
    console.log( '2018-07-10 - ', fuzzyDate(moment('2018-07-10','YYYY-MM-DD')) ) ;
    console.log( '2018-07-11 - ', fuzzyDate(moment('2018-07-11','YYYY-MM-DD')) ) ;
    console.log( '2018-07-12 - ', fuzzyDate(moment('2018-07-12','YYYY-MM-DD')) ) ;
    console.log( '2018-07-13 - ', fuzzyDate(moment('2018-07-13','YYYY-MM-DD')) ) ;
    console.log( '2018-07-15 - ', fuzzyDate(moment('2018-07-15','YYYY-MM-DD')) ) ;
    console.log( '2018-07-30 - ', fuzzyDate(moment('2018-07-30','YYYY-MM-DD')) ) ;
    console.log( '2018-08-30 - ', fuzzyDate(moment('2018-08-30','YYYY-MM-DD')) ) ;

    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>





    Output of the above function



    2018-06-01 - LastMonth
    2018-07-01 - LastWeek ThisMonth
    2018-07-07 - ThisWeek ThisMonth
    2018-07-10 - ThisWeek ThisMonth
    2018-07-11 - Yesterday ThisWeek ThisMonth
    2018-07-12 - Today ThisWeek ThisMonth
    2018-07-13 - Tomorrow ThisWeek ThisMonth
    2018-07-15 - ThisWeek ThisMonth
    2018-07-30 - ThisMonth
    2018-08-30 - NextMonth









    share|improve this question









    $endgroup$




    bumped to the homepage by Community♦ 2 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      1












      1








      1





      $begingroup$


      In my JS project, I am using datatable plugin to show data where I have a date column which users can filter/search.



      In order to help users to search using a logical string such as today, thismonth , lastweek I am writting a fucntion which uses MomentJs.



      I am looking at the most efficient way of writing this fuzzyDate function.






      function fuzzyDate(mydate)
      var fuzzy1 = ''; var fuzzy2 = ''; var fuzzy3 = '';

      var todaydt = moment(moment().format('YYYY-MM-DD'));
      var daydiff = mydate.diff(todaydt,'day');
      if (daydiff==-1)fuzzy1='Yesterday'
      if (daydiff==0)fuzzy1='Today'
      if (daydiff==1)fuzzy1='Tomorrow'

      var weekdiff = mydate.diff(todaydt,'week');
      if (weekdiff==-1)fuzzy2='LastWeek'
      if (weekdiff==0)fuzzy2='ThisWeek'
      if (weekdiff==1)fuzzy2='NextWeek'

      var monthdiff = mydate.diff(todaydt,'month');
      if (monthdiff==-1)fuzzy3='LastMonth'
      if (monthdiff==0)fuzzy3='ThisMonth'
      if (monthdiff==1)fuzzy3='NextMonth'

      return fuzzy1 + ' ' + fuzzy2 + ' ' + fuzzy3;


      console.log( '2018-06-01 - ', fuzzyDate(moment('2018-06-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-01 - ', fuzzyDate(moment('2018-07-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-07 - ', fuzzyDate(moment('2018-07-07','YYYY-MM-DD')) ) ;
      console.log( '2018-07-10 - ', fuzzyDate(moment('2018-07-10','YYYY-MM-DD')) ) ;
      console.log( '2018-07-11 - ', fuzzyDate(moment('2018-07-11','YYYY-MM-DD')) ) ;
      console.log( '2018-07-12 - ', fuzzyDate(moment('2018-07-12','YYYY-MM-DD')) ) ;
      console.log( '2018-07-13 - ', fuzzyDate(moment('2018-07-13','YYYY-MM-DD')) ) ;
      console.log( '2018-07-15 - ', fuzzyDate(moment('2018-07-15','YYYY-MM-DD')) ) ;
      console.log( '2018-07-30 - ', fuzzyDate(moment('2018-07-30','YYYY-MM-DD')) ) ;
      console.log( '2018-08-30 - ', fuzzyDate(moment('2018-08-30','YYYY-MM-DD')) ) ;

      <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>





      Output of the above function



      2018-06-01 - LastMonth
      2018-07-01 - LastWeek ThisMonth
      2018-07-07 - ThisWeek ThisMonth
      2018-07-10 - ThisWeek ThisMonth
      2018-07-11 - Yesterday ThisWeek ThisMonth
      2018-07-12 - Today ThisWeek ThisMonth
      2018-07-13 - Tomorrow ThisWeek ThisMonth
      2018-07-15 - ThisWeek ThisMonth
      2018-07-30 - ThisMonth
      2018-08-30 - NextMonth









      share|improve this question









      $endgroup$




      In my JS project, I am using datatable plugin to show data where I have a date column which users can filter/search.



      In order to help users to search using a logical string such as today, thismonth , lastweek I am writting a fucntion which uses MomentJs.



      I am looking at the most efficient way of writing this fuzzyDate function.






      function fuzzyDate(mydate)
      var fuzzy1 = ''; var fuzzy2 = ''; var fuzzy3 = '';

      var todaydt = moment(moment().format('YYYY-MM-DD'));
      var daydiff = mydate.diff(todaydt,'day');
      if (daydiff==-1)fuzzy1='Yesterday'
      if (daydiff==0)fuzzy1='Today'
      if (daydiff==1)fuzzy1='Tomorrow'

      var weekdiff = mydate.diff(todaydt,'week');
      if (weekdiff==-1)fuzzy2='LastWeek'
      if (weekdiff==0)fuzzy2='ThisWeek'
      if (weekdiff==1)fuzzy2='NextWeek'

      var monthdiff = mydate.diff(todaydt,'month');
      if (monthdiff==-1)fuzzy3='LastMonth'
      if (monthdiff==0)fuzzy3='ThisMonth'
      if (monthdiff==1)fuzzy3='NextMonth'

      return fuzzy1 + ' ' + fuzzy2 + ' ' + fuzzy3;


      console.log( '2018-06-01 - ', fuzzyDate(moment('2018-06-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-01 - ', fuzzyDate(moment('2018-07-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-07 - ', fuzzyDate(moment('2018-07-07','YYYY-MM-DD')) ) ;
      console.log( '2018-07-10 - ', fuzzyDate(moment('2018-07-10','YYYY-MM-DD')) ) ;
      console.log( '2018-07-11 - ', fuzzyDate(moment('2018-07-11','YYYY-MM-DD')) ) ;
      console.log( '2018-07-12 - ', fuzzyDate(moment('2018-07-12','YYYY-MM-DD')) ) ;
      console.log( '2018-07-13 - ', fuzzyDate(moment('2018-07-13','YYYY-MM-DD')) ) ;
      console.log( '2018-07-15 - ', fuzzyDate(moment('2018-07-15','YYYY-MM-DD')) ) ;
      console.log( '2018-07-30 - ', fuzzyDate(moment('2018-07-30','YYYY-MM-DD')) ) ;
      console.log( '2018-08-30 - ', fuzzyDate(moment('2018-08-30','YYYY-MM-DD')) ) ;

      <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>





      Output of the above function



      2018-06-01 - LastMonth
      2018-07-01 - LastWeek ThisMonth
      2018-07-07 - ThisWeek ThisMonth
      2018-07-10 - ThisWeek ThisMonth
      2018-07-11 - Yesterday ThisWeek ThisMonth
      2018-07-12 - Today ThisWeek ThisMonth
      2018-07-13 - Tomorrow ThisWeek ThisMonth
      2018-07-15 - ThisWeek ThisMonth
      2018-07-30 - ThisMonth
      2018-08-30 - NextMonth





      function fuzzyDate(mydate)
      var fuzzy1 = ''; var fuzzy2 = ''; var fuzzy3 = '';

      var todaydt = moment(moment().format('YYYY-MM-DD'));
      var daydiff = mydate.diff(todaydt,'day');
      if (daydiff==-1)fuzzy1='Yesterday'
      if (daydiff==0)fuzzy1='Today'
      if (daydiff==1)fuzzy1='Tomorrow'

      var weekdiff = mydate.diff(todaydt,'week');
      if (weekdiff==-1)fuzzy2='LastWeek'
      if (weekdiff==0)fuzzy2='ThisWeek'
      if (weekdiff==1)fuzzy2='NextWeek'

      var monthdiff = mydate.diff(todaydt,'month');
      if (monthdiff==-1)fuzzy3='LastMonth'
      if (monthdiff==0)fuzzy3='ThisMonth'
      if (monthdiff==1)fuzzy3='NextMonth'

      return fuzzy1 + ' ' + fuzzy2 + ' ' + fuzzy3;


      console.log( '2018-06-01 - ', fuzzyDate(moment('2018-06-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-01 - ', fuzzyDate(moment('2018-07-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-07 - ', fuzzyDate(moment('2018-07-07','YYYY-MM-DD')) ) ;
      console.log( '2018-07-10 - ', fuzzyDate(moment('2018-07-10','YYYY-MM-DD')) ) ;
      console.log( '2018-07-11 - ', fuzzyDate(moment('2018-07-11','YYYY-MM-DD')) ) ;
      console.log( '2018-07-12 - ', fuzzyDate(moment('2018-07-12','YYYY-MM-DD')) ) ;
      console.log( '2018-07-13 - ', fuzzyDate(moment('2018-07-13','YYYY-MM-DD')) ) ;
      console.log( '2018-07-15 - ', fuzzyDate(moment('2018-07-15','YYYY-MM-DD')) ) ;
      console.log( '2018-07-30 - ', fuzzyDate(moment('2018-07-30','YYYY-MM-DD')) ) ;
      console.log( '2018-08-30 - ', fuzzyDate(moment('2018-08-30','YYYY-MM-DD')) ) ;

      <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>





      function fuzzyDate(mydate)
      var fuzzy1 = ''; var fuzzy2 = ''; var fuzzy3 = '';

      var todaydt = moment(moment().format('YYYY-MM-DD'));
      var daydiff = mydate.diff(todaydt,'day');
      if (daydiff==-1)fuzzy1='Yesterday'
      if (daydiff==0)fuzzy1='Today'
      if (daydiff==1)fuzzy1='Tomorrow'

      var weekdiff = mydate.diff(todaydt,'week');
      if (weekdiff==-1)fuzzy2='LastWeek'
      if (weekdiff==0)fuzzy2='ThisWeek'
      if (weekdiff==1)fuzzy2='NextWeek'

      var monthdiff = mydate.diff(todaydt,'month');
      if (monthdiff==-1)fuzzy3='LastMonth'
      if (monthdiff==0)fuzzy3='ThisMonth'
      if (monthdiff==1)fuzzy3='NextMonth'

      return fuzzy1 + ' ' + fuzzy2 + ' ' + fuzzy3;


      console.log( '2018-06-01 - ', fuzzyDate(moment('2018-06-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-01 - ', fuzzyDate(moment('2018-07-01','YYYY-MM-DD')) ) ;
      console.log( '2018-07-07 - ', fuzzyDate(moment('2018-07-07','YYYY-MM-DD')) ) ;
      console.log( '2018-07-10 - ', fuzzyDate(moment('2018-07-10','YYYY-MM-DD')) ) ;
      console.log( '2018-07-11 - ', fuzzyDate(moment('2018-07-11','YYYY-MM-DD')) ) ;
      console.log( '2018-07-12 - ', fuzzyDate(moment('2018-07-12','YYYY-MM-DD')) ) ;
      console.log( '2018-07-13 - ', fuzzyDate(moment('2018-07-13','YYYY-MM-DD')) ) ;
      console.log( '2018-07-15 - ', fuzzyDate(moment('2018-07-15','YYYY-MM-DD')) ) ;
      console.log( '2018-07-30 - ', fuzzyDate(moment('2018-07-30','YYYY-MM-DD')) ) ;
      console.log( '2018-08-30 - ', fuzzyDate(moment('2018-08-30','YYYY-MM-DD')) ) ;

      <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>






      javascript datetime






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 12 '18 at 10:20









      AdarshAdarsh

      1496




      1496





      bumped to the homepage by Community♦ 2 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community♦ 2 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          What if you have three functions that each calculate the string on its own? Therefore:



          function days_diff(daydiff) 
          if (daydiff==0) return 'Today'
          if (daydiff==1) return 'Tomorrow'
          if (daydiff==-1) return 'Yesterday'
          return null

          function weeks_diff(daydiff) {
          if (daydiff > 0 && daydiff < 7) return 'Thisweek'
          if (daydiff < 7) return 'Nextweek'
          return null
          ...


          Then you can have your one aggregate function that calls the three of them...



          Here's the much more complicated one from Rails that might provide guidance/inspiration: https://github.com/rails/rails/blob/2c97fbf6503c9199f3fe5ed06222e7226dc6fcd9/actionview/lib/action_view/helpers/date_helper.rb#L104






          share|improve this answer









          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "196"
            ;
            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/3.0/"u003ecc by-sa 3.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%2fcodereview.stackexchange.com%2fquestions%2f198352%2ffuzzy-humanize-date-using-moment-js-for-datatable-searching%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0












            $begingroup$

            What if you have three functions that each calculate the string on its own? Therefore:



            function days_diff(daydiff) 
            if (daydiff==0) return 'Today'
            if (daydiff==1) return 'Tomorrow'
            if (daydiff==-1) return 'Yesterday'
            return null

            function weeks_diff(daydiff) {
            if (daydiff > 0 && daydiff < 7) return 'Thisweek'
            if (daydiff < 7) return 'Nextweek'
            return null
            ...


            Then you can have your one aggregate function that calls the three of them...



            Here's the much more complicated one from Rails that might provide guidance/inspiration: https://github.com/rails/rails/blob/2c97fbf6503c9199f3fe5ed06222e7226dc6fcd9/actionview/lib/action_view/helpers/date_helper.rb#L104






            share|improve this answer









            $endgroup$

















              0












              $begingroup$

              What if you have three functions that each calculate the string on its own? Therefore:



              function days_diff(daydiff) 
              if (daydiff==0) return 'Today'
              if (daydiff==1) return 'Tomorrow'
              if (daydiff==-1) return 'Yesterday'
              return null

              function weeks_diff(daydiff) {
              if (daydiff > 0 && daydiff < 7) return 'Thisweek'
              if (daydiff < 7) return 'Nextweek'
              return null
              ...


              Then you can have your one aggregate function that calls the three of them...



              Here's the much more complicated one from Rails that might provide guidance/inspiration: https://github.com/rails/rails/blob/2c97fbf6503c9199f3fe5ed06222e7226dc6fcd9/actionview/lib/action_view/helpers/date_helper.rb#L104






              share|improve this answer









              $endgroup$















                0












                0








                0





                $begingroup$

                What if you have three functions that each calculate the string on its own? Therefore:



                function days_diff(daydiff) 
                if (daydiff==0) return 'Today'
                if (daydiff==1) return 'Tomorrow'
                if (daydiff==-1) return 'Yesterday'
                return null

                function weeks_diff(daydiff) {
                if (daydiff > 0 && daydiff < 7) return 'Thisweek'
                if (daydiff < 7) return 'Nextweek'
                return null
                ...


                Then you can have your one aggregate function that calls the three of them...



                Here's the much more complicated one from Rails that might provide guidance/inspiration: https://github.com/rails/rails/blob/2c97fbf6503c9199f3fe5ed06222e7226dc6fcd9/actionview/lib/action_view/helpers/date_helper.rb#L104






                share|improve this answer









                $endgroup$



                What if you have three functions that each calculate the string on its own? Therefore:



                function days_diff(daydiff) 
                if (daydiff==0) return 'Today'
                if (daydiff==1) return 'Tomorrow'
                if (daydiff==-1) return 'Yesterday'
                return null

                function weeks_diff(daydiff) {
                if (daydiff > 0 && daydiff < 7) return 'Thisweek'
                if (daydiff < 7) return 'Nextweek'
                return null
                ...


                Then you can have your one aggregate function that calls the three of them...



                Here's the much more complicated one from Rails that might provide guidance/inspiration: https://github.com/rails/rails/blob/2c97fbf6503c9199f3fe5ed06222e7226dc6fcd9/actionview/lib/action_view/helpers/date_helper.rb#L104







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 13 '18 at 4:00









                ndpndp

                1,21686




                1,21686



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Code Review 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%2fcodereview.stackexchange.com%2fquestions%2f198352%2ffuzzy-humanize-date-using-moment-js-for-datatable-searching%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

                    瀋陽號驅逐艦 目录 接收與服役 配置反潛直升機 武進三型性能升級 歷史 除役 參考資料 外部連結 导航菜单Taiwan Air Power海疆老兵-陽字號驅逐艦沿革World Navies Today: Taiwan (Republic of China)DD-839 USS POWER编

                    波兰旗帜列表 目录 国旗 军旗 其他制服部门旗帜 特别国家机构船只 参考文献 外部链接 导航菜单Polskie flagi, chorągwie, bandery... [波兰旗帜、条幅、船旗等]原始内容Ustawa z dnia 31 stycznia 1980 r. o godle, barwach i hymnie Rzeczypospolitej Polskiej oraz o pieczęciach państwowychZarządzenie Ministra Obrony Narodowej z dnia 14 grudnia 2005 r. zmieniające zarządzenie w sprawie szczegółowych zasad używania znaków Sił Zbrojnych Rzeczypospolitej Polskiej oraz ustalenia innych znaków używanych w Siłach Zbrojnych Rzeczypospolitej PolskiejZarządzenie Ministra Obrony Narodowej z dnia 29 stycznia 1996 r. w sprawie szczegółowych zasad używania znaków Sił Zbrojnych Rzeczypospolitej Polskiej oraz ustalenia innych znaków używanych w Siłach Zbrojnych Rzeczypospolitej PolskiejUstawa z dnia 19 lutego 1993 r. o znakach Sił Zbrojnych Rzeczypospolitej PolskiejHistoria Marynarki Wojennej RP [波兰海军史]Rozporządzenie Ministra Spraw Wewnętrznych i Administracji z dnia 12 kwietnia 2002 r. w sprawie wzoru flagi oraz oznakowania jednostek pływających i statków powietrznych Straży GranicznejRozporządzenie Ministra Spraw Wewnętrznych i Administracji z dnia 18 kwietnia 2005 r. w sprawie wzoru flagi oraz oznakowania jednostek pływających i statków powietrznych PolicjiRozporządzenie Ministra Infrastruktury z dnia 21 października 2005 r. w sprawie wzorów flag dla statków morskich na oznaczenie pełnionej specjalnej służby państwowej oraz okoliczności i warunków ich podnoszenia波兰旗帜波兰编

                    Indenting and Dedenting ASP code with Python