├── floreal.js ├── test ├── all.js └── date.test.js ├── package.json ├── LICENSE ├── README.md └── date.js /floreal.js: -------------------------------------------------------------------------------- 1 | var FlorealDate = require("./date.js"); 2 | 3 | exports.Date = FlorealDate; 4 | -------------------------------------------------------------------------------- /test/all.js: -------------------------------------------------------------------------------- 1 | exports["test date"] = require("./date.test.js"); 2 | 3 | if (module == require.main) require('test').run(exports); 4 | 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "floreal", 3 | "description": "Date formatting for the French Revolutionary calendar", 4 | "version": "1.1.1", 5 | "author": { 6 | "name": "Matthieu Valleton", 7 | "email": "mvalleton@seos.fr", 8 | "url": "http://ssz.fr" 9 | }, 10 | "license": "MIT", 11 | "keywords": [ 12 | "conversion", 13 | "dates", 14 | "calendar", 15 | "history", 16 | "historical", 17 | "france", 18 | "french", 19 | "republic" 20 | ], 21 | "repository": { 22 | "type": "git", 23 | "url": "http://github.com/seeschloss/floreal" 24 | }, 25 | "main": "floreal.js", 26 | "scripts": { 27 | "test": "node test/all.js" 28 | }, 29 | "dependencies": { 30 | "roman-numerals": "^0.3.2" 31 | }, 32 | "devDependencies": { 33 | "test": ">=0.0.5" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 SeeSchloß 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # floreal 2 | ## Installation ## 3 | Using git: 4 | 5 | $ git clone https://github.com/seeschloss/floreal.git 6 | 7 | Using npm: 8 | 9 | $ npm install floreal 10 | 11 | ## Usage ## 12 | 13 | ### new floreal.Date(timespec) ### 14 | Uses the native JavaScript Date object to parse *timespec* and takes any correctly formatted date. An `undefined` timespec means today. 15 | 16 | ```javascript 17 | var Floreal = require('floreal').Date; 18 | var coup = new Floreal("1799-11-09"); 19 | console.log('%s', coup); 20 | ``` 21 | will output: 22 | 23 | 18 brumaire, an VIII 24 | 25 | 26 | ### floreal.Date.toFullDateString() ### 27 | Returns the full date in long form as "[day number] [month name], an [year in roman numerals]" 28 | 29 | ```javascript 30 | var Floreal = require('floreal').Date; 31 | console.log('%s', (new Floreal("1799-10-11")).toFullDateString()); 32 | ``` 33 | will output: 34 | 35 | 18 brumaire, an VIII 36 | 37 | ### floreal.Date.toShortDateString() ### 38 | Returns the full date in short form as "[day number]-[month number]-[year in roman numerals]" 39 | 40 | ```javascript 41 | var Floreal = require('floreal').Date; 42 | console.log('%s', (new Floreal("1799-10-11")).toShortDateString()); 43 | ``` 44 | 45 | will output: 46 | 47 | 18-02-VIII 48 | 49 | ### floreal.Date.setYear(year) ### 50 | Sets Republican year for the date *in roman numerals* 51 | 52 | ### floreal.Date.setYearDecimal(year) ### 53 | Sets Republican year for the date in arabic numerals 54 | 55 | ### floreal.Date.setMonth(month) ### 56 | Sets Republican month for the date. Month 1 is vendémiaire, both 0 and 13 represent complementary days. 57 | 58 | ### floreal.Date.setDay(day) ### 59 | Sets Republican day for the date, first day of the month is 1. 60 | 61 | ### floreal.Date.setDate(year, month, day) ### 62 | Sets the full Republican date. 63 | 64 | ```javascript 65 | var Floreal = require('floreal').Date; 66 | var date = new Floreal(); 67 | date.setDate(8, 2, 18); 68 | console.log('%s', date.toFullDateString()); 69 | ``` 70 | will output: 71 | 72 | 18 brumaire, an VIII 73 | 74 | ### floreal.Date.setMonth(month) ### 75 | ### floreal.Date.setDay(day) ### 76 | 77 | ### floreal.Date.year() ### 78 | ### floreal.Date.yearDecimal() ### 79 | Displays year of the Republic as roman numerals or as a decimal number 80 | 81 | ```javascript 82 | var Floreal = require('floreal').Date; 83 | var coup = new Floreal("1799-11-09"); 84 | console.log('%s', coup.year()); 85 | console.log('%s', coup.yearDecimal()); 86 | ``` 87 | will output: 88 | 89 | VIII 90 | 8 91 | 92 | ### floreal.Date.isYearSextile() ### 93 | Returns true if year is sextile, using actual sextile years for years I to XVI, and [Romme system](http://gallica.bnf.fr/ark:/12148/bpt6k826927/f328.image.r) for subsequent years. 94 | 95 | ```javascript 96 | var Floreal = require('floreal').Date; 97 | console.log('%s', (new Floreal("1799-11-09")).isYearSextile()); 98 | console.log('%s', (new Floreal("1803-08-18")).isYearSextile()); 99 | ``` 100 | will output: 101 | 102 | false 103 | true 104 | 105 | ### floreal.Date.firstDayOfYear() ### 106 | Returns the first day of the Republican year as a JavaScript Date object. 107 | 108 | ```javascript 109 | var Floreal = require('floreal').Date; 110 | console.log('%s', (new Floreal("1799-11-09")).firstDayOfYear().toDateString()); 111 | console.log('%s', (new Floreal("1803-08-18")).firstDayOfYear().toDateString()); 112 | ``` 113 | will output: 114 | 115 | Mon Sep 23 1799 116 | Thu Sep 23 1802 117 | 118 | ### floreal.Date.dayOfYear() ### 119 | Returns the day number within the year (from 1 to 365, or 366 for sextile years). 120 | 121 | ```javascript 122 | var Floreal = require('floreal').Date; 123 | console.log('%s', (new Floreal("1799-11-09")).dayOfYear()); 124 | ``` 125 | will output: 126 | 127 | 48 128 | 129 | ### floreal.Date.month() ### 130 | Returns the month number within the year. Complementary days are technically not part of any month, but for practical purposes are considered part of the 13th month. 131 | 132 | ```javascript 133 | var Floreal = require('floreal').Date; 134 | console.log('%s', (new Floreal("1799-11-09")).month()); 135 | ``` 136 | will output: 137 | 138 | 2 139 | 140 | ### floreal.Date.isComplementaryDay() ### 141 | Whether the day is a complementary day—the five or six days at the end of the year which are not part of any month. 142 | 143 | ```javascript 144 | var Floreal = require('floreal').Date; 145 | console.log('%s', (new Floreal("1800-09-20")).isComplementaryDay()); 146 | ``` 147 | will output: 148 | 149 | true 150 | 151 | ### floreal.Date.monthName() ### 152 | Returns the (French) name of the month, in all lower case, or an empty string for complementary days. 153 | 154 | ```javascript 155 | var Floreal = require('floreal').Date; 156 | console.log('"%s"', (new Floreal("1799-11-09")).monthName()); 157 | console.log('"%s"', (new Floreal("1800-09-20")).monthName()); 158 | ``` 159 | will output: 160 | 161 | "brumaire" 162 | "" 163 | 164 | ### floreal.Date.dayOfMonth() ### 165 | ### floreal.Date.day() ### 166 | Returns the day number within its month, from 1 to 30 (1 to 6 for complementary days). 167 | 168 | ```javascript 169 | var Floreal = require('floreal').Date; 170 | console.log('%s', (new Floreal("1799-11-09")).dayOfMonth()); 171 | console.log('%s', (new Floreal("1800-09-20")).dayOfMonth()); 172 | ``` 173 | will output: 174 | 175 | 18 176 | 3 177 | 178 | ### floreal.Date.dayOfDecade() ### 179 | ### floreal.Date.dayOfWeek() ### 180 | Returns the day number within its decade, from 1 to 10 (1 to 6 for complementary days). 181 | 182 | ```javascript 183 | var Floreal = require('floreal').Date; 184 | console.log('%s', (new Floreal("1799-11-09")).dayOfDecade()); 185 | console.log('%s', (new Floreal("1800-09-20")).dayOfDecade()); 186 | ``` 187 | will output: 188 | 189 | 8 190 | 3 191 | 192 | ### floreal.Date.decade() ### 193 | Returns the decade number within the month, from 1 to 3 (complementary days are reported as belonging to first decade). 194 | 195 | ```javascript 196 | var Floreal = require('floreal').Date; 197 | console.log('%s', (new Floreal("1799-11-09")).decade()); 198 | console.log('%s', (new Floreal("1800-09-20")).decade()); 199 | ``` 200 | will output: 201 | 202 | 2 203 | 1 204 | 205 | ### floreal.Date.dayName() ### 206 | Returns the name of the day (primidi, duodi... equivalent to monday, tuesday...). Complementary days have a different naming scheme and are named "jour de la vertu", "jour du génie", etc. 207 | 208 | ```javascript 209 | var Floreal = require('floreal').Date; 210 | console.log('%s', (new Floreal("1799-11-09")).dayName()); 211 | ``` 212 | will output: 213 | 214 | octidi 215 | 216 | ### floreal.Date.dayTitle() ### 217 | Returns the French name of the object associated with the day (like saints on Christian calendars). 218 | 219 | ```javascript 220 | var Floreal = require('floreal').Date; 221 | console.log('%s', (new Floreal("1799-10-11")).dayTitle()); 222 | ``` 223 | will output: 224 | 225 | tournesol 226 | -------------------------------------------------------------------------------- /date.js: -------------------------------------------------------------------------------- 1 | var roman = require('roman-numerals'); 2 | 3 | var day_names = [ 4 | '', // align with day numbers 5 | 'raisin', 'safran', 'châtaigne', 'colchique', 'cheval', 'balsamine', 'carotte', 'amaranthe', 'panais', 'cuve', 'pomme de terre', 'immortelle', 'potiron', 'réséda', 'âne', 'belle de nuit', 'citrouille', 'sarrasin', 'tournesol', 'pressoir', 'chanvre', 'pêche', 'navet', 'amaryllis', 'bœuf', 'aubergine', 'piment', 'tomate', 'orge', 'tonneau', 6 | 'pomme', 'céleri', 'poire', 'betterave', 'oie', 'héliotrope', 'figue', 'scorsonère', 'alisier', 'charrue', 'salsifis', 'mâcre', 'topinambour', 'endive', 'dindon', 'chervis', 'cresson', 'dentelaire', 'grenade', 'herse', 'bacchante', 'azerole', 'garance', 'orange', 'faisan', 'pistache', 'macjonc', 'coing', 'cormier', 'rouleau', 7 | 'raiponce', 'turneps', 'chicorée', 'nèfle', 'cochon', 'mâche', 'chou-fleur', 'miel', 'genièvre', 'pioche', 'cire', 'raifort', 'cèdre', 'sapin', 'chevreuil', 'ajonc', 'cyprès', 'lierre', 'sabine', 'hoyau', 'érable sucré', 'bruyère', 'roseau', 'oseille', 'grillon', 'pignon', 'liège', 'truffe', 'olive', 'pelle', 8 | 'tourbe', 'houille', 'bitume', 'soufre', 'chien', 'lave', 'terre végétale', 'fumier', 'salpêtre', 'fléau', 'granit', 'argile', 'ardoise', 'grès', 'lapin', 'silex', 'marne', 'pierre à chaux', 'marbre', 'van', 'pierre à plâtre', 'sel', 'fer', 'cuivre', 'chat', 'étain', 'plomb', 'zinc', 'mercure', 'crible', 9 | 'lauréole', 'mousse', 'fragon', 'perce-neige', 'taureau', 'laurier tin', 'amadouvier', 'mézéréon', 'peuplier', 'coignée', 'ellébore', 'brocoli', 'laurier', 'avelinier', 'vache', 'buis', 'lichen', 'if', 'pulmonaire', 'serpette', 'thlaspi', 'thimele', 'chiendent', 'trainasse', 'lièvre', 'guède', 'noisetier', 'cyclamen', 'chélidoine', 'traîneau', 10 | 'tussilage', 'cornouiller', 'violier', 'troène', 'bouc', 'asaret', 'alaterne', 'violette', 'marceau', 'bêche', 'narcisse', 'orme', 'fumeterre', 'vélar', 'chèvre', 'épinard', 'doronic', 'mouron', 'cerfeuil', 'cordeau', 'mandragore', 'persil', 'cochléaria', 'pâquerette', 'thon', 'pissenlit', 'sylvie', 'capillaire', 'frêne', 'plantoir', 11 | 'primevère', 'platane', 'asperge', 'tulipe', 'poule', 'bette', 'bouleau', 'jonquille', 'aulne', 'couvoir', 'pervenche', 'charme', 'morille', 'hêtre', 'abeille', 'laitue', 'mélèze', 'ciguë', 'radis', 'ruche', 'gainier', 'romaine', 'marronnier', 'roquette', 'pigeon', 'lilas', 'anémone', 'pensée', 'myrtile', 'greffoir', 12 | 'rose', 'chêne', 'fougère', 'aubépine', 'rossignol', 'ancolie', 'muguet', 'champignon', 'hyacinthe', 'râteau', 'rhubarbe', 'sainfoin', 'bâton-d\'or', 'chamerops', 'ver à soie', 'consoude', 'pimprenelle', 'corbeille d\'or', 'arroche', 'sarcloir', 'statice', 'fritillaire', 'bourrache', 'valériane', 'carpe', 'fusain', 'civette', 'buglosse', 'sénevé', 'houlette', 13 | 'luzerne', 'hémérocalle', 'trèfle', 'angélique', 'canard', 'mélisse', 'fromental', 'lis martagon', 'serpolet', 'faux', 'fraise', 'bétoine', 'pois', 'acacia', 'caille', 'œillet', 'sureau', 'pavot', 'tilleul', 'fourche', 'barbeau', 'camomille', 'chèvrefeuille', 'caille-lait', 'tanche', 'jasmin', 'verveine', 'thym', 'pivoine', 'chariot', 14 | 'seigle', 'avoine', 'oignon', 'véronique', 'mulet', 'romarin', 'concombre', 'échalote', 'absinthe', 'faucille', 'coriandre', 'artichaut', 'girofle', 'lavande', 'chamois', 'tabac', 'groseille', 'gesse', 'cerise', 'parc', 'menthe', 'cumin', 'haricot', 'orcanète', 'pintade', 'sauge', 'ail', 'vesce', 'blé', 'chalemie', 15 | 'épeautre', 'bouillon-blanc', 'melon', 'ivraie', 'bélier', 'prêle', 'armoise', 'carthame', 'mûre', 'arrosoir', 'panic', 'salicorne', 'abricot', 'basilic', 'brebis', 'guimauve', 'lin', 'amande', 'gentiane', 'écluse', 'carline', 'câprier', 'lentille', 'aunée', 'loutre', 'myrte', 'colza', 'lupin', 'coton', 'moulin', 16 | 'prune', 'millet', 'lycoperdon', 'escourgeon', 'saumon', 'tubéreuse', 'sucrion', 'apocyn', 'réglisse', 'échelle', 'pastèque', 'fenouil', 'épine vinette', 'noix', 'truite', 'citron', 'cardère', 'nerprun', 'tagette', 'hotte', 'églantier', 'noisette', 'houblon', 'sorgho', 'écrevisse', 'bigarade', 'verge d\'or', 'maïs', 'marron', 'panier', 17 | ]; 18 | 19 | var is_year_sextile = function(year) { 20 | switch (year) { 21 | case 3: 22 | case 7: 23 | case 11: 24 | return true; 25 | default: 26 | return year > 14 && ( 27 | (year % 4 == 0 && (year + 1792) % 100 != 0) 28 | || ((year + 1792) % 400 == 0 && (year + 1792) % 4000 != 0) 29 | ); 30 | 31 | } 32 | }; 33 | 34 | var first_day_of_year = function(year) { 35 | switch (year) { 36 | case 4: 37 | case 8: 38 | var first_day = 23; 39 | break; 40 | case 12: 41 | case 16: 42 | var first_day = 24; 43 | break; 44 | default: 45 | var first_day = 24 46 | - Math.floor((year - 1)/100) 47 | + Math.floor((year - 1) / 400) 48 | + Math.floor((year - 209) / 100) 49 | - Math.floor((year - 209) / 400); 50 | break; 51 | } 52 | 53 | var date = new Date(); 54 | date.setUTCFullYear(year + 1791); 55 | date.setUTCMonth(9 - 1); 56 | date.setUTCDate(first_day); 57 | date.setUTCHours(0); 58 | date.setUTCMinutes(0); 59 | date.setUTCSeconds(0); 60 | date.setUTCMilliseconds(0); 61 | 62 | return date; 63 | }; 64 | 65 | var ordinal_string = function(day) { 66 | return day == 1 ? "1er" : day + "e"; 67 | }; 68 | 69 | var pad_left = function(number) { 70 | return number < 10 ? "0" + number : "" + number; 71 | }; 72 | 73 | var republicReference = new Date('1792-09-22'); 74 | 75 | var FlorealDate = function(arg) { 76 | if (arg) { 77 | this.date = new Date(arg); 78 | } else { 79 | this.date = new Date(); 80 | } 81 | 82 | this.revolutionaryTimestamp = this.date - republicReference; 83 | }; 84 | 85 | FlorealDate.prototype.setDate = function(year, month, day) { 86 | var gregorianDate = first_day_of_year(year); 87 | 88 | // Allow using 0 as the month for complementary days 89 | month = month > 0 ? month : 13; 90 | 91 | var day_of_republican_year = 30 * (month-1) + day; 92 | 93 | gregorianDate.setDate(gregorianDate.getDate() + day_of_republican_year - 1); 94 | 95 | this.date = gregorianDate; 96 | 97 | return this; 98 | }; 99 | 100 | FlorealDate.prototype.setYear = function(year) { 101 | return this.setDate(roman.toArabic(year), this.month(), this.dayOfMonth()); 102 | }; 103 | 104 | FlorealDate.prototype.setYearDecimal = function(year) { 105 | return this.setDate(year, this.month(), this.dayOfMonth()); 106 | }; 107 | 108 | FlorealDate.prototype.setMonth = function(month) { 109 | return this.setDate(this.yearDecimal(), month, this.dayOfMonth()); 110 | }; 111 | 112 | FlorealDate.prototype.setDay = function(day) { 113 | return this.setDate(this.yearDecimal(), this.month(), day); 114 | }; 115 | 116 | FlorealDate.day_names = day_names; 117 | FlorealDate.first_day_of_year = first_day_of_year; 118 | 119 | FlorealDate.prototype.yearDecimal = function() { 120 | var year = this.date.getFullYear() - 1792; 121 | 122 | if (this.date.getMonth()+1 > 9) { 123 | // All years start in september, so any month after that means 124 | // the year is +1793 instead of +1792 125 | year += 1; 126 | } else if (this.date.getMonth()+1 == 9) { 127 | // Since years can start either on 22, 23 or 24 september, let's 128 | // check more precisely on which date we are. 129 | if (this.date.getDate() >= 22 && this.date >= first_day_of_year(year+1)) { 130 | // If this date is at least equal to the first day of 131 | // year+1, obviously this year is year+1 132 | year += 1; 133 | } 134 | } 135 | 136 | // There is no year 0 137 | if (year <= 0) { 138 | year -= 1; 139 | } 140 | 141 | return year; 142 | }; 143 | 144 | FlorealDate.prototype.year = function() { 145 | var decimal = this.yearDecimal(); 146 | 147 | // Roman numerals cannot be negative, and years before an I are simply 148 | // not supposed to be displayed using the revolutionary calendar. 149 | // Let's just prepend a - to the roman value. 150 | if (decimal < 0) { 151 | return '-' + roman.toRoman(-1 * this.yearDecimal()); 152 | } else { 153 | return roman.toRoman(this.yearDecimal()); 154 | } 155 | }; 156 | 157 | FlorealDate.prototype.isYearSextile = function() { 158 | return is_year_sextile(this.yearDecimal()); 159 | }; 160 | 161 | FlorealDate.prototype.firstDayOfYear = function() { 162 | return first_day_of_year(this.yearDecimal()); 163 | }; 164 | 165 | FlorealDate.prototype.dayOfYear = function() { 166 | var seconds = ((+this.date) - (+this.firstDayOfYear())) / 1000; 167 | 168 | return Math.floor(seconds / (3600 * 24)) + 1; 169 | }; 170 | 171 | FlorealDate.prototype.month = function() { 172 | return Math.floor((this.dayOfYear() - 1) / 30) + 1; 173 | }; 174 | 175 | FlorealDate.prototype.isComplementaryDay = function() { 176 | return this.month() == 13; 177 | }; 178 | 179 | FlorealDate.prototype.monthName = function() { 180 | switch (this.month()) { 181 | case 1: return "vendémiaire"; 182 | case 2: return "brumaire"; 183 | case 3: return "frimaire"; 184 | case 4: return "nivôse"; 185 | case 5: return "pluviôse"; 186 | case 6: return "ventôse"; 187 | case 7: return "germinal"; 188 | case 8: return "floréal"; 189 | case 9: return "prairial"; 190 | case 10: return "messidor"; 191 | case 11: return "thermidor"; 192 | case 12: return "fructidor"; 193 | 194 | // Jours complémentaires 195 | default: return ""; 196 | 197 | } 198 | }; 199 | 200 | FlorealDate.prototype.dayOfMonth = function() { 201 | return ((this.dayOfYear() - 1) % 30) + 1; 202 | }; 203 | FlorealDate.prototype.day = FlorealDate.prototype.dayOfMonth; 204 | 205 | FlorealDate.prototype.dayOfDecade = function() { 206 | return Math.floor((this.day() - 1) % 10) + 1; 207 | }; 208 | FlorealDate.prototype.dayOfWeek = FlorealDate.prototype.dayOfDecade; 209 | 210 | FlorealDate.prototype.dayName = function() { 211 | if (!this.isComplementaryDay()) switch (this.dayOfDecade()) { 212 | case 1: return "primidi"; 213 | case 2: return "duodi"; 214 | case 3: return "tridi"; 215 | case 4: return "quartidi"; 216 | case 5: return "quintidi"; 217 | case 6: return "sextidi"; 218 | case 7: return "septidi"; 219 | case 8: return "octidi"; 220 | case 9: return "nonidi"; 221 | case 10: return "décadi"; 222 | } else switch (this.dayOfDecade()) { 223 | case 1: return "jour de la vertu"; 224 | case 2: return "jour du génie"; 225 | case 3: return "jour du travail"; 226 | case 4: return "jour de l'opinion"; 227 | case 5: return "jour des récompenses"; 228 | case 6: return "jour de la révolution"; 229 | } 230 | }; 231 | 232 | FlorealDate.prototype.dayTitle = function() { 233 | if (!this.isComplementaryDay()) { 234 | return day_names[this.dayOfYear()]; 235 | } else switch (this.dayOfDecade()) { 236 | case 1: return "vertu"; 237 | case 2: return "génie"; 238 | case 3: return "travail"; 239 | case 4: return "opinion"; 240 | case 5: return "récompenses"; 241 | case 6: return "révolution"; 242 | } 243 | }; 244 | 245 | FlorealDate.prototype.decade = function() { 246 | return Math.floor((this.day()-1)/10) + 1; 247 | }; 248 | 249 | 250 | FlorealDate.prototype.toFullDateString = function() { 251 | var day = this.day(); 252 | 253 | if (this.isComplementaryDay()) { 254 | return ordinal_string(day) + " jour complémentaire, an " + this.year(); 255 | } else { 256 | var day_string = day == 1 ? '1er' : day; 257 | return day_string + " " + this.monthName() + ", an " + this.year(); 258 | } 259 | }; 260 | 261 | // Short format was not used, I define it as: 262 | // DD-MM-YYY 263 | // DD being the day number, between 01 and 30 264 | // MM the month number, between 01 and 13 (13 being the number for complementary days) 265 | // YYY the year number, in roman numerals 266 | FlorealDate.prototype.toShortDateString = function() { 267 | return pad_left(this.day()) + "-" + pad_left(this.month()) + "-" + this.year(); 268 | }; 269 | FlorealDate.prototype.toDateString = FlorealDate.prototype.toShortDateString; 270 | 271 | FlorealDate.prototype.toString = FlorealDate.prototype.toFullDateString; 272 | 273 | module.exports = FlorealDate; 274 | 275 | -------------------------------------------------------------------------------- /test/date.test.js: -------------------------------------------------------------------------------- 1 | // vim:et:sw=2 2 | 3 | var FlorealDate = require("../date.js"); 4 | 5 | exports['test date constructor'] = function(assert, done) { 6 | var date = new FlorealDate("2015-01-16 12:34:56"); 7 | 8 | assert.equal(date.date.toString(), (new Date("2015-01-16 12:34:56")).toString(), "Internal date correctly set"); 9 | 10 | done(); 11 | }; 12 | 13 | exports['test first_day_of_year'] = function(assert, done) { 14 | assert.equal(+FlorealDate.first_day_of_year(1), +new Date("1792-09-22"), "Year I started on 22 september"); 15 | assert.equal(+FlorealDate.first_day_of_year(2), +new Date("1793-09-22"), "Year II started on 22 september"); 16 | assert.equal(+FlorealDate.first_day_of_year(3), +new Date("1794-09-22"), "Year III started on 22 september"); 17 | assert.equal(+FlorealDate.first_day_of_year(4), +new Date("1795-09-23"), "Year IV started on 23 september"); 18 | assert.equal(+FlorealDate.first_day_of_year(5), +new Date("1796-09-22"), "Year V started on 22 september"); 19 | assert.equal(+FlorealDate.first_day_of_year(6), +new Date("1797-09-22"), "Year VI started on 22 september"); 20 | assert.equal(+FlorealDate.first_day_of_year(7), +new Date("1798-09-22"), "Year VII started on 22 september"); 21 | assert.equal(+FlorealDate.first_day_of_year(8), +new Date("1799-09-23"), "Year VIII started on 23 september"); 22 | assert.equal(+FlorealDate.first_day_of_year(9), +new Date("1800-09-23"), "Year XI started on 23 september"); 23 | assert.equal(+FlorealDate.first_day_of_year(10), +new Date("1801-09-23"), "Year X started on 23 september"); 24 | assert.equal(+FlorealDate.first_day_of_year(11), +new Date("1802-09-23"), "Year XI started on 23 september"); 25 | assert.equal(+FlorealDate.first_day_of_year(12), +new Date("1803-09-24"), "Year XII started on 24 september"); 26 | assert.equal(+FlorealDate.first_day_of_year(13), +new Date("1804-09-23"), "Year XIII started on 23 september"); 27 | assert.equal(+FlorealDate.first_day_of_year(14), +new Date("1805-09-23"), "Year XIV started on 23 september"); 28 | assert.equal(+FlorealDate.first_day_of_year(79), +new Date("1870-09-23"), "Year LXXIX started on 23 september"); 29 | assert.equal(+FlorealDate.first_day_of_year(222), +new Date("2013-09-22"), "Year CCXXII would have started on 22 september"); 30 | assert.equal(+FlorealDate.first_day_of_year(223), +new Date("2014-09-22"), "Year CCXXIII would have started on 22 september"); 31 | assert.equal(+FlorealDate.first_day_of_year(224), +new Date("2015-09-22"), "Year CCXXIV would have started on 22 september"); 32 | 33 | done(); 34 | }; 35 | 36 | exports['test yearDecimal'] = function(assert, done) { 37 | assert.equal(new FlorealDate("1792-09-22").yearDecimal(), 1, "Year correctly calculated"); 38 | assert.equal(new FlorealDate("1792-10-22").yearDecimal(), 1, "Year correctly calculated"); 39 | assert.equal(new FlorealDate("1794-01-16").yearDecimal(), 2, "Year correctly calculated"); 40 | assert.equal(new FlorealDate("1792-09-21").yearDecimal(), -1, "Years before 1er vendémiaire I are negative"); 41 | 42 | done(); 43 | }; 44 | 45 | exports['test year'] = function(assert, done) { 46 | assert.equal(new FlorealDate("1792-09-22").year(), "I", "Year correctly formatted as Roman numerals"); 47 | assert.equal(new FlorealDate("1794-01-16").year(), "II", "Year correctly formatted as Roman numerals"); 48 | assert.equal(new FlorealDate("1794-09-21").year(), "II", "Year II started on 22 september"); 49 | assert.equal(new FlorealDate("1792-09-21").year(), "-I", "Years before 1er vendémiaire I are negative"); 50 | assert.equal(new FlorealDate("1798-09-22").year(), "VII", "Year VII started on 22 september"); 51 | assert.equal(new FlorealDate("1798-09-30").year(), "VII", "Year VII started on 22 september"); 52 | assert.equal(new FlorealDate("1799-09-22").year(), "VII", "Year VII ended on 22 september"); 53 | 54 | done(); 55 | }; 56 | 57 | exports['test isYearSextile'] = function(assert, done) { 58 | assert.equal(+new FlorealDate("1792-09-22").isYearSextile(), false, "Year I is not sextile"); 59 | assert.equal(+new FlorealDate("1793-09-22").isYearSextile(), false, "Year II is not sextile"); 60 | assert.equal(+new FlorealDate("1794-09-22").isYearSextile(), true, "Year III is sextile"); 61 | assert.equal(+new FlorealDate("1795-09-23").isYearSextile(), false, "Year IV is not sextile"); 62 | assert.equal(+new FlorealDate("1796-09-22").isYearSextile(), false, "Year V is not sextile"); 63 | assert.equal(+new FlorealDate("1797-09-22").isYearSextile(), false, "Year VI is not sextile"); 64 | assert.equal(+new FlorealDate("1798-09-22").isYearSextile(), true, "Year VII is sextile"); 65 | assert.equal(+new FlorealDate("1799-09-23").isYearSextile(), false, "Year VIII is not sextile"); 66 | assert.equal(+new FlorealDate("1800-09-23").isYearSextile(), false, "Year XI is not sextile"); 67 | assert.equal(+new FlorealDate("1801-09-23").isYearSextile(), false, "Year X is not sextile"); 68 | assert.equal(+new FlorealDate("1802-09-23").isYearSextile(), true, "Year XI is sextile"); 69 | assert.equal(+new FlorealDate("1803-09-24").isYearSextile(), false, "Year XII is not sextile"); 70 | assert.equal(+new FlorealDate("1804-09-23").isYearSextile(), false, "Year XIII is not sextile"); 71 | assert.equal(+new FlorealDate("1805-09-23").isYearSextile(), false, "Year XIV is not sextile"); 72 | assert.equal(+new FlorealDate("1870-09-23").isYearSextile(), false, "Year LXXIX is not sextile"); 73 | assert.equal(+new FlorealDate("2013-09-21").isYearSextile(), false, "Year CCXXII is not sextile"); 74 | assert.equal(+new FlorealDate("2014-09-21").isYearSextile(), false, "Year CCXXIII is not sextile"); 75 | assert.equal(+new FlorealDate("2015-09-21").isYearSextile(), false, "Year CCXXIV is sextile"); 76 | 77 | done(); 78 | }; 79 | 80 | exports['test firstDayOfYear'] = function(assert, done) { 81 | assert.equal(+new FlorealDate("1792-09-22").firstDayOfYear(), +new Date("1792-09-22"), "The very first day of the calendar is correct"); 82 | assert.equal(+new FlorealDate("1793-09-21").firstDayOfYear(), +new Date("1792-09-22"), "Year I started on 22 september"); 83 | assert.equal(+new FlorealDate("1793-09-22").firstDayOfYear(), +new Date("1793-09-22"), "Year II started on 22 september"); 84 | assert.equal(+new FlorealDate("1794-09-21").firstDayOfYear(), +new Date("1793-09-22"), "Year II started on 22 september"); 85 | assert.equal(+new FlorealDate("1794-09-22").firstDayOfYear(), +new Date("1794-09-22"), "Year III started on 22 september"); 86 | assert.equal(+new FlorealDate("1795-09-21").firstDayOfYear(), +new Date("1794-09-22"), "Year III started on 22 september"); 87 | assert.equal(+new FlorealDate("1795-09-23").firstDayOfYear(), +new Date("1795-09-23"), "Year IV started on 23 september"); 88 | assert.equal(+new FlorealDate("1796-09-22").firstDayOfYear(), +new Date("1796-09-22"), "Year V started on 22 september"); 89 | assert.equal(+new FlorealDate("1797-09-21").firstDayOfYear(), +new Date("1796-09-22"), "Year V started on 22 september"); 90 | assert.equal(+new FlorealDate("1797-09-22").firstDayOfYear(), +new Date("1797-09-22"), "Year VI started on 22 september"); 91 | assert.equal(+new FlorealDate("1798-09-22").firstDayOfYear(), +new Date("1798-09-22"), "Year VII started on 22 september"); 92 | assert.equal(+new FlorealDate("1799-09-23").firstDayOfYear(), +new Date("1799-09-23"), "Year VIII started on 23 september"); 93 | assert.equal(+new FlorealDate("1800-09-23").firstDayOfYear(), +new Date("1800-09-23"), "Year XI started on 23 september"); 94 | assert.equal(+new FlorealDate("1801-09-23").firstDayOfYear(), +new Date("1801-09-23"), "Year X started on 23 september"); 95 | assert.equal(+new FlorealDate("1802-09-23").firstDayOfYear(), +new Date("1802-09-23"), "Year XI started on 23 september"); 96 | assert.equal(+new FlorealDate("1803-09-24").firstDayOfYear(), +new Date("1803-09-24"), "Year XII started on 24 september"); 97 | assert.equal(+new FlorealDate("1804-09-23").firstDayOfYear(), +new Date("1804-09-23"), "Year XIII started on 23 september"); 98 | assert.equal(+new FlorealDate("1805-09-23").firstDayOfYear(), +new Date("1805-09-23"), "Year XIV started on 23 september"); 99 | assert.equal(+new FlorealDate("1870-09-23").firstDayOfYear(), +new Date("1870-09-23"), "Year LXXIV started on 23 september"); 100 | assert.equal(+new FlorealDate("2013-09-22").firstDayOfYear(), +new Date("2013-09-22"), "Year CCXXII would have started on 22 september"); 101 | assert.equal(+new FlorealDate("2014-09-22").firstDayOfYear(), +new Date("2014-09-22"), "Year CCXXIII would have started on 22 september"); 102 | assert.equal(+new FlorealDate("2015-09-22").firstDayOfYear(), +new Date("2015-09-22"), "Year CCXXIV would have started on 22 september"); 103 | done(); 104 | }; 105 | 106 | exports['test dayOfYear'] = function(assert, done) { 107 | assert.equal(new FlorealDate("1792-09-22").dayOfYear(), 1, "The very first day of the calendar is correct"); 108 | assert.equal(new FlorealDate("1792-09-23").dayOfYear(), 2, "The second day is also correct"); 109 | assert.equal(new FlorealDate("1792-10-01").dayOfYear(), 10, "The first day of the second decade is also correct"); 110 | assert.equal(new FlorealDate("1793-10-22").dayOfYear(), 31, "The first day of the second month is the 31st of the year"); 111 | assert.equal(new FlorealDate("1793-02-19").dayOfYear(), 151, "The first day of the sixth month is the 151th of the year"); 112 | assert.equal(new FlorealDate("1793-03-21").dayOfYear(), 181, "The first day of the seventh month is the 181th of the year"); 113 | assert.equal(new FlorealDate("1793-04-20").dayOfYear(), 211, "The first day of the eighth month is the 211th of the year"); 114 | assert.equal(new FlorealDate("1793-05-20").dayOfYear(), 241, "The first day of the ninth month is the 241th of the year"); 115 | assert.equal(new FlorealDate("1793-06-19").dayOfYear(), 271, "The first day of the tenth month is the 271th of the year"); 116 | assert.equal(new FlorealDate("1793-09-21").dayOfYear(), 365, "The last day of year I is the 365th"); 117 | 118 | done(); 119 | }; 120 | 121 | exports['test month'] = function(assert, done) { 122 | assert.equal(new FlorealDate("1792-09-22").month(), 1, "The very first day of the calendar is in first month"); 123 | assert.equal(new FlorealDate("1792-09-23").month(), 1, "The second day is also in first month"); 124 | assert.equal(new FlorealDate("1792-10-01").month(), 1, "The first day of the second decade is also in first month"); 125 | assert.equal(new FlorealDate("1792-10-21").month(), 1, "The last day of first month is correct"); 126 | assert.equal(new FlorealDate("1793-10-22").month(), 2, "The first day of the second month is correct"); 127 | assert.equal(new FlorealDate("1793-02-19").month(), 6, "The first day of the sixth month is correct"); 128 | assert.equal(new FlorealDate("1793-03-21").month(), 7, "The first day of the seventh month is correct"); 129 | assert.equal(new FlorealDate("1793-04-20").month(), 8, "The first day of the eighth month is correct"); 130 | assert.equal(new FlorealDate("1793-05-20").month(), 9, "The first day of the ninth month is correct"); 131 | assert.equal(new FlorealDate("1793-06-19").month(), 10, "The first day of the tenth month is correct"); 132 | assert.equal(new FlorealDate("1793-09-17").month(), 13, "The last five days of year I are not parts of an actual month, but for regularisation purposes they are said to be part of month #13"); 133 | assert.equal(new FlorealDate("1793-09-18").month(), 13, "The last five days of year I are not parts of an actual month, but for regularisation purposes they are said to be part of month #13"); 134 | assert.equal(new FlorealDate("1793-09-19").month(), 13, "The last five days of year I are not parts of an actual month, but for regularisation purposes they are said to be part of month #13"); 135 | assert.equal(new FlorealDate("1793-09-20").month(), 13, "The last five days of year I are not parts of an actual month, but for regularisation purposes they are said to be part of month #13"); 136 | assert.equal(new FlorealDate("1793-09-21").month(), 13, "The last five days of year I are not parts of an actual month, but for regularisation purposes they are said to be part of month #13"); 137 | assert.equal(new FlorealDate("1803-09-23").month(), 13, "The last day of a sextile year is also part of complementary days"); 138 | 139 | done(); 140 | }; 141 | 142 | exports['test isComplementaryDay'] = function(assert, done) { 143 | assert.equal(new FlorealDate("1792-09-22").isComplementaryDay(), false, "The very first day of the calendar is not a complementary day"); 144 | assert.equal(new FlorealDate("1793-06-19").isComplementaryDay(), false, "The first day of the tenth month is still not a complementary day"); 145 | assert.equal(new FlorealDate("1793-09-17").isComplementaryDay(), true, "The last five days of year I are complementary days"); 146 | assert.equal(new FlorealDate("1793-09-18").isComplementaryDay(), true, "The last five days of year I are complementary days"); 147 | assert.equal(new FlorealDate("1793-09-19").isComplementaryDay(), true, "The last five days of year I are complementary days"); 148 | assert.equal(new FlorealDate("1793-09-20").isComplementaryDay(), true, "The last five days of year I are complementary days"); 149 | assert.equal(new FlorealDate("1793-09-21").isComplementaryDay(), true, "The last five days of year I are complementary days"); 150 | assert.equal(new FlorealDate("1803-09-23").isComplementaryDay(), true, "The last day of a sextile year is also a complementary day"); 151 | 152 | done(); 153 | }; 154 | 155 | exports['test monthName'] = function(assert, done) { 156 | assert.equal(new FlorealDate("1792-09-22").monthName(), "vendémiaire", "The very first day of the calendar is in first month"); 157 | assert.equal(new FlorealDate("1792-09-23").monthName(), "vendémiaire", "The second day is also in first month"); 158 | assert.equal(new FlorealDate("1792-10-01").monthName(), "vendémiaire", "The first day of the second decade is also in first month"); 159 | assert.equal(new FlorealDate("1793-10-22").monthName(), "brumaire", "The first day of the second month is correct"); 160 | assert.equal(new FlorealDate("1793-02-19").monthName(), "ventôse", "The first day of the sixth month is correct"); 161 | assert.equal(new FlorealDate("1793-03-21").monthName(), "germinal", "The first day of the seventh month is correct"); 162 | assert.equal(new FlorealDate("1793-04-20").monthName(), "floréal", "The first day of the eighth month is correct"); 163 | assert.equal(new FlorealDate("1793-05-20").monthName(), "prairial", "The first day of the ninth month is correct"); 164 | assert.equal(new FlorealDate("1793-06-19").monthName(), "messidor", "The first day of the tenth month is correct"); 165 | assert.equal(new FlorealDate("1793-09-17").monthName(), "", "The last five days of year I are not parts of an actual month"); 166 | assert.equal(new FlorealDate("1793-09-18").monthName(), "", "The last five days of year I are not parts of an actual month"); 167 | assert.equal(new FlorealDate("1793-09-19").monthName(), "", "The last five days of year I are not parts of an actual month"); 168 | assert.equal(new FlorealDate("1793-09-20").monthName(), "", "The last five days of year I are not parts of an actual month"); 169 | assert.equal(new FlorealDate("1793-09-21").monthName(), "", "The last five days of year I are not parts of an actual month"); 170 | assert.equal(new FlorealDate("1803-09-23").monthName(), "", "The last day of a sextile year is also part of complementary days"); 171 | 172 | done(); 173 | }; 174 | 175 | exports['test dayOfMonth'] = function(assert, done) { 176 | assert.equal(new FlorealDate("1792-09-22").day(), 1, "The very first day of the calendar is #1"); 177 | assert.equal(new FlorealDate("1792-09-23").day(), 2, "The second day is #2"); 178 | assert.equal(new FlorealDate("1792-10-01").day(), 10, "The last day of the first decade is #10"); 179 | assert.equal(new FlorealDate("1792-10-11").day(), 20, "The last day of the second decade is #20"); 180 | assert.equal(new FlorealDate("1792-10-21").day(), 30, "The last day of the third decade is #30"); 181 | assert.equal(new FlorealDate("1793-10-22").day(), 1, "The first day of the second month is #1"); 182 | assert.equal(new FlorealDate("1793-09-17").day(), 1, "The complementary days are correctly counted"); 183 | assert.equal(new FlorealDate("1793-09-18").day(), 2, "The complementary days are correctly counted"); 184 | assert.equal(new FlorealDate("1793-09-19").day(), 3, "The complementary days are correctly counted"); 185 | assert.equal(new FlorealDate("1793-09-20").day(), 4, "The complementary days are correctly counted"); 186 | assert.equal(new FlorealDate("1793-09-21").day(), 5, "The complementary days are correctly counted"); 187 | assert.equal(new FlorealDate("1803-09-23").day(), 6, "The complementary days are correctly counted"); 188 | 189 | assert.equal(FlorealDate.prototype.dayOfMonth, FlorealDate.prototype.day, "day() is an alias of dayOfMonth()"); 190 | 191 | done(); 192 | }; 193 | 194 | exports['test decade'] = function(assert, done) { 195 | assert.equal(new FlorealDate("1792-09-22").decade(), 1, "The very first day of the calendar is in first decade"); 196 | assert.equal(new FlorealDate("1792-09-23").decade(), 1, "The second day is still in first decade"); 197 | assert.equal(new FlorealDate("1792-10-01").decade(), 1, "The last day of the first decade is again in first decade"); 198 | assert.equal(new FlorealDate("1792-10-11").decade(), 2, "The last day of the second decade is correct"); 199 | assert.equal(new FlorealDate("1792-10-21").decade(), 3, "The last day of the third decade is correct"); 200 | assert.equal(new FlorealDate("1793-10-22").decade(), 1, "The first day of the second month is in first decade"); 201 | assert.equal(new FlorealDate("1793-09-17").decade(), 1, "The complementary days are not in any decade, but for regularisation purposes they are said to be part of decade 1"); 202 | assert.equal(new FlorealDate("1793-09-18").decade(), 1, "The complementary days are not in any decade, but for regularisation purposes they are said to be part of decade 1"); 203 | assert.equal(new FlorealDate("1793-09-19").decade(), 1, "The complementary days are not in any decade, but for regularisation purposes they are said to be part of decade 1"); 204 | assert.equal(new FlorealDate("1793-09-20").decade(), 1, "The complementary days are not in any decade, but for regularisation purposes they are said to be part of decade 1"); 205 | assert.equal(new FlorealDate("1793-09-21").decade(), 1, "The complementary days are not in any decade, but for regularisation purposes they are said to be part of decade 1"); 206 | assert.equal(new FlorealDate("1803-09-23").decade(), 1, "The complementary days are not in any decade, but for regularisation purposes they are said to be part of decade 1"); 207 | 208 | done(); 209 | }; 210 | 211 | exports['test dayOfDecade'] = function(assert, done) { 212 | assert.equal(new FlorealDate("1792-09-22").dayOfDecade(), 1, "The very first day of the calendar is first of the first decade"); 213 | assert.equal(new FlorealDate("1792-09-23").dayOfDecade(), 2, "The second day is #2"); 214 | assert.equal(new FlorealDate("1792-09-24").dayOfDecade(), 3, "The third day is #3"); 215 | assert.equal(new FlorealDate("1792-09-25").dayOfDecade(), 4, "The fourth day is #4"); 216 | assert.equal(new FlorealDate("1792-09-26").dayOfDecade(), 5, "The fifth day is #5"); 217 | assert.equal(new FlorealDate("1792-09-27").dayOfDecade(), 6, "The sixth day is #6"); 218 | assert.equal(new FlorealDate("1792-09-28").dayOfDecade(), 7, "The seventh day is #7"); 219 | assert.equal(new FlorealDate("1792-09-29").dayOfDecade(), 8, "The eighth day is #8"); 220 | assert.equal(new FlorealDate("1792-09-30").dayOfDecade(), 9, "The ninth day is #9"); 221 | assert.equal(new FlorealDate("1792-10-01").dayOfDecade(), 10, "The tenth day is #10"); 222 | assert.equal(new FlorealDate("1792-10-02").dayOfDecade(), 1, "The first day of second decade is #1"); 223 | assert.equal(new FlorealDate("1793-09-17").dayOfDecade(), 1, "The complementary days are not in any decade but still have numbers"); 224 | assert.equal(new FlorealDate("1793-09-18").dayOfDecade(), 2, "The complementary days are not in any decade but still have numbers"); 225 | assert.equal(new FlorealDate("1793-09-19").dayOfDecade(), 3, "The complementary days are not in any decade but still have numbers"); 226 | assert.equal(new FlorealDate("1793-09-20").dayOfDecade(), 4, "The complementary days are not in any decade but still have numbers"); 227 | assert.equal(new FlorealDate("1793-09-21").dayOfDecade(), 5, "The complementary days are not in any decade but still have numbers"); 228 | assert.equal(new FlorealDate("1803-09-23").dayOfDecade(), 6, "The complementary days are not in any decade but still have numbers"); 229 | 230 | assert.equal(FlorealDate.prototype.dayOfDecade, FlorealDate.prototype.dayOfWeek, "dayOfWeek() is an alias of dayOfDecade()"); 231 | 232 | done(); 233 | }; 234 | 235 | exports['test dayName'] = function(assert, done) { 236 | assert.equal(new FlorealDate("1792-09-22").dayName(), "primidi", "The very first day of the calendar is first of the first decade"); 237 | assert.equal(new FlorealDate("1792-09-23").dayName(), "duodi", "The second day is #2"); 238 | assert.equal(new FlorealDate("1792-09-24").dayName(), "tridi", "The third day is #3"); 239 | assert.equal(new FlorealDate("1792-09-25").dayName(), "quartidi", "The fourth day is #4"); 240 | assert.equal(new FlorealDate("1792-09-26").dayName(), "quintidi", "The fifth day is #5"); 241 | assert.equal(new FlorealDate("1792-09-27").dayName(), "sextidi", "The sixth day is #6"); 242 | assert.equal(new FlorealDate("1792-09-28").dayName(), "septidi", "The seventh day is #7"); 243 | assert.equal(new FlorealDate("1792-09-29").dayName(), "octidi", "The eighth day is #8"); 244 | assert.equal(new FlorealDate("1792-09-30").dayName(), "nonidi", "The ninth day is #9"); 245 | assert.equal(new FlorealDate("1792-10-01").dayName(), "décadi", "The tenth day is #10"); 246 | assert.equal(new FlorealDate("1792-10-02").dayName(), "primidi", "The first day of second decade is #1"); 247 | assert.equal(new FlorealDate("1793-09-17").dayName(), "jour de la vertu", "The complementary days have special names"); 248 | assert.equal(new FlorealDate("1793-09-18").dayName(), "jour du génie", "The complementary days have special names"); 249 | assert.equal(new FlorealDate("1793-09-19").dayName(), "jour du travail", "The complementary days have special names"); 250 | assert.equal(new FlorealDate("1793-09-20").dayName(), "jour de l'opinion", "The complementary days have special names"); 251 | assert.equal(new FlorealDate("1793-09-21").dayName(), "jour des récompenses", "The complementary days have special names"); 252 | assert.equal(new FlorealDate("1803-09-23").dayName(), "jour de la révolution", "The complementary days have special names"); 253 | 254 | done(); 255 | }; 256 | 257 | exports['test toFullDateString'] = function(assert, done) { 258 | assert.equal(new FlorealDate("1792-09-22").toFullDateString(), "1er vendémiaire, an I", "The very first day of the calendar is correctly formatted"); 259 | assert.equal(new FlorealDate("1803-09-23").toFullDateString(), "6e jour complémentaire, an XI", "Complementary days are correctly formatted"); 260 | 261 | done(); 262 | }; 263 | 264 | exports['test toShortDateString'] = function(assert, done) { 265 | assert.equal(new FlorealDate("1792-09-22").toShortDateString(), "01-01-I", "The very first day of the calendar is correctly formatted"); 266 | assert.equal(new FlorealDate("1803-09-23").toShortDateString(), "06-13-XI", "Complementary days are correctly formatted"); 267 | 268 | assert.equal(FlorealDate.prototype.toShortDateString, FlorealDate.prototype.toDateString, "toDateString() is an alias of toShortDateString()"); 269 | 270 | done(); 271 | }; 272 | 273 | exports['test dayTitle'] = function(assert, done) { 274 | assert.equal(FlorealDate.day_names.length, 360 + 1, "There are 360 days associated with objects"); 275 | assert.equal(FlorealDate.day_names[0], "", "The first one in the array is for padding"); 276 | 277 | assert.equal(new FlorealDate("1795-08-18").dayTitle(), "prune", "1er fructidor, an III is plum day"); 278 | assert.equal(new FlorealDate("1803-09-23").dayTitle(), "révolution", "6th complementary day of an XI is the day of revolution"); 279 | 280 | done(); 281 | }; 282 | 283 | exports['test setYear'] = function(assert, done) { 284 | assert.equal(new FlorealDate("1795-08-18").setYear("XVI").year(), "XVI", "Year was correctly set"); 285 | 286 | done(); 287 | }; 288 | 289 | exports['test setYearDecimal'] = function(assert, done) { 290 | assert.equal(new FlorealDate("1795-08-18").setYearDecimal(16).year(), "XVI", "Year was correctly set"); 291 | 292 | done(); 293 | }; 294 | 295 | exports['test setMonth'] = function(assert, done) { 296 | assert.equal(new FlorealDate("1795-08-18").setMonth(1).month(), 1, "Month was correctly set"); 297 | assert.equal(new FlorealDate("1795-08-18").setMonth(0).month(), 13, "Month #0 is complementary days"); 298 | assert.equal(new FlorealDate("1795-08-18").setMonth(13).month(), 13, "Month #13 is also complementary days"); 299 | 300 | done(); 301 | }; 302 | 303 | exports['test setDay'] = function(assert, done) { 304 | assert.equal(new FlorealDate("1795-08-18").setDay(1).dayOfMonth(), 1, "Day was correctly set"); 305 | assert.equal(new FlorealDate("1795-08-18").setDay(30).dayOfMonth(), 30, "Day was correctly set"); 306 | 307 | done(); 308 | }; 309 | 310 | exports['test setDate'] = function(assert, done) { 311 | assert.equal(new FlorealDate().setDate(11, 13, 6).toShortDateString(), "06-13-XI", "Date was correctly set"); 312 | assert.equal(new FlorealDate().setDate(223, 5, 7).toShortDateString(), "07-05-CCXXIII", "Date was correctly set"); 313 | 314 | done(); 315 | }; 316 | 317 | --------------------------------------------------------------------------------