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

                    名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

                    Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

                    Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar