![]() ![]() I say "very fortunately" because I couldn't believe my good luck with what I found. I wanted one that I could use as a high performance "iSF" (Inline Scalar Function) like the one I had built. Very fortunately for me, I had misplaced my previously written T-SQL solution to solve for ISO Week Numbers and decided to do a quick web search to find one instead of trying to find my own. How to build a “Broadcast Calendar” will have to wait until another article, though, because I found something else that’s very cool. SELECT was working on a thread that asked how to create a "Broadcast Calendar" ( ) and, to make a much longer story shorter, it dawned on me that I might be able to solve the problem using a calculation similar to an "ISO Week Number" calculation. The modifications only cause a scant increase of a dozen or so milliseconds over a million row test so it's still a competitor with the ISOWEEK date-part of SQL Server 2008 and up and still works in earlier versions. Here's that code and that's the one I recommend that you use if you have the need (< SQL Server 2008). SELECT verified the modified formula and made an additional optimization that removed one of the additions which saves a bit on CPU time. I found the fix and that was to add the difference in dates to the "base date" instead of using the difference in dates as a date serial number. I had the article taken "offline" until I could fix it and test it. This works just fine for dates greater than or equal to because that difference in days matches SQL Server's underlying date serial numbers but it doesn't work correctly for dates that have a date serial number less than 0 (). The problem is with "Step 3 – Convert the Date Serial to the "Day of the Year" where a difference in days is used in the calculation instead of the actual date. The original formula has a problem that I didn't originally test for and, that is, if you use the formula for dates earlier than, the calculation of the correct ISOWeek is by chance rather than by plan. This article is no exception and I thank Peter Larsson who discovered that there was a problem. I've made no changes in the article starting with the "Introduction" because it still correctly describes the original formula written by "t-clausen.dk".Īs is the nature of this fine community, if there's a problem with something in an article, it is quickly ferreted out by those who participate in the discussion. display = 'none' // Test whether a new date input falls back to a text input or not const test = document. querySelector ( '#fallbackWeek' ) // Hide fallback initiallyįallbackPicker. querySelector ( '#year' ) const weekSelect = document. ![]() querySelector ( '.fallbackLabel' ) const yearSelect = document. querySelector ( '.fallbackWeekPicker' ) const fallbackLabel = document. querySelector ( '.nativeWeekPicker' ) const fallbackPicker = document. Get UI elements const nativePicker = document. The best way to deal with week/years in forms in a cross-browser way at the moment is to get the user to enter the week number and year in separate controls ( elements being popular see below for an example), or use JavaScript libraries such as jQuery date picker. There are multiple ways in which people could write week values for example: When the browser falls back to a generic text input, there's nothing to guide the user toward correctly formatting the input (and it's certainly not intuitive). As mentioned earlier, with a week input the actual value is always normalized to the format yyyy-Www. Non-supporting browsers gracefully degrade to a text input, but this creates problems both in terms of consistency of user interface (the presented control will be different), and data handling. For example, the week picker on Chrome for Android looks like this: Mobile platforms such as Android and iOS make really good use of such input types, providing specialist UI controls that make it really easy to select values in a touchscreen environment. As mentioned above, the major problem with using week inputs right now is browser support: Safari and Firefox don't support it on desktop, and old versions of IE don't support it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |