How Do I Calculate Day Names From Parameters?

I'm creating my own Time System plugin and I'm trying to figure how to calculate the current day name based on the several factors (namely the plugin parameters). The attached screenshot is an example if the parameters read:

Days Per Month: 31
Months Per Year: 12 (only showing 3 though to keep it simple/smaller)
Day Names: ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]

So how do I get a function to return "Thu" based on the 1st of Month 2 in the example? (Or if the Days per Month were to be changed to 28), how to return "Mon" based on the 1st of Month 2, etc.

- To anyone before commenting "Why not use an already made time system plugin?"
A: While great in their own way, I am designing my own plugin to both tailor it to my needs, and I'm learning as I develop it. Enhancing it when/where I can (like I'm just now getting into the clock sprite side of it) and so the other systems don't really have what I need. So that's where I'm at with that.
You could use the Date.getDay() method, which returns 0 for sunday, up to 6 for saturday. So, you could simply create an array with the name for the day names:

var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var d = new Date(dateString);
var dayName = days[d.getDay()];
Here dateString is the string you received from the third party API.

Alternatively, if you want the first 3 letters of the day name, you could use the Date object's built-in toString method:

var d = new Date(dateString);
var dayName = d.toString().split(' ')[0];
That will take the first word in the d.toString() output, which will be the 3-letter day name.
Variable 1 = Amount of Total Days passed.
Variable 1 mod 7
If Variable 1 = 0
Show Text: Today is Monday
If Variable 1 = 1
Show Text: Today is Tuesday
If Variable 1 = 2
Show Text: Today is Wednesday
If Variable 1 = 3
Show Text: Today is Thursday
If Variable 1 = 4
Show Text: Today is Friday
If Variable 1 = 5
Show Text: Today is Saturday
If Variable 1 = 6
Show Text: Today is Sunday

Edit:
Example:
Day 14 mod 7 = 0 ; 0 equals Monday
Day 16 mod 7 = 2 ; 2 equals Wednesday
Day 86 mod 7 = 2 ; 2 equals Wednesday
...
Got it to work, through this mess (it was sometimes returning an index greater than 7, and kept returning the day as "undefined", but this fixed everything:
You could use the Date.getDay() method, which returns 0 for sunday, up to 6 for saturday. So, you could simply create an array with the name for the day names:

var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var d = new Date(dateString);
var dayName = days[d.getDay()];
Here dateString is the string you received from the third party API.

Alternatively, if you want the first 3 letters of the day name, you could use the Date object's built-in toString method:

var d = new Date(dateString);
var dayName = d.toString().split(' ')[0];
That will take the first word in the d.toString() output, which will be the 3-letter day name.
That's a great example, but it relates to real time and as such probably isn't what the original poster is looking for.

Got it to work, through this mess (it was sometimes returning an index greater than 7, and kept returning the day as "undefined", but this fixed everything:
That code looks incorrect. If you take "day of month" mod "days per week", then every month is going to begin on a Monday.

To get the "day of week", you need to take "day of year" mod "days per week".

(Although even that is wrong for the Gregorian calendar, as it makes every year start on a Monday; but it might be close enough for a game? If it's not close enough you can take "days since game started" mod "day of year".)
That's a great example, but it relates to real time and as such probably isn't what the original poster is looking for.

That code looks incorrect. If you take "day of month" mod "days per week", then every month is going to begin on a Monday.

To get the "day of week", you need to take "day of year" mod "days per week".

(Although even that is wrong for the Gregorian calendar, as it makes every year start on a Monday; but it might be close enough for a game? If it's not close enough you can take "days since game started" mod "day of year".)

It's correct. Tested it myself, and it works. ((Although I did notice my example calendar is incorrect since I skipped day 10 on Month 2...))

Days Per Month: 31
Day Names: ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]

The code:

JavaScript:
// Getting day 28 on Month 1 (of the above calendar)
Game_TimeSystem.prototype.weekDayName = function() {
    var week = $.dayNames.length; // 7 days.. (to die)
    var mod  = $.dayPerMo % week; // 31 % 7 = 3
    var startDay = (this._timeMonth - 1) * mod; // (1-1) * 0 = 0
    var index = ((this._timeDay - 1) % week) + startDay; // (28-1) % 7 = 6
    while (index >= week) index -= week; // no adjustments
    return $.dayNames[index]; // should return "Sun" (index 6)
};

Edit: Then to show you the formula works ongoing (Day 9 of Month 2 above - since I screwed up Day 10)

JavaScript:
Game_TimeSystem.prototype.weekDayName = function() {
    var week = $.dayNames.length; // 7 (still)
    var mod  = $.dayPerMo % week; // 3
    var startDay = (this._timeMonth - 1) * mod; // (2-1) * 3 = 3
    var index = ((this._timeDay - 1) % week) + startDay; //((9-1) % 7) + 3 = 4
    while (index >= week) index -= week; // no adjustments
    return $.dayNames[index]; // should return "Fri" (index 4)
};
Hmm, okay, maybe it's correct, but I think it's more complicated than it needs to be. I think something like this would still work and be both simpler and faster:

JavaScript:
return ((this._timeMonth * $.dayPerMo) + this._timeDay) % $.dayNames.length;

Untested, could be off by one or something. Also assumes that month 1 starts on a Monday. Basically the idea of that code is to calculate how many days have passed since the start of the year and then take that modulo 7. Of course, you could write that in several statements to make it even clearer, if you wanted to.

Or you could just stick with what you have, since it sounds like it works for you.
Following from the discussion on discord, I revised my day of month method from

Code:
function getDayOfMonth(day) {
  return day % Days_Per_Month;;
}

to

Code:
function getDayOfMonth(day) {
  var res = day % Days_Per_Month;
  if (res == 0) {
    res = Days_Per_Month
  }
  return res;
}

Which is still quite ugly, but I couldn't figure out how to deal with the case when the number of days divides evenly into it.
Iam no Scripter, but iam curious why you are Focussing on the Month?

He wants the Weekday Name, isnt all that needed the total amount of Days passed?
Bringing the Month into this seems unnecessary and complicates this even more. Or am i wrong?

OP does your Time System have a Variable that stores the Total amount of passed Time?
The standard Game Time for example is in "Seconds"
Total Seconds devided through 86400 (Seconds a Day got) = Total Days.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-calculate-day-names-from-parameters.125088/