Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1012355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:56:02+00:00 2026-05-16T09:56:02+00:00

I have a frequency and a time range with which the frequency has to

  • 0

I have a frequency and a time range with which the frequency has to be executed.
For eg, if the current time is 2AM and frequency is 360 mins, it has to assume that
since it just passed midnight , the task should execute at 360 mins after 12 means 6 AM

the current time is server start time from midnight.
so if server starts at 5AM and frequncy is 360 the task should be run at 6AM

but if the task is 5am and frequency is 240, since it has already passed 240 mins from midnight
the next run should be at 8AM

If the server starts at 10AM and frequency is 300 then starting from midnight one run is elapsed at 5AM ans next as calculated at 10AM so will start immediately at 10AM

The time ranges are divded into 4 quarters, 12AM to 6AM to 12PM ,12PM to 6PM and 6PM to 12AM next day
This is the code below which is working fine for 240 and 360 frequency but going wrong when its 60 frequency.
Some values which are provided below:

 stNow----serverTime
sElapsed ---time elapsed from midnight
currFreq ----frequecy 
    protected int _getInitWorkerTime()
    {
         int vRun=0;
         STime stNow= new STime(PWMSystem.newDate());
         int currFreq = _findAlertFrequency()/60;
         int sElapsed =Constants.MINUTES_PER_DAY-stNow.elapsedMinutes(STime.midnight);
         _log.error("now time as 24------"+stNow.getHourNo24());
         _log.error("now currFreq------"+currFreq);
         _log.error("now sElapsed-----"+sElapsed);
         if(sElapsed == 1440)
             sElapsed=0;
         if(stNow.getHourNo24()>=0  && stNow.getHourNo24()<=6)
         {
             _log.error("now time as 24-inside cond-1-----"+stNow.getHourNo24());
                 if(currFreq>sElapsed)
                     vRun= currFreq-sElapsed;
                 else
                     vRun= -(currFreq-sElapsed);
         }
         if(stNow.getHourNo24()>6 && stNow.getHourNo24()<=12)
         {
             _log.error("now time as 24-inside cond-2-----"+stNow.getHourNo24());
             if(currFreq>sElapsed)
                  vRun=360-(currFreq-sElapsed);
              else
                  vRun=360-(-(currFreq-sElapsed));
         }
         if(stNow.getHourNo24()>12 && stNow.getHourNo24()<=18)
         {
             _log.error("now time as 24-inside cond-3-----"+stNow.getHourNo24());
             if(currFreq>sElapsed)
                  vRun=720-(currFreq-sElapsed);
              else
                  vRun=720-(-(currFreq-sElapsed));
         }
         if(stNow.getHourNo24()>18 && (stNow.getHourNo24()<=24 ||stNow.getHourNo24()<=0))
         {
             _log.error("now time as 24-inside cond-4-----"+stNow.getHourNo24());
             if(currFreq>sElapsed)
                  vRun=1080-(currFreq-sElapsed);
              else
                  vRun=1080-(-(currFreq-sElapsed));
         }
            // vRun=_MAX_FREQUENCY_DELAY_IN_SEC+ sElapsed*60+_findAlertFrequency()+_BOOT_DELAY_SECONDS_START;*/
        //vRun=stNow.elapsedMinutes(STime.midnight)*60+_findAlertFrequency()+_BOOT_DELAY_SECONDS_START;
        return (vRun*60 + _BOOT_DELAY_SECONDS_START);       
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:56:03+00:00Added an answer on May 16, 2026 at 9:56 am

    I found out to be..

    protected int _getInitWorkerTime()
    {   
            int vRun = 0;
            STime stNow = new STime(PWMSystem.newDate());
            int currFreq = _findAlertFrequency() / Constants.SECONDS_PER_MINUTE;
            int sElapsed = Constants.MINUTES_PER_DAY- stNow.elapsedMinutes(STime.midnight);
            int runsCompleted = sElapsed / currFreq;
            int remainLeft = (runsCompleted + 1) * currFreq;
    
    
                    if (remainLeft > sElapsed)
                        vRun = remainLeft - sElapsed;
                    else
                        vRun = sElapsed - remainLeft;
    
    
    return (vRun * 60 + _BOOT_DELAY_SECONDS_START);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.