HISE Logo Forum
    • Categories
    • Register
    • Login

    Dates...

    Scheduled Pinned Locked Moved General Questions
    41 Posts 5 Posters 2.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey
      last edited by

      Yeah I think date is a good choice since that's familiar to us Javascript people :)

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      1 Reply Last reply Reply Quote 2
      • ustkU
        ustk @Christoph Hart
        last edited by ustk

        @Christoph-Hart @d-healey @Lindon Pull request made (along with a few others)

        Can't help pressing F5 in the forum...

        1 Reply Last reply Reply Quote 2
        • LindonL
          Lindon @Christoph Hart
          last edited by

          @Christoph-Hart said in Dates...:

          reg leapYears = [1992,1996,2000,2004,2008,2012,2016,2020,2024,2028,2032]; //add more if you need em
          

          Lol

          inline function isLeapYear(year) 
          {
              return year % 4 == 0;
          }
          

          except of course this is wrong.... you will need

          year % 100

          and

          year % 400

          HISE Development for hire.
          www.channelrobot.com

          Christoph HartC 1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart @Lindon
            last edited by

            @Lindon huh? This would mean that theres a leap year every 400 years so please tell everyone who has their birthday on the 29th of February that they won‘t live to see another birthday party…

            LindonL 1 Reply Last reply Reply Quote 0
            • LindonL
              Lindon @Christoph Hart
              last edited by Lindon

              @Christoph-Hart - er you should go read up on what makes a leap year, here's the code (which I couldnt be bothered writing and testing last time out - naturally lazy...):

              inline function isLeapYear(year) 
              {
                  if(year % 400 == 0 )
                  {
                         return true;
                  }else{
                      if(year % 100 == 0)
                      {
                           return false;
                      }else{
                          return year % 4 == 0;
                     }
                  }
              }
              

              So 2000 is a leap year - but 1900 isnt.

              HISE Development for hire.
              www.channelrobot.com

              Dan KorneffD 1 Reply Last reply Reply Quote 0
              • Dan KorneffD
                Dan Korneff @Lindon
                last edited by

                @Lindon here's a little script online:
                https://www.programiz.com/javascript/examples/check-leap-year

                inline function isLeapYear(year) 
                {
                     if ((0 == year % 4) && (0 != year % 100) || (0 == year % 400)) 
                     {
                          return true;
                     }  
                     else 
                     {
                          return false;
                     }
                }

                Dan Korneff - Producer / Mixer / Audio Nerd

                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @Dan Korneff
                  last edited by

                  @Dan-Korneff Why not?

                  inline function isLeapYear(year) 
                  {
                      return (0 == year % 4) && (0 != year % 100) || (0 == year % 400));
                  }
                  

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  Dan KorneffD LindonL 2 Replies Last reply Reply Quote 0
                  • Dan KorneffD
                    Dan Korneff @d.healey
                    last edited by

                    @d-healey That works too, and you save 4 lines of code.

                    Dan Korneff - Producer / Mixer / Audio Nerd

                    LindonL 1 Reply Last reply Reply Quote 0
                    • ustkU
                      ustk
                      last edited by

                      00b53da02349bc224f3f858a07c29073.jpg

                      Can't help pressing F5 in the forum...

                      1 Reply Last reply Reply Quote 1
                      • LindonL
                        Lindon @Dan Korneff
                        last edited by

                        @Dan-Korneff said in Dates...:

                        @d-healey That works too, and you save 4 lines of code.

                        if we are interested in saving lines of code my original version is precisely 1 line.... :-)

                        HISE Development for hire.
                        www.channelrobot.com

                        Dan KorneffD 1 Reply Last reply Reply Quote 1
                        • Dan KorneffD
                          Dan Korneff @Lindon
                          last edited by

                          @Lindon I only skimmed the last few posts 💩

                          Dan Korneff - Producer / Mixer / Audio Nerd

                          1 Reply Last reply Reply Quote 0
                          • Christoph HartC
                            Christoph Hart
                            last edited by

                            if we are interested in saving lines of code my original version is precisely 1 line....

                            But you need to ship an update in 2036 and we're all in here for the long run...

                            LindonL 1 Reply Last reply Reply Quote 2
                            • LindonL
                              Lindon @Christoph Hart
                              last edited by

                              @Christoph-Hart said in Dates...:

                              if we are interested in saving lines of code my original version is precisely 1 line....

                              But you need to ship an update in 2036 and we're all in here for the long run...

                              well you have me there...

                              HISE Development for hire.
                              www.channelrobot.com

                              1 Reply Last reply Reply Quote 0
                              • LindonL
                                Lindon @d.healey
                                last edited by Lindon

                                @d-healey said in Dates...:

                                @Dan-Korneff Why not?

                                inline function isLeapYear(year) 
                                {
                                    return (0 == year % 4) && (0 != year % 100) || (0 == year % 400));
                                }
                                

                                except when you try this it always returns true....so it doenst work.

                                -- oh hang on I spot a typeo in my implementation....

                                HISE Development for hire.
                                www.channelrobot.com

                                LindonL 1 Reply Last reply Reply Quote 0
                                • LindonL
                                  Lindon @Lindon
                                  last edited by Lindon

                                  Okay so whilst we await @ustk 's push here's a fix using just HISE:

                                  function isLeapYear(aYear)
                                  {
                                  	return ((0 == aYear % 4) && (0 != aYear % 100) || (0 == aYear % 400));
                                  }
                                  
                                  function daysFrom2000(aYear,aMonth,aDay)
                                  {
                                  	reg calcYear = 2000;
                                  	reg totalDays = 0;
                                  	reg leap = 0;
                                  	reg monthAmounts = [31,28,31,30,31,30,31,31,30,31,30,31];
                                  	if(aYear < calcYear)
                                  		return -1;
                                  		
                                  	if(aMonth > 2 && isLeapYear(aYear))
                                  		leap = 1;
                                  	totalDays = aDay + leap;
                                  	for(i = 0; i< aMonth-1; i++)
                                  	{
                                  		totalDays = totalDays + monthAmounts[i];
                                  	};
                                  		
                                  		
                                  	while(calcYear < aYear)
                                  	{
                                  		totalDays = totalDays + 365 + isLeapYear(calcYear);
                                  		calcYear++;
                                  	};
                                  	
                                  	return totalDays;
                                  }
                                  
                                  Console.print(daysFrom2000(2023,01,01));
                                  

                                  Obviously just doing days not microseconds

                                  HISE Development for hire.
                                  www.channelrobot.com

                                  ustkU 1 Reply Last reply Reply Quote 0
                                  • ustkU
                                    ustk @Lindon
                                    last edited by

                                    @Lindon the push’s been made, Christoph should merge soon

                                    Can't help pressing F5 in the forum...

                                    d.healeyD 1 Reply Last reply Reply Quote 1
                                    • d.healeyD
                                      d.healey @ustk
                                      last edited by

                                      @ustk Already has, no?

                                      Link Preview Image
                                      Commits · christophhart/HISE

                                      The open source framework for sample based instruments - Commits · christophhart/HISE

                                      favicon

                                      GitHub (github.com)

                                      Libre Wave - Freedom respecting instruments and effects
                                      My Patreon - HISE tutorials
                                      YouTube Channel - Public HISE tutorials

                                      ustkU 1 Reply Last reply Reply Quote 0
                                      • ustkU
                                        ustk @d.healey
                                        last edited by

                                        @d-healey Oh yes my mistake, was waiting for the others...

                                        Can't help pressing F5 in the forum...

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post

                                        11

                                        Online

                                        1.8k

                                        Users

                                        12.2k

                                        Topics

                                        106.3k

                                        Posts