I'm working on a Universal windows store app and I want to add a simple calendar so that users can add birthdays of their friends and save them and some other stuff. Is there any simple way to do this?
PS: Using Visual Studio 2013
What I do understand about Calendars, is there are fourteen of them in total that are possible - seven for each day of the week a normal year begins on, and seven more for leap years. You may have to create all fourteen and put them in somehow. There is instead a formula for working out what day of the year anyone was born on by their date of birth, and formulae can be programmed into r or other programmes using perhaps the for loop, or if command. This formula is :
{4(d+y)+x-4c}/28, where d is what number day of the year it is - so Jan 1st, d=1, and so on, but for Leap Years it gets different from Feb 29, y is the year in question, x the closest year before y divisible by four, and c an era constant. For modern dates, c=0, so no worries, but if You go back before September, 1752, it changes, as this is when the British went from the Julian to the Gregorian, while in Catholic Europe it was October, 1582, but these are only a concern if You are into such historical dates. For those, c=1, but may have different values much earlier - if You want to know more, reply to this, and I will get out what I have written on it.
For example, if one was born on 17th May, 1979, you would go :
{4(137+1979)+1976-4 times zero}/28, which equals 372 plus six sevenths - you ignore the whole number, and look at how many sevenths there are. Six means Thursday, and thus the 17th May, 1979 was a Thursday. This is it in short - for more details, if this interests, feel free.
The simple way is in use third-party controls like Telerik Calendar or something free like this one.
Related
I need to alternate between 2 tasks every day, and I need a simple algorithm to know which task I need to do.
I need to be able to run this algorithm by head, using simple general knowledge (like day of week, day of month, etc), and it must not rely of which task has been done the previous day (because I have a crappy memory).
I have tried checking for parity in a combination of day of week / day of month / # of month, etc, but couldn't find a suitable system: day of week have 2 consecutive odd numbers, same goes for day of month every so often.
I am afraid that this is impossible: if you can't remember what you did the day before, any other procedure will require more mnemonic effort.
remember what you did on January first (or another date),
remember the parities of the cumulated months: oeoeoeooeoe or ooeoeoeeoeo for a leap year,
add the cumulated parity of the month before* to the parity of the day,
add that to the parity of the first task.
E.g. if A on January 1st 2022, then on March 17, 2022: e + o = o gives B.
*In January, use even.
You can also state the month parity rule as: until August inclusive, use the co-parity of the month number; then use the parity. But for a leap year, change that parity after February (excluded).
I need to be able to run this algorithm by head
So, you don't need to take help of Computer science. You can use cognitive human ability to map a thing to another thing.
Note: This need not make sense to everybody though, if you are thinking out of the box.
Map task 1 as God's day.
Map task 2 as Devil's day in your brain.
This should be simple just like day and night.
Now, remember that devil's evil karma is always burnt by God the next day and that devil never learns his lesson. So this way, alternating would be easy.
Friends Episode snippet on Youtube
Just count the number of days in between your date and a given "zero" one...then use parity.
Take number of seconds (or milli, or whatever) since EPOCH (common zero for date and time), divide (integer division) by 60x60x24 (or 1000x60x60x24, or what is appropriate), you then get the number of days since EPOCH.
----EDIT----
Example: Got 1653910695 seconds since EPOCH (at the time of my experience). Dividing it by 60x60x24 give 19142 days. To morrow it will give 19143, etc.
<?php
$day = Date('j');
$previous_day = date('j', strtotime("-1 days"));
if($day%2==0 OR $previous_day%2!=0)
echo "Task 1";
}else{
echo "Task 2";
}
?>
I want to find the "same day of the week last year". I'm sure that question is going to have litany of subtleties that I've not yet begun to think about but I believe this question is likely a common one.
Here are a few use cases where someone might want to use this algorithm:
Example 1
I'm a manager at a Walmart. I want to find out how many kitten mittens I sold the same day last year. I know that kitten mitten purchases are closely related to day of week and week of year. Thus I want to know "how many kitten mittens do I need to stock for tomorrow "the first Tuesday in January".
Example 2
I'm a nurse at a hospital. I want to determine how many patients are coming in each day next week so I can better align staff with bed demand. I know that there are strong trends with how many patients arrive at the hospital by day of week, and I want to see how many patients we had "the third Friday of November" last year.
I feel like this is a standard problem people have to have come across. Is there a best approach to this challenge? I can imagine issues where in the current year there are five Fridays in say November, and the last year there were only four, so you would not be able to report in that manner.
What is a language-independent (although if you're curious, I would be implementing this in M) approach to this algorithm?
There is a function that returns week day number. In Cache it's $zd(date,10), in GT.M there should be similar one. All you need to do is to correct your date using this function:
set currentDate=+$h
set currentWeekDay=$zd(currentDate,10)
set dateAboutYearAgo=currentDate-365
set weekDayAboutYearAgo=$zd(dateAboutYearAgo,10)
set sameWeekDayAboutYearAgo=dateAboutYearAgo-weekDayAboutYearAgo+currentWeekDay
So basically I've been given a question to this language which I've been reading the documentation on since early last night. I don't know a thing yet so I figured I'd give this website a try.
Basically what question here is this:
I've been given several structures for calendar dates and an interval in scheme:
(define-struct cal (month day))
(define-struct interval (start end))
However I'm being asked to check if 2 different intervals overlap each other. An example to this:
If I have dates March 12th - March 14th in my first interval,
but in my second interval I have the dates March 13th - March 2th
(overlap? int1 int2) would return true.
However if I have dates March 12th - March 14th in my first interval,
but I have March 15th - March 18th in my second interval
(overlap? int1 int2) would return false.
I don't know where to start with this. If anyone can clear this up for me so I can finish this problem I would be grateful. Thanks a lot!
A good approach in general when writing programs is to break a problem down into more manageable ones. So, before tackling the problem of comparing two intervals, try tackling the simpler problem of comparing two calendar dates. Given two dates a and b, try to write a function that returns true if a is before b, and false otherwise. So,
; date1 is January 5, date2 is February 6
(before? date1 date2) ; returns true
; date1 is January 5, date2 is January 2
(before? date1 date2) ; return false
Next, think about how you might use before? to construct overlap?. In particular, consider this: if two intervals do not overlap, then the end date of one comes before the start date of the other.
Finally, consider the edge cases - what do you want your program to do if given, for example, (January 4 to March 6) and (March 6 to December 3) ? Do these intervals overlap or not?
Happy coding!
PS - if you need more help, don't be afraid to ask. I'm being deliberately vague because I thought that giving you hints would be better than just plopping a solution down in front of you - that way you wouldn't learn anything.
To add to Ord's excellent advice, if you're looking for more basic information: what does define-struct mean? How do I write a function that uses dates?--then I would suggest you take a look at the (free, online) textbook How To Design Programs, version 2e. It looks like you're interested in Section 2.5, "Adding Structure", but it may be hard to understand this section without reading earlier ones, as well.
Good luck!
From this online calculator: http://homer.freeshell.org/dd.cgi using its data I've successfully written a working version, however its data is limited to years 1500 to 2600. I want to modify (and make a better one) so that I can calculate for any year > 2600.
Referring to Table X, is there actually a formula to calculate the base doomsday for all base centuries (above 2600)?
I've tried working it out myself by putting centuries higher than this e.g. 2700 gave me a base doomsday of '00', 2800 gave '02;, 2900 back to '00' again...
Help appreciated.
As I understand it, that page's “Base Doomsday” is just an offset to allow for the four-hundred-year cycle of leap day calculations. So, you can extend it indefinitely into the future simply by adding blocks of four centuries.
Are there any other calculators out there that do this?
Two common methods for calculating the day of the week
given a date are Doomsday, which you are using,
and Zeller's Congruence
www.merlyn.demon.co.uk provides
some really interesting information on date/time calculations, various calendar
systems and significant dates as they relate to calendar/date calculations.
The calculator at this link http://homer.freeshell.org/dd.cgi is the best in terms of explaining doomsday algorithm cleanly and clearly for human, with one little caveat.
If you input 2/29/1900, it would say it's a Thursday. Well, there is no 2/29/1900, because it's not a leap year.
Of course if your input 1/35/2016, it would "garbage-in-garbage-out" for you as well.
Imagine there are only 364 days in a year, then the day of week for each date will never change year after year, because mod(364,7)==0.
But we have 365 days a year, so the day steps forward 1 each year, that's where the second term mod(year, 7) comes from.
In addition, every 4 year, there is a leap year, which contributes to the last term mod(year, 4).
But every 100 years, you subtract a leap year, and every 400 years, you add one leap year. That's where the first term "3,2,0,5" comes in.
You see, it's all because of this leap year, and mod(365,7)==1 business.
7/11, 5to9 helps to remember table Z greatly.
I have the following question, and what I'm most confused on, is how to do the logic for determining if a check is one month late or not.
Question is:
"Write pseudocode for a program that calculates the service charge of a customer owes for writing a bad check. The program accepts a customer's name, the date the check was written (year, month and day), the current date (year, month and day), and the amount of the check in dollars and cents. The program continues until an eof value is encountered. The service charge is $20 plus 2 percent of the amount of the check, plus $5 for every month that has passed since the check was written. A check is one month late as soon as a new month starts-so a bad check written on September 30 is one month overdue on October 1."
So far what I have write now is:
Start
string Name
num AmountOwed
num DateCheckWritten
num CurrentDate
num CheckAmount
get Name, DateCheckWritten, CurrentDate, CheckAmount
while eof
Since you don't have to deal with days, the algorithm is very straightforward:
MonthsLate = (CurrentDate.Year - DateCheckWritten.Year) * 12
+ (CurrentDate.Month - DateCheckWritten.Month)
Good luck with the rest of the problem!
I'm not sure where your problem lies, but I think you have two issues to deal with:
What is the definition of late?
How many months late is this check?
So in my pseudocode, I would have a step that determines how late a check is, and then another step to calculate the fee. Inside the first step, you could just subtract the days and divide. But the directions say as soon as a new month comes along, it is one month late. So all you really have to do is subtract months.
Not sure what else you are asking, but it appears you are asking for guidance, not code. Hope this helps.
I'm going to assume this is homework, and as such I'll try to just point you in the right direction.
If you assign numbers to each month (Jan = 1, Feb = 2, etc) then the number of months between two dates is easy to determine - how many months are there between September (= 9) and May (= 5)?
The other thing to take into account is the year - for each year the check is late, you'll also have to add another twelve months. This works the same as for months.
Need any extra detail, feel free to let me know.
Simplify, hit the main points and then break it down more and more, write it how you would tell your grandma it worked.
you might start out with something like
Start
While there are more bad checks
get the service charge
add the service charge to the account
record the updates
get the service charge
charge starts at $20
add to the charge $5 multiplied by number of months