// ISODate.java Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2016-01-26 ISODate14.java file created. // 2020-03-11 File was renamed ISODate.java and the // old ISODate.java was abandoned. // This file contains the definition of class ISODate. // Internally this has been implemented by using special arrays // that are generated with special programs. // ISO refers to International Standards Organization that // has provided a standard according to which date information // should be shown in the format YYYY-MM-DD. Objects of this // ISODate class can be easily converted to strings in which date // information is in ISO format. /* The Gregorian Calendar, that most countries of the world use, is such that it actually consists of 14 different types of calendars, which can be denoted with numbers from 1 to 14 in the following way: 1 Non-Leap Year starting with Monday 2 Non-Leap Year starting with Tuesday 3 Non-Leap Year starting with Wednesday 4 Non-Leap Year starting with Thursday 5 Non-Leap Year starting with Friday 6 Non-Leap Year starting with Saturday 7 Non-Leap Year starting with Sunday 8 Leap Year starting with Monday 9 Leap Year starting with Tuesday 10 Leap Year starting with Wednesday 11 Leap Year starting with Thursday 12 Leap Year starting with Friday 13 Leap Year starting with Saturday 14 Leap Year starting with Sunday */ import java.util.Calendar ; import java.util.GregorianCalendar ; class ISODate { // Data for the initialized arrays below is generated with // separate computer programs. // The following array contains calendar codes for 400 years. // These codes are suitable for periods like 2001 ... 2400 or // 1601 ... 2000. // The first array element contains code 1 which means that // the years 1601 and 2001 are a non-leap years that start with Monday. protected static int[] calendar_codes = { 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 5, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 3, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 1, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13, 1, 2, 3, 11, 6, 7, 1, 9, 4, 5, 6, 14, 2, 3, 4, 12, 7, 1, 2, 10, 5, 6, 7, 8, 3, 4, 5, 13 } ; // The following array contains calendars that can be indexed with the // calendar codes, minus 1, taken from the array above. protected static int[] [] [] calendars = { { { 1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3 }, { 4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3 }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,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1 }, { 2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4 }, { 5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6 }, { 7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2 }, { 3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5 }, { 6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7 }, { 1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3 }, { 4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5 }, { 6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1 } } } ; // The following initialized arrays are used by the method get_week_number(). // The following array covers a 400-year period, e.g. 2001 ... 2400. // In the Gregorian Calendar 400 years has an exact whole number of weeks. // There are 15 different ways for week numbers to fit into a year. // I discovered this with a computer program. // The numbers in the following array refer to these 15 different calendars. // See also: https://en.wikipedia.org/wiki/ISO_week_date protected static int[] codes_for_week_number_calendars = { 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 9, 10, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 3, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 1, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15, 1, 2, 3, 4, 5, 6, 1, 7, 8, 9, 10, 11, 2, 3, 8, 12, 6, 1, 2, 13, 9, 10, 6, 14, 3, 8, 9, 15 } ; // The following multidimensional array contains 15 calendars with // week numbers. protected static int[] [] [] week_number_calendars = { // First day=1 First week=1 Common Year Last week=1 { { 1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5 }, { 5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9 }, { 9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13 }, { 13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18 }, { 18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22 }, { 22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26 }, { 26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31 }, { 31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35 }, { 35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39 }, { 40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44 }, { 44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48 }, { 48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,1 } }, // First day=2 First week=1 Common Year Last week=1 { { 1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5 }, { 5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9,9 }, { 9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13 }, { 14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18 }, { 18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22 }, { 22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26 }, { 27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31 }, { 31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35 }, { 35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40 }, { 40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44,44 }, { 44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48,48 }, { 48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,1,1 } }, // First day=3 First week=1 Common Year Last week=1 { { 1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5 }, { 5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9,9,9 }, { 9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13,14 }, { 14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,18 }, { 18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22,22 }, { 22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27 }, { 27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31 }, { 31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35,35 }, { 36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40,40 }, { 40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44,44,44 }, { 44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48,48,48 }, { 49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,1,1,1 } }, // First day=4 First week=1 Leap Year Last week=53 { { 1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,5 }, { 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9,9,9,9,9 }, { 10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13,14,14,14 }, { 14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18 }, { 18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22,22,22,23 }, { 23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27,27,27 }, { 27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31,31 }, { 31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35,35,36,36 }, { 36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40,40,40,40 }, { 40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44,44,44,44,44 }, { 45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48,48,48,49,49 }, { 49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,53,53,53,53,53 } }, // First day=6 First week=53 Common Year Last week=52 { { 53,53,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5 }, { 5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9 }, { 9,9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13 }, { 13,13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17 }, { 17,18,18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22 }, { 22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26 }, { 26,26,26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30 }, { 31,31,31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35 }, { 35,35,35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39 }, { 39,39,40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44 }, { 44,44,44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48 }, { 48,48,48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52 } }, // First day=7 First week=52 Common Year Last week=52 { { 52,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5 }, { 5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9 }, { 9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13 }, { 13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17 }, { 18,18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22 }, { 22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26 }, { 26,26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31 }, { 31,31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35 }, { 35,35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39 }, { 39,40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44 }, { 44,44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48 }, { 48,48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52 } }, // First day=2 First week=1 Leap Year Last week=1 { { 1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5 }, { 5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9,9,9 }, { 9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13,14 }, { 14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,18 }, { 18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22,22 }, { 22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27 }, { 27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31 }, { 31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35,35 }, { 36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40,40 }, { 40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44,44,44 }, { 44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48,48,48 }, { 49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,1,1,1 } }, // First day=4 First week=1 Common Year Last week=53 { { 1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,5 }, { 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9,9,9,9 }, { 9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13,14,14 }, { 14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18 }, { 18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22,22,22 }, { 23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27,27 }, { 27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31 }, { 31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35,35,36 }, { 36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40,40,40 }, { 40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44,44,44,44 }, { 44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48,48,48,49 }, { 49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,53,53,53,53 } }, // First day=5 First week=53 Common Year Last week=52 { { 53,53,53,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4 }, { 5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8 }, { 9,9,9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13 }, { 13,13,13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17 }, { 17,17,18,18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22 }, { 22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26 }, { 26,26,26,26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30 }, { 30,31,31,31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35 }, { 35,35,35,35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39 }, { 39,39,39,40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43 }, { 44,44,44,44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48 }, { 48,48,48,48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52 } }, // First day=6 First week=52 Common Year Last week=52 { { 52,52,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5 }, { 5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9 }, { 9,9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13 }, { 13,13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17 }, { 17,18,18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22 }, { 22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26 }, { 26,26,26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30 }, { 31,31,31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35 }, { 35,35,35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39 }, { 39,39,40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44 }, { 44,44,44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48 }, { 48,48,48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52 } }, // First day=7 First week=52 Leap Year Last week=1 { { 52,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5 }, { 5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9 }, { 9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13 }, { 13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18 }, { 18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22 }, { 22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26 }, { 26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31 }, { 31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35 }, { 35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39 }, { 40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44 }, { 44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48 }, { 48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,1 } }, // First day=5 First week=53 Leap Year Last week=52 { { 53,53,53,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4 }, { 5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9 }, { 9,9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13 }, { 13,13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17 }, { 17,18,18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22 }, { 22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26 }, { 26,26,26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30 }, { 31,31,31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35 }, { 35,35,35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39 }, { 39,39,40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44 }, { 44,44,44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48 }, { 48,48,48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52 } }, // First day=3 First week=1 Leap Year Last week=53 { { 1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5 }, { 5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9,9,9,9 }, { 9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13,14,14 }, { 14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18 }, { 18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22,22,22 }, { 23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27,27 }, { 27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31 }, { 31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35,35,36 }, { 36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40,40,40 }, { 40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44,44,44,44 }, { 44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48,48,48,49 }, { 49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,53,53,53,53 } }, // First day=1 First week=1 Leap Year Last week=1 { { 1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5 }, { 5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9,9 }, { 9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13 }, { 14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18 }, { 18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22 }, { 22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26 }, { 27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31 }, { 31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35 }, { 35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40 }, { 40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44,44,44 }, { 44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48,48,48 }, { 48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,1,1 } }, // First day=6 First week=52 Leap Year Last week=52 { { 52,52,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5 }, { 5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9 }, { 9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13 }, { 13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17 }, { 18,18,18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22 }, { 22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26 }, { 26,26,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31 }, { 31,31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35 }, { 35,35,35,36,36,36,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39 }, { 39,40,40,40,40,40,40,40,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,44,44 }, { 44,44,44,44,44,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,47,47,48,48,48,48 }, { 48,48,48,49,49,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52 } } } ; protected int this_year, this_month, this_day ; public ISODate() { // This default constructor reads the current computer's date // by using the standard classes Calendar and GregorianCalendar. Calendar current_system_date = new GregorianCalendar() ; this_year = current_system_date.get( Calendar.YEAR ) ; this_month = current_system_date.get( Calendar.MONTH ) + 1 ; this_day = current_system_date.get( Calendar.DAY_OF_MONTH ) ; } public ISODate( int given_year, int given_month, int given_day ) { this_year = given_year ; this_month = given_month ; this_day = given_day ; } public ISODate( String date_as_string ) { // This constructor accepts date strings in three formats: // // YYYY-MM-DD is the ISO 8601 format // MM/DD/YYYY is the American format. // DD.MM.YYYY is the format used in Europe. // // It seems that by using the String method split() it is possible // make the constructor to accept days and months that are // expressed only with a single digit. boolean given_date_is_valid = true ; if ( date_as_string.indexOf( '/' ) != -1 ) { // Character '/' is contained in the given date. // We'll think that it is a date in format MM/DD/YYYY String[] date_components = date_as_string.split( "[/]" ) ; this_day = Integer.parseInt( date_components[ 1 ] ) ; this_month = Integer.parseInt( date_components[ 0 ] ) ; this_year = Integer.parseInt( date_components[ 2 ] ) ; } else if ( date_as_string.indexOf( '.' ) != -1 ) { // We'll suppose the given date is in format DD.MM.YYYY String[] date_components = date_as_string.split( "[.]" ) ; this_day = Integer.parseInt( date_components[ 0 ] ) ; this_month = Integer.parseInt( date_components[ 1 ] ) ; this_year = Integer.parseInt( date_components[ 2 ] ) ; } else if ( date_as_string.indexOf( '-' ) != -1 ) { // We'll suppose the given date format is YYYY-MM-DD String[] date_components = date_as_string.split( "[-]" ) ; this_day = Integer.parseInt( date_components[ 2 ] ) ; this_month = Integer.parseInt( date_components[ 1 ] ) ; this_year = Integer.parseInt( date_components[ 0 ] ) ; } else { given_date_is_valid = false ; } if ( this_day < 1 || this_day > 31 || this_month < 1 || this_month > 12 ) { given_date_is_valid = false ; } if ( given_date_is_valid == false ) { System.out.print( "\n\n " + date_as_string + " is not a valid date. \n\n" ) ; } } // The following is the copy constructor. public ISODate( ISODate another_date ) { this_year = another_date.this_year ; this_month = another_date.this_month ; this_day = another_date.this_day ; } protected int get_calendar_code_index() { int calendar_code_index = 0 ; if ( this_year > 2000 && this_year <= 2400 ) { calendar_code_index = this_year - 2001 ; } else if ( this_year > 1600 && this_year <= 2000 ) { calendar_code_index = this_year - 1601 ; } else if ( this_year > 1200 && this_year <= 1600 ) { calendar_code_index = this_year - 1201 ; } else if ( this_year > 800 && this_year <= 1200 ) { calendar_code_index = this_year - 801 ; } else if ( this_year > 400 && this_year <= 800 ) { calendar_code_index = this_year - 401 ; } else if ( this_year > 0 && this_year <= 400 ) { calendar_code_index = this_year - 1 ; } else if ( this_year > 2400 && this_year <= 2800 ) { calendar_code_index = this_year - 2401 ; } else if ( this_year > 2800 && this_year <= 3200 ) { calendar_code_index = this_year - 2801 ; } else { System.out.print( "\n ISODate error. Year cannot be handled. \n" ) ; } return calendar_code_index ; } // The following are the getter methods for the three // data fields. public int day() { return this_day ; } public int month() { return this_month ; } public int year() { return this_year ; } public boolean is_last_day_of_month() { int calendar_code = calendar_codes[ get_calendar_code_index() ] ; int[] days_of_this_month = calendars[ calendar_code - 1 ] [ this_month - 1 ] ; return ( days_of_this_month.length == this_day ) ; } public boolean this_is_a_leap_year() { int calendar_code = calendar_codes[ get_calendar_code_index() ] ; return ( calendar_code > 7 ) ; } public boolean is_within_dates( ISODate earlier_date, ISODate later_date ) { return (( is_equal_to( earlier_date ) ) || ( is_equal_to( later_date ) ) || ( is_later_than( earlier_date ) && is_earlier_than( later_date ) ) ) ; } public int index_for_day_of_week() { // day_index will get a value in the range from 0 to 6, // 0 meaning Monday and 6 meaning Sunday. int calendar_code = calendar_codes[ get_calendar_code_index() ] ; int day_code_for_this_day = calendars[ calendar_code - 1 ] [ this_month - 1 ] [ this_day - 1 ] ; return ( day_code_for_this_day - 1 ) ; } public String get_day_of_week() { String[] days_of_week = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" } ; return days_of_week[ index_for_day_of_week() ] ; } public void increment() { if ( is_last_day_of_month() ) { this_day = 1 ; if ( this_month < 12 ) { this_month ++ ; } else { this_month = 1 ; this_year ++ ; } } else { this_day ++ ; } } public void decrement() { if ( this_day > 1 ) { this_day -- ; } else { // We have to decrement from the first day of month. if ( this_month == 1 ) { // We must go to the last day of previous year. this_day = 31 ; this_month = 12 ; this_year -- ; } else { // We must go to the last day of previous month in this year. int calendar_code = calendar_codes[ get_calendar_code_index() ] ; this_month -- ; int[] days_of_previous_month = calendars[ calendar_code - 1 ] [ this_month - 1 ] ; this_day = days_of_previous_month.length ; } } } public void get_distance_to( ISODate another_date, int[] distance_to_caller ) { int years_of_distance, months_of_distance, days_of_distance ; ISODate start_date, end_date ; int start_day, end_day ; if ( this.is_earlier_than( another_date ) ) { start_date = this ; end_date = another_date ; } else { start_date = another_date ; end_date = this ; } // We will suppose that day 30 is the last day of every // month. This way we minimize calculation errors. if ( start_date.is_last_day_of_month() || ( start_date.day() == 28 && start_date.month() == 2 ) ) { start_day = 30 ; } else { start_day = start_date.day() ; } if ( end_date.is_last_day_of_month() || ( end_date.day() == 28 && end_date.month() == 2 ) ) { end_day = 30 ; } else { end_day = end_date.day() ; } years_of_distance = end_date.year() - start_date.year() ; months_of_distance = end_date.month() - start_date.month() ; days_of_distance = end_day - start_day ; if ( days_of_distance < 0 ) { months_of_distance -- ; days_of_distance = days_of_distance + 30 ; } if ( months_of_distance < 0 ) { years_of_distance -- ; months_of_distance = months_of_distance + 12 ; } // This method delivers data to its caller in an array of type int. // The array must be created by the caller of this method. distance_to_caller[ 0 ] = years_of_distance ; distance_to_caller[ 1 ] = months_of_distance ; distance_to_caller[ 2 ] = days_of_distance ; } public int get_week_number() { int calendar_code = codes_for_week_number_calendars[ get_calendar_code_index() ] ; int week_number = week_number_calendars[ calendar_code - 1 ] [ this_month - 1 ] [ this_day - 1 ] ; return week_number ; } public boolean is_equal_to( ISODate another_date ) { return ( this_day == another_date.day() && this_month == another_date.month() && this_year == another_date.year() ) ; } public boolean is_not_equal_to( ISODate another_date ) { return ( this_day != another_date.day() || this_month != another_date.month() || this_year != another_date.year() ) ; } public boolean is_earlier_than( ISODate another_date ) { return ( ( this_year < another_date.year() ) || ( ( this_year == another_date.year() ) && ( this_month < another_date.month() ) ) || ( ( this_year == another_date.year() ) && ( this_month == another_date.month() ) && ( this_day < another_date.day() ) ) ) ; } public boolean is_later_than( ISODate another_date ) { return ( ( this_year > another_date.year() ) || ( ( this_year == another_date.year() ) && ( this_month > another_date.month() ) ) || ( ( this_year == another_date.year() ) && ( this_month == another_date.month() ) && ( this_day > another_date.day() ) ) ) ; } public boolean is_in_year_of( ISODate another_date ) { return ( this_year == another_date.this_year ) ; } public boolean is_in_month_of( ISODate another_date ) { return ( this_year == another_date.this_year && this_month == another_date.this_month ) ; } public String toString() { // This method return 'this' date as a string in the YYYY-MM-DD format. return String.format( "%d-%02d-%02d", this_year, this_month, this_day ) ; } }