I am looking for a fiscal calendar class rather than having to roll my own.
So far I haven’t had much luck in finding something that suits me.
I am relatively new to the idea of a fiscal calendar and to programming for that matter.
The dates that my company uses for its fiscal reporting are strange to me, I can’t seem to make any sense of it and I am suspecting that the financial department uses tea leaves and chicken entrails to create the calendar. I have asked, several times but no answer.
Details :
Our fiscal year starts on July 1 every year. Our current year is named FY11.
The dates of our fiscal year are as follows:
Jul 30-Jun-10 to 27-Jul-10
Aug 28-Jul-10 to 28-Aug-10
Sep 29-Aug-10 to 27-Sep-10
Oct 28-Sep-10 to 26-Oct-10
Nov 27-Oct-10 to 27-Nov-10
Dec 28-Nov-10 to 28-Dec-10
Jan 29-Dec-10 to 26-Jan-11
Feb 27-Jan-11 to 23-Feb-11
Mar 24-Feb-11 to 28-Mar-11
Apr 29-Mar-11 to 26-Apr-11
May 27-Apr-11 to 28-May-11
Jun 29-May-11 to 29-Jun-11
The next year will be different . I have a number of years into the future.
Anyways, I have pretty much given up on trying to find example code that I could work from and I am asking this forum for any advice that you could give a beginner programmer on what approach you would take to creating a fiscal_calendar class.
I suspect that I will never find the true rational behind the financial departments financial calendar creation methodology and will be stuck with spreadsheets detailing the gregorian to fiscal comparison.
Thanks for any insight you can provide
Related
I'm currently trying to display a datetime in the format of the local culture of the user.
As an example, an user from the US will see a date as 20 June 2020 05.50 PM where as an user from germany will see the date as 20 Juni 2020, 17:50.
My issue is, that e.g for the german case, I'd like to have a Uhr added at the end, so it will be 20 Juni 2020, 17:50 Uhr as explained in this related question.
Is there any way to achieve that in .NET as well? In theory I could just keep checking the culture and add Uhr if it's a german one, but I assume that there are other cultures as well with a similar suffix.
Very basic question.
When MSFT creates a migration ID, it prefixes the name of the migration with a timestamp.
For Example.
201802132140243_initial.
Can someone explain how to read that?
year = 2018
month = 02
day = 13
and then?
2140243?
I'm pretty sure that it is the time of day in hhmmss format, maybe to the tenth of a second. If it doesn't fit with the time when you created the migration, maybe it is in UTC time and you live in a different hour band than UTC (not sure about this because I live close to UTC time, so I have never paid attention to see if there is a big difference). So summing up, it should mean 21 hours, 40 minutes, 24.3 seconds
I have a dateTimePicker created, and I only want to select month and year. So, I put the following code:
dateTimePicker2.Format = DateTimePickerFormat.Custom;
dateTimePicker2.CustomFormat = "MM yyyy";
dateTimePicker2.ShowUpDown = true;
Whenever I scroll with the arrow through the months, once it gets to February, the value is blank, instead of February.
I also tried customformats MMM and MMMM, but retain the same problem. I tried different years, but every year does not show February. I also tried to put a new datetimepicker, but continue having the same problem.
I can only select, without showUpDown = true, in the calendar, but still not with arrow up/down. It works without custom format, but I do not want to see the day, I only want to select month and year.
I'm using Visual Studio 2010 Ultimate (10.0.40219.1.SP1). .NET Framework 4.0.30319 SP1.
When the user select value by the up-down buttons or arrow keys, the DateTimePicker won't change the value of the element which is not included in its custom format.
I guess your dateTimePicker2 initially has the value of Now whose day of month is 29 or 30, hence the error on February.
I recommend you set 1 to dateTimePicker2.Value.Day beforehand.
Well, the problem really has to do with the fact that 02/29 will only be valid date on leap years. To prove this, scroll to 2012 and then scroll to 02. You'll have to implement code to catch an invalid value and either notify a user or move to 03/01.
DateTime has a method that lets you find out if a year is a leap year, so that you wouldn't have to jump through hoops: DateTime.IsLeapYear(year), where year is an int.
Here's a short list of leap years for your reference:
Leap Years (1800 - 2400)
1804 1808 1812 1816 1820 1824 1828 1832 1836 1840 1844 1848 1852 1856
1860 1864 1868 1872 1876 1880 1884 1888 1892 1896 1904 1908 1912 1916
1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972
1976 1980 1984 1988 1992 1996 2000 2004 2008 2012 2016 2020 2024 2028
2032 2036 2040 2044 2048 2052 2056 2060 2064 2068 2072 2076 2080 2084
2088 2092 2096 2104 2108 2112 2116 2120 2124 2128 2132 2136 2140 2144
2148 2152 2156 2160 2164 2168 2172 2176 2180 2184 2188 2192 2196 2204
2208 2212 2216 2220 2224 2228 2232 2236 2240 2244 2248 2252 2256 2260
2264 2268 2272 2276 2280 2284 2288 2292 2296 2304 2308 2312 2316 2320
2324 2328 2332 2336 2340 2344 2348 2352 2356 2360 2364 2368 2372 2376
2380 2384 2388 2392 2396 2400
If you think about it, you got really lucky with that bug. What are the odds that you'll be testing that control on 29, which is not a valid day for February of this year... You'll be able to fix it now and not when a user sends a report.
I wrote some code for my new billing system. The purpose is to bill the customer on the same day each month. (not the 1st or last day of the month)
static bool NeedToBill(DateTime planLastBilled, DateTime cycleDate)
{
// is today the same date as the cycleDate AND is was the planLastBilled not the same day as today?
if (DateTime.UtcNow.Day.Equals(cycleDate.Day) && !DateTime.UtcNow.Day.Equals(planLastBilled))
return true;
else
return false;
}
The 2 pitfalls are:
If his cycleDate.Day is the 31 and the current month only has 29 days
cycleDate is Feb 29 2012 - he will only get billed on leap years
Is there a common best practice here?
so it seems like there's a bunch things to check
has this account already been billed this month?
does the cycle day exists in the current month
is the cycle day greater than or equal to the current date (this is ideal if
the transaction failed the day before)
Thanks!
Only allow the choice of a billing day between 1 - 28. In my experience this is how most credit card / loan companies deal with it when given a choice.
What does the same day each month mean?
If I am a customer, I want to be billed on the 16th each month. No problem. If I want to be billed on the 31st on each month the obvious issue is not all months have 31 days as you've pointed out in your question.
Why not check the current month for the number of days. If it has less than 31 days, make the last day of the month the bill date.
Is there more to the problem?
I'd say make him choose between 1-28, or any day but charge on the last day on the month if the current month has less days than the chosen day of month.
Ok, I believe I have been totally over-thinking this.
This is simple and covers everything:
bool NeedToBill = ((DateTime.UTCNow – LastBillDate) >= 30 Days)
It will not necessarily bill on the exact same day, however it's close enough.
This also adds flexibility if the transaction was denied for a day, or if the scheduled task was not ran for 1 day the next time it runs it will pick it up.
How can I code a calendar? I mean how can I determine the days of the month, is the 1st a monday, tuesday or what. how many days are there in the particular month etc.
I use mainly PHP & C#. But I am mainly looking for the logic behind
Take a look at the DateTime type in the MSDN for C#.
You can determine the Weekday of a given day the following way:
var date = DateTime.Parse("16.10.2010");
Console.WriteLine(date.DayOfWeek);
If you are looking for the amount of days in a month, try this:
Console.WriteLine(DateTime.DaysInMonth(date.Year, date.Month));
Most languages (PHP and C# included) will provide utility functions or libraries which allow you to play with dates without having to get too involved in the gritty calculations.
PHP's date() and getdate() functions will tell you most details about a given date, including the day of week, day of month and day of year, provided you start with it in timestamp format.
If you want to find the details of the first of a given month, use the PHP mktime() function to get the time stamp for the date you want, then pass that into getdate() as above.
To find out how many days long a month is, you could either use a lookup table (ie Jan=31, etc), with a special case for Feb, or use the above method to get the 1st of the next month, and subtract 24 hours to get the last of the current month.
If you're using an up-to-date version of PHP (ie 5.3), there is a very useful new date class which supersedes most of the old date/time functionality, and provides a lot more besides. (it's also there in PHP 5.2, but not nearly as good as the 5.3 version).
Take a look at the GregorianCalendar class in C#. This will tell you what you need to know regarding a date according to different date "rules".
This will help you find things like the week number of a date that the DateTime class won't manage for you.