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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:44:39+00:00 2026-05-18T09:44:39+00:00

I want to use a bunch of functions that were written in Javascript in

  • 0

I want to use a bunch of functions that were written in Javascript in my Obj-C app. I made a header file and got the first one converted, but got stuck on the second. Here’s what I started with and what I’ve done so far that doesn’t work…

function calcDayOfWeek(juld)
    {
        var A = (juld + 1.5) % 7;
        var DOW =     (A==0)?"Sunday":(A==1)?"Monday":(A==2)?"Tuesday":(A==3)?"Wednesday":(A==4)?"Thursday":(A==5)?"Friday":"Saturday";
        return DOW;
    }

…and my attempt:

NSString calcDayOfWeek(float julianDay)
{
    float A = (julianDay + 1.5) % 7;
    NSString DOW = (A==0)?"Sunday":(A==1)?"Monday":(A==2)?"Tuesday":(A==3)?"Wednesday":(A==4)?"Thursday":(A==5)?"Friday":"Saturday";
    return DOW;
}

It should return a string with the day of the week based on the input of a Julian Day Number.

EDIT: Per Yuji’s answer, this is what worked…

NSString* calculateDayOfWeek(float julianDay) {
    int a = fmod(julianDay + 1.5, 7);
    NSString* dayOfWeek = (a==0)?@"Sunday":(a==1)?@"Monday":(a==2)?@"Tuesday":(a==3)?@"Wednesday":(a==4)?@"Thursday":(a==5)?@"Friday":@"Saturday";
    return dayOfWeek;
}
  • 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-18T09:44:39+00:00Added an answer on May 18, 2026 at 9:44 am

    You first need to learn the syntax and the grammar of Objective-C.
    The function would be

    NSString* calcDayOfWeek(float julianDay)
    {
         int A = ((int)(julianDay + 1.5)) % 7;
         NSString* DOW = (A==0)?@"Sunday":(A==1)?@"Monday":(A==2)?@"Tuesday":(A==3)?@"Wednesday":(A==4)?@"Thursday":(A==5)?@"Friday":@"Saturday";
         return DOW;
    }
    
    • In Objective-C, variables for objects are pointers, not the object itself. You need NSString* instead of NSString.
    • @"..." is the Objective-C string which is an object. "..." is a C-string, which is just char*.
    • I recommend against using == for a float. What happens if two floats differ by .00000001? Well, % operator automatically gives you integer, but I still don’t like it.

    However, you shouldn’t re-invent the wheel. Cocoa has an API that does the calendar conversion for you. See Date and Time Programming Topics.

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

Sidebar

Related Questions

I am attempting to access some functions in file that's one directory below the
I'm trying to debug a bunch of functions that redirect the user. I want
I have a header ( .h ) file that I've defined a bunch of
I have some different Map/Reduces functions that I use in my project. But one
I want to use a bunch of local variables defined in a function, outside
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want use a single php file to handle all of my voting requests.
I have a bunch of javascript functions which depend on some server-side constants (such
I have a bunch of very simple functions. Each function has one input and
I have a bunch of forms that have various input elements. I want to

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.