I'm trying to interface with a program at work and I have to provide data based on dates.
However the weeks don't seem to be standard, this is not ISO, this is not calendar, what is it?
the only thing I can think of right now is to go from 2018 and add 7 days again and again until I reach the date I need. Then compute which years have 52 or 53 weeks and do some math to get to the week that I'm interested in.
[the week] goes from staturday to friday
if the week has 4 or more days being part of a specific year then it's a week of the said year
The WeekFields class of my Java 9 knows a lot of locales that have Saturday as first day of week, but they all require just 1 day in week 1 of the year. Your observations and mine both seem to indicate that this could be a homegrown system.
If you are using Java, WeekFields.of(DayOfWeek.SATURDAY, 4) will give you the definition of weeks used by the program you are interfacing with.
Related
My client wants to work in Nepal's Official Calendar- Hindu Calendar (Vikram Sambat). Currently i am using JQuery Ui selector which is static one. In application I need to find the number of days between two dates which are in Vikram Sambat Format; Now, I need to convert Nepali date to English and find the number of days.
And most awkward thing is, general convention of converting date
algorithm could not work perfectly for too old dates like 1960's and
upcoming dates.
By tallying I found that with in 60 years there were only 14 leap years in Vikram Sambat format, actually there must 15 leap years according english date, and number of days in a month also varying year to year some time having 31 some time 32.
I don't want to make use of array for this purpose, i want to know the logic that could determine the number of days in a month.
One of the general convention is Nepali Date to English Date: Subtract - 56 Years - 8 Months - 16 Days
As per ISO 8601, the first week is the week having at least 4 days and week start with Monday. For countries where the week starts with another day, like Sunday, how is the first week defined ?
Weeks can be defined in all sorts of ways.
The ISO 8601 standard way (starts on Monday, week # 1 has first Thursday of year) is sensible and practical, and increasingly common. In Java and its java.time framework (see Tutorial), the standard defined behavior is encapsulated in the IsoFields class. See my Answer to another Question for examples.
The non-standard approaches vary widely. Be very clear in determining such definitions with the stakeholders in your project. Document the definitions in your code base as well.
Often a company uses their own defined fiscal year for other business purposes, while some companies use the fiscal year only for bookkeeping and another calendar system for operations. Often the fiscal year is defined by its last day being a certain day-of-week such as the Friday closest to 31 December. So a year may have 52 or 53 weeks.
Sometimes week number 1 is the week containing January 1. Some people include the prior days of that week (December 31, December 30, etc.) in that new year’s week while some people cut the week into two parts (last year’s part and new year’s part).
Some define week # 1 as the earliest week that contains the first day of the week. Of course that first day of the week is defined by cultural norms such as Sunday in the United States.
Some people define week number 1 as the first complete week of the year, having no days from the previous years. So January 1, January 2, and so on may be counted in the last year.
Some industries and some companies define their own weeks of the year. Some are predictable with a pattern that can deterministically be projected out into the future, while some are arbitrary and defined by humans every year or two or three.
Until the 1990s, the Eastman Kodak Company for decades used and promoted a very different calendar system, the International Fixed Calendar. This system provides for a year of 13 months of 28 days each (exactly 4 weeks), with every date fixed always on the same weekday. So every year has week # 1 starting on Sunday January 1.
The French Republican Calendar is another different calendar in use for over a decade, with a ten-day week.
Keep your mind open, to make sense of date-time matters such as this. Understand that while a day is defined by nature (spinning of the earth) and a year is defined by nature (Earth’s orbit around the Sun), weeks and months and such are inventions of humans. The definition is subject to human creativity and to human folly (ex: Daylight Saving Time nonsense).
Being a standard, it's standardized. Same everywhere.
See Wikipedia page.
What date time format is this : 735715:37344280
<ExecDateTOD Friendly="Monday April 27, 2015 10:23:00am">735715:37344280</ExecDateTOD>
It's found in C:\Windows\Performance\WinSAT\DataStore\file_name.xml, and is the date time when the Windows Experience Index Assessment test was run.
Any idea how it's structured and can be edited? I need to change it to a previous years Date.
It seems that this format is called VariantTime, in MSDN the call to convert time is called VariantTimeToSystemTime. So it may be number of days, with decimal part after the :.
For the timestamp 735715:37344280
The first number (the one before the colon) is the number of days since the year 0:
735715 / 365 = 2015.66
The second number (the one after the colon) is the number of milliseconds that have passed within the current day.
37344280 / (1000*60*60) = 10.37 hours since start of day
So you can just subtract 365 days from the first number to obtain the previous year like this:
<ExecDateTOD Friendly="Monday April 27, 2014 10:23:00am">735350:37344280</ExecDateTOD>
Note that there were no leap years in either 2015 or 2014, so these year are exactly 365 days long.
Here is a link to a page with another <ExecDateTOD> tag where you can compare: http://www.scribd.com/doc/82935159/2012-01-30-16-00-49-986-Formal-assessment-Recent-WinSAT#scribd
I think that if you subtract 365 from that number, you'll be in previous year.
That number seems to be days since the year 0. The first part might be the number of days, taking into account leap years, etc). The second part the time coded in some way.
My customer wants to display week numbers as they show up in his wall calendar:
Week #1 starts on 1st January
Last week of the year (#53 or #54) ends on 31st December
All other weeks start on Monday and end on Sunday
(As a consequence, first and last weeks do not necessarily have 7 days.)
Does this week number algorithm have a name?
Clarification: I already have PHP code to calculate it, I'm just curious about whether this way of identifying weeks has a commonly accepted name.
There isn't one - that is a completely off-the-wall approach to week numbers. Weeks normally start either with Monday or Sunday when using the Gregorian Calendar. They do not start midway. This is not a criticism of your customer, but a comment on the fact that people invent new ways looking at date arithmetic. And get in trouble migrating to new systems.
RFC 3339
http://www.ietf.org/rfc/rfc3339.txt
See also ISO 8601
Is there a function in Haskell that will allow me to enter component of a date (like a string representation or day month year components) that I can get information from (like day of week, days in a month, etc.)?
I've looked online and it looks like there are a lot of custom libraries, but I'm hoping there's one in the standard prelude library of ghci 10.6.4 that's just not well documented?
Are Data.Time.Calendar and Data.Time.Format in the time library sufficient?
You can parse a string representation of a date and get the length of a month using gregorianMonthLength. Not sure about day of the week, though you could format the date as a string using a format that just displays the week day.
A quick Google search turns up this, which may be what you want. It lets you parse strings representing dates and extract information from them.
You can find the day of the week with mondayStartWeek or sundayStartWeek, depending on whether you think a week starts on Monday, or on Sunday. Both functions are in Data.Time.Calendar.OrdinalDate.
λ> snd $ mondayStartWeek $ fromGregorian 2017 10 3
2
In the above example, the return value is 2, which indicates the second day of the week. Since the function is called mondayStartWeek, Monday is the first day, so 2 corresponds to Tuesday. This is true of October 3, 2017.
A warning regarding week numbers
Both functions return a tuple, where the second element is the week day. As far as I can tell, that should be trustworthy.
The first element, however, is the week number of the year. Be careful with that, because the rules for week numbering are political. If I remember correctly, in USA, week 1 is the week that contains January 1. That's not the case in Denmark, where I live. Here, week 1 is the first week where Thursday falls in the new year. This can mean that December 31 can fall in week 1 of the next year. IIRC, this is the rule for many other European countries. Some years, the American and the European week numbers align, but some years, they don't.