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 3937454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:04:14+00:00 2026-05-20T00:04:14+00:00

I wrote the CS 462 Office Hours app over the past two days. The

  • 0

I wrote the CS 462 Office Hours app over the past two days. The most recent iteration tells the user when the next office hour time block will be. Right now, it just formats it as “Thursday (February 3) at 3 PM.” I’d like it to be a little smarter, though, and say something like “this afternoon at 3 PM” or “tomorrow at 10 AM”.

This is similar to Twitter’s relative timestamps on tweets (it says “3 minutes ago” or “23 hours ago;” beyond that it lists the date). In my case, though, it will be the opposite, since we’re dealing with future times.

Basically, it needs to be smart enough to know that an event is today or tomorrow. Beyond that, I just want to display the date and day of the week.

Is there a way to do this with KRL? Do I just need to use logic like this and write a function (or module)?

  • 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-20T00:04:14+00:00Added an answer on May 20, 2026 at 12:04 am

    These are the functions I have:

    // First define some constants to measuring relative time
    now = time:now({"tz": "America/Denver"});
    midnight = time:new("23:59:59.000-07:00");
    tomorrow_midnight = time:add(midnight, {"days": 1});
    yesterday_midnight = time:add(midnight, {"days": -1});
    
    // Functions for calculating relative time
    relativefuturedate = function(d){
      ispast(d) => "today (past) at " + justtime(d)
        | istoday(d) => "today at " + justtime(d)
        | istomorrow(d) => "tomorrow at " + justtime(d)
        | datetime(d);
    };
    
    istoday = function(d){
      d > now && d <= midnight;
    };
    
    istomorrow = function(d){
      not istoday(d) && d <= tomorrow_midnight;
    };
    
    ispast = function(d){
      d < now;
    };
    
    isfuture = function(d){
      d > now;
    };
    
    justtime = function(d){
      time:strftime(d, "%l:%M %p");
    };
    
    datetime = function(d){
      time:strftime(d, "%A (%B %e) at %l:%M %p");
    };
    

    This should do the trick. Right now I’m testing it with this rule:

    rule first_rule {
      select when pageview ".*"
      pre {
        today_9 = time:new("2011-02-09T09:00:00.000-07:00");
        today_12 = time:new("2011-02-09T12:00:00.000-07:00");
        today_4  = time:new("2011-02-09T16:00:00.000-07:00");
        tomorrow_9 = time:new("2011-02-10T09:00:00.000-07:00");
        tomorrow_4 = time:new("2011-02-10T16:00:00.000-07:00");
        nextday_9 = time:new("2011-02-11T09:00:00.000-07:00");
    
        relative_now = relativefuturedate(now);
        relative_today_9 = relativefuturedate(today_9);
        relative_today_12 = relativefuturedate(today_12);
        relative_today_4 = relativefuturedate(today_4);
        relative_tomorrow_9 = relativefuturedate(tomorrow_9);
        relative_tomorrow_4 = relativefuturedate(tomorrow_4);
        relative_nextday_9 = relativefuturedate(nextday_9);
    
        message = <<
          Now: #{relative_now}<br />
          Today at 9: #{relative_today_9}<br />
          Today at 12: #{relative_today_12}<br />
          Today at 4: #{relative_today_4}<br />
          Tomorrow at 9: #{relative_tomorrow_9}<br />
          Tomorrow at 4: #{relative_tomorrow_4}<br />
          Day after tomorrow at 9: #{relative_nextday_9}<br />
        >>;
      }
      notify("Time calculations:", message) with sticky=true;
    }
    

    However, that doesn’t seem to be working yet. I get this output:

    Incorrect relative times

    Can anyone see what’s wrong?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple web app to let user input data as they walk
Wrote the following two functions for storing and retrieving any Python (built-in or user-defined)
I wrote an little app in C# to keep track of customers and jobs
I wrote two shell scripts a.sh and b.sh . In a.sh and b.sh I
I wrote this code app = Tk() app.title('Myapp') app.geometry('260x100+50+50') labelText =StringVar() labelText.set('Insert the version
I wrote a webpage where a user can enter a log entry that is
I wrote a batch to check and deploy the rails app from github, the
So I wrote an app for Mac. Everything works properly on my Mac laptop
Wrote a small app that accesses a bunch of search websites and puts the
Wrote a quick Java proggy to spawn 10 threads with each priority and calculate

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.