├── .travis.yml ├── .gitignore ├── bower.json ├── package.json ├── .jshintrc ├── README.md ├── test.js ├── moment-ferie-fr.min.js └── moment-ferie-fr.js /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.10 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | 4 | *.log 5 | 6 | node_modules 7 | bower_components -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "moment-ferie-fr", 3 | "version": "0.2.0", 4 | "homepage": "https://github.com/DepthFrance/moment-ferie-fr", 5 | "description": "An extension to moment.js that handles working days in France", 6 | "main": "moment-ferie-fr.js", 7 | "ignore": [ 8 | "**/.*", 9 | "node_modules", 10 | "bower_components", 11 | "test", 12 | "tests" 13 | ], 14 | "dependencies": { 15 | "moment": "^2.4.0" 16 | } 17 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "moment-ferie-fr", 3 | "version": "0.2.0", 4 | "description": "An extension to moment.js that handles working days in France", 5 | "main": "moment-ferie-fr.js", 6 | "scripts": { 7 | "test": "node test.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/DepthFrance/moment-ferie-fr.git" 12 | }, 13 | "author": "damienlabat", 14 | "homepage": "https://github.com/DepthFrance/moment-ferie-fr", 15 | "dependencies": { 16 | "moment": "^2.4.0" 17 | }, 18 | "devDependencies": { 19 | "grunt": "~0.4.5", 20 | "grunt-release": "~0.7.0" 21 | }, 22 | "bugs": { 23 | "url": "https://github.com/DepthFrance/moment-ferie-fr/issues" 24 | }, 25 | "keywords": [ 26 | "moment", 27 | "ferie", 28 | "holiday", 29 | "france", 30 | "date" 31 | ], 32 | "license": "ISC" 33 | } 34 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | // http://www.jshint.com/docs/options/ 3 | // 4 | // == Enforcing options == 5 | "bitwise": true, 6 | // "camelcase": true, 7 | "curly": true, 8 | "eqeqeq": true, 9 | "es3": false, 10 | "forin": true, 11 | "freeze": true, 12 | "immed": true, 13 | // "indent": 2, 14 | //Does not work! 15 | // - Problem with switch case indentation (use the style of the first token found, but could be in node_modules files in Intellij (does not happen with command line) 16 | // - Problem with indentation of angular routes declaration 17 | "latedef": true, 18 | "newcap": false, 19 | "noarg": true, 20 | "noempty": true, 21 | "nonew": true, 22 | // "plusplus": true, 23 | "quotmark": "double", 24 | "undef": true, 25 | "unused": "vars", 26 | "strict": true, 27 | "trailing": true, 28 | // == Relaxing options == 29 | "sub": false, 30 | "esnext": false, 31 | // == Environments == 32 | "browser": true, 33 | "node": true, 34 | // == Global Variables == 35 | "globals": { 36 | "angular": false 37 | } 38 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Moment-ferie-fr [![Build Status](https://travis-ci.org/DepthFrance/moment-ferie-fr.svg?branch=master)](https://travis-ci.org/DepthFrance/moment-ferie-fr) 2 | ================================================== 3 | 4 | Plug-in [Moment.js][1] jours feriés en France 5 | 6 | 7 | exemple utilisation: 8 | ----------- 9 | 10 | var day = moment("9-6-2014", "DD-MM-YYYY"); 11 | 12 | console.log( day.isFerie() ); // boolean 13 | console.log( day.getFerie() ); // string, 'Pentecôte' 14 | 15 | console.log( day.getFerieList() ); // array, liste jours feriés de l'année de day 16 | console.log( moment().getFerieList(2018) ); // array, liste jours feriés de l'année 2018 17 | 18 | console.log( day.lundiDePaques() ); // momentObj, jour de paques de l'année de day 19 | console.log( moment().lundiDePaques(2018) ); // momentObj, jour de paques de l'année 2018 20 | 21 | /* 22 | idem pour: 23 | 24 | day.paques(); 25 | day.lundiDePaques(); 26 | day.ascension(); 27 | day.pentecote(); 28 | 29 | day.jourDeLAn(); 30 | day.feteDuTravail(); 31 | day.victoireDeAllies(); 32 | day.feteNationale(); 33 | day.assomption(); 34 | day.toussaint(); 35 | day.armistice(); 36 | day.noel(); 37 | */ 38 | 39 | 40 | [1]: http://momentjs.com/ 41 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var moment = require("./moment-ferie-fr"); 2 | var assert = require("assert"); 3 | 4 | var y2013 = moment("2013", "YYYY"); 5 | assert.equal(y2013.victoireDeAllies().format("DD/MM/YYYY"), "08/05/2013"); 6 | assert.equal(y2013.ascension().format("DD/MM/YYYY"), "09/05/2013"); 7 | assert.equal(y2013.pentecote().format("DD/MM/YYYY"), "20/05/2013"); 8 | 9 | var y2014 = moment("2014", "YYYY"); 10 | assert.equal(y2014.noel().format("DD/MM/YYYY"), "25/12/2014"); 11 | assert.equal(y2014.lundiDePaques().format("DD/MM/YYYY"), "21/04/2014"); 12 | assert.equal(y2014.ascension().format("DD/MM/YYYY"), "29/05/2014"); 13 | assert.equal(y2014.pentecote().format("DD/MM/YYYY"), "09/06/2014"); 14 | assert.equal(y2014.jourDeLAn().format("DD/MM/YYYY"), "01/01/2014"); 15 | assert.equal(y2014.feteDuTravail().format("DD/MM/YYYY"), "01/05/2014"); 16 | assert.equal(y2014.victoireDeAllies().format("DD/MM/YYYY"), "08/05/2014"); 17 | assert.equal(y2014.feteNationale().format("DD/MM/YYYY"), "14/07/2014"); 18 | assert.equal(y2014.assomption().format("DD/MM/YYYY"), "15/08/2014"); 19 | assert.equal(y2014.toussaint().format("DD/MM/YYYY"), "01/11/2014"); 20 | assert.equal(y2014.armistice().format("DD/MM/YYYY"), "11/11/2014"); 21 | 22 | assert.equal(moment().noel(2015).format("DD/MM/YYYY"), "25/12/2015"); 23 | assert.equal(moment().lundiDePaques(2015).format("DD/MM/YYYY"), "06/04/2015"); 24 | assert.equal(moment().ascension(2015).format("DD/MM/YYYY"), "14/05/2015"); 25 | assert.equal(moment().pentecote(2015).format("DD/MM/YYYY"), "25/05/2015"); 26 | assert.equal(moment().jourDeLAn(2015).format("DD/MM/YYYY"), "01/01/2015"); 27 | assert.equal(moment().feteDuTravail(2015).format("DD/MM/YYYY"), "01/05/2015"); 28 | assert.equal(moment().victoireDeAllies(2015).format("DD/MM/YYYY"), "08/05/2015"); 29 | assert.equal(moment().feteNationale(2015).format("DD/MM/YYYY"), "14/07/2015"); 30 | assert.equal(moment().assomption(2015).format("DD/MM/YYYY"), "15/08/2015"); 31 | assert.equal(moment().toussaint(2015).format("DD/MM/YYYY"), "01/11/2015"); 32 | assert.equal(moment().armistice(2015).format("DD/MM/YYYY"), "11/11/2015"); 33 | 34 | //console.log( moment("2015", "YYYY").getFerieList()); 35 | assert.equal(moment("2015", "YYYY").getFerieList()[0].name, "Jour de l\'an"); 36 | assert.equal(moment("2015", "YYYY").getFerieList()[0].date.format("DD/MM/YYYY"), "01/01/2015"); 37 | 38 | var day = moment("9-6-2014", "DD-MM-YYYY"); 39 | assert.equal(true, day.isFerie()); 40 | assert.equal(day.getFerie(), "Pentecôte"); 41 | 42 | //day : 09/06/14 is a Monday but is "ferie" 43 | assert.equal(false, day.isWorkingDay()); 44 | day.subtract(2, "days"); 45 | // now day is "saturday" 46 | assert.equal(false, day.isWorkingDay()); 47 | // go to "sunday" 48 | day.add(1, "days"); 49 | assert.equal(false, day.isWorkingDay()); 50 | //return to "tuesday" 51 | day.add(2, "days"); 52 | assert.equal(true, day.isWorkingDay()); 53 | 54 | process.exit(0); -------------------------------------------------------------------------------- /moment-ferie-fr.min.js: -------------------------------------------------------------------------------- 1 | (function(){"use strict";var initialize=function(moment){moment.fn.easterDay=moment.fn.paques=function(Y){if(Y===undefined){Y=this.year()} 2 | var a=Y%19;var b=Math.floor(Y/100);var c=Y%100;var d=Math.floor(b/4);var e=b%4;var f=Math.floor((b+8)/25);var g=Math.floor((b-f+1)/3);var h=(19*a+b-d-g+15)%30;var i=Math.floor(c/4);var k=c%4;var l=(32+2*e+2*i-h-k)%7;var m=Math.floor((a+11*h+22*l)/451);var n0=(h+l+7*m+114);var n=Math.floor(n0/31)-1;var p=n0%31+1;var date=new Date(Y,n,p);return moment(date)};moment.fn.lundiDePaques=function(Y){if(Y===undefined){Y=this.year()} 3 | return moment.fn.paques(Y).add(1,"days")};moment.fn.ascension=function(Y){if(Y===undefined){Y=this.year()} 4 | return moment.fn.paques(Y).add(39,"days")};moment.fn.pentecote=function(Y){if(Y===undefined){Y=this.year()} 5 | return moment.fn.paques(Y).add(50,"days")};moment.fn.jourDeLAn=function(Y){if(Y===undefined){Y=this.year()} 6 | return moment("1-1-"+Y,"DD-MM-YYYY")};moment.fn.feteDuTravail=function(Y){if(Y===undefined){Y=this.year()} 7 | return moment("1-5-"+Y,"DD-MM-YYYY")};moment.fn.victoireDeAllies=function(Y){if(Y===undefined){Y=this.year()} 8 | return moment("8-5-"+Y,"DD-MM-YYYY")};moment.fn.feteNationale=function(Y){if(Y===undefined){Y=this.year()} 9 | return moment("14-7-"+Y,"DD-MM-YYYY")};moment.fn.assomption=function(Y){if(Y===undefined){Y=this.year()} 10 | return moment("15-8-"+Y,"DD-MM-YYYY")};moment.fn.toussaint=function(Y){if(Y===undefined){Y=this.year()} 11 | return moment("1-11-"+Y,"DD-MM-YYYY")};moment.fn.armistice=function(Y){if(Y===undefined){Y=this.year()} 12 | return moment("11-11-"+Y,"DD-MM-YYYY")};moment.fn.noel=function(Y){if(Y===undefined){Y=this.year()} 13 | return moment("25-12-"+Y,"DD-MM-YYYY")};var listeFerie={"Jour de l'an":moment.fn.jourDeLAn,"Fête du travail":moment.fn.feteDuTravail,"Victoire des alliés":moment.fn.victoireDeAllies,"Fête Nationale":moment.fn.feteNationale,"Assomption":moment.fn.assomption,"Toussaint":moment.fn.toussaint,"Armistice":moment.fn.armistice,"Noël":moment.fn.noel,"Pâques":moment.fn.paques,"Lundi de Pâques":moment.fn.lundiDePaques,"Ascension":moment.fn.ascension,"Pentecôte":moment.fn.pentecote};moment.fn.getFerieList=function(Y){if(Y===undefined){Y=this.year()} 14 | var res=[];for(var key in listeFerie){if(listeFerie.hasOwnProperty(key)){res.push({name:key,date:listeFerie[key](Y)})}} 15 | return res};moment.fn.getFerie=function(){for(var key in listeFerie){if(listeFerie.hasOwnProperty(key)){if(this.isSame(listeFerie[key].call(this),'days')){return key}}} 16 | return null};moment.fn.isFerie=function(){return(this.getFerie()!==null)};moment.fn.isWeekEnd=function(){return(this.day()===0||this.day()===6)};moment.fn.isWorkingDay=function(){return(!this.isWeekEnd()&&!this.isFerie())};return moment};if(typeof define==="function"&&define.amd){define("moment-ferie-fr",["moment"],function(moment){return this.moment=initialize(moment)})}else if(typeof module!=="undefined"){module.exports=initialize(require("moment"))}else if(typeof window!=="undefined"&&window.moment){this.moment=initialize(this.moment)}}).call(this) -------------------------------------------------------------------------------- /moment-ferie-fr.js: -------------------------------------------------------------------------------- 1 | // https://github.com/damienlabat/moment-ferie-fr 2 | (function () { 3 | 4 | "use strict"; 5 | 6 | var initialize = function (moment) { 7 | 8 | // Source: http://techneilogy.blogspot.fr/2012/02/couple-of-years-ago-i-posted-source.html 9 | moment.fn.easterDay = moment.fn.paques = function (Y) { 10 | if (Y === undefined) { 11 | Y = this.year(); 12 | } 13 | var a = Y % 19; 14 | var b = Math.floor(Y / 100); 15 | var c = Y % 100; 16 | var d = Math.floor(b / 4); 17 | var e = b % 4; 18 | var f = Math.floor((b + 8) / 25); 19 | var g = Math.floor((b - f + 1) / 3); 20 | var h = (19 * a + b - d - g + 15) % 30; 21 | var i = Math.floor(c / 4); 22 | var k = c % 4; 23 | var l = (32 + 2 * e + 2 * i - h - k) % 7; 24 | var m = Math.floor((a + 11 * h + 22 * l) / 451); 25 | var n0 = (h + l + 7 * m + 114); 26 | var n = Math.floor(n0 / 31) - 1; 27 | var p = n0 % 31 + 1; 28 | var date = new Date(Y, n, p); 29 | return moment(date); 30 | }; 31 | 32 | moment.fn.lundiDePaques = function (Y) { 33 | if (Y === undefined) { 34 | Y = this.year(); 35 | } 36 | return moment.fn.paques(Y).add(1, "days"); 37 | }; 38 | 39 | moment.fn.ascension = function (Y) { 40 | if (Y === undefined) { 41 | Y = this.year(); 42 | } 43 | return moment.fn.paques(Y).add(39, "days"); 44 | }; 45 | 46 | moment.fn.pentecote = function (Y) { 47 | if (Y === undefined) { 48 | Y = this.year(); 49 | } 50 | return moment.fn.paques(Y).add(50, "days"); 51 | }; 52 | 53 | moment.fn.jourDeLAn = function (Y) { 54 | if (Y === undefined) { 55 | Y = this.year(); 56 | } 57 | return moment("1-1-" + Y, "DD-MM-YYYY"); 58 | }; 59 | 60 | moment.fn.feteDuTravail = function (Y) { 61 | if (Y === undefined) { 62 | Y = this.year(); 63 | } 64 | return moment("1-5-" + Y, "DD-MM-YYYY"); 65 | }; 66 | 67 | moment.fn.victoireDeAllies = function (Y) { 68 | if (Y === undefined) { 69 | Y = this.year(); 70 | } 71 | return moment("8-5-" + Y, "DD-MM-YYYY"); 72 | }; 73 | 74 | moment.fn.feteNationale = function (Y) { 75 | if (Y === undefined) { 76 | Y = this.year(); 77 | } 78 | return moment("14-7-" + Y, "DD-MM-YYYY"); 79 | }; 80 | 81 | moment.fn.assomption = function (Y) { 82 | if (Y === undefined) { 83 | Y = this.year(); 84 | } 85 | return moment("15-8-" + Y, "DD-MM-YYYY"); 86 | }; 87 | 88 | moment.fn.toussaint = function (Y) { 89 | if (Y === undefined) { 90 | Y = this.year(); 91 | } 92 | return moment("1-11-" + Y, "DD-MM-YYYY"); 93 | }; 94 | 95 | moment.fn.armistice = function (Y) { 96 | if (Y === undefined) { 97 | Y = this.year(); 98 | } 99 | return moment("11-11-" + Y, "DD-MM-YYYY"); 100 | }; 101 | 102 | moment.fn.noel = function (Y) { 103 | if (Y === undefined) { 104 | Y = this.year(); 105 | } 106 | return moment("25-12-" + Y, "DD-MM-YYYY"); 107 | }; 108 | 109 | var listeFerie = { 110 | "Jour de l'an": moment.fn.jourDeLAn, 111 | "Fête du travail": moment.fn.feteDuTravail, 112 | "Victoire des alliés": moment.fn.victoireDeAllies, 113 | "Fête Nationale": moment.fn.feteNationale, 114 | "Assomption": moment.fn.assomption, 115 | "Toussaint": moment.fn.toussaint, 116 | "Armistice": moment.fn.armistice, 117 | "Noël": moment.fn.noel, 118 | "Pâques": moment.fn.paques, 119 | "Lundi de Pâques": moment.fn.lundiDePaques, 120 | "Ascension": moment.fn.ascension, 121 | "Pentecôte": moment.fn.pentecote 122 | }; 123 | 124 | moment.fn.getFerieList = function (Y) { 125 | if (Y === undefined) { 126 | Y = this.year(); 127 | } 128 | 129 | var res = []; 130 | for (var key in listeFerie) { 131 | if (listeFerie.hasOwnProperty(key)) { 132 | res.push({name: key, date: listeFerie[key](Y) }); 133 | } 134 | } 135 | return res; 136 | }; 137 | 138 | moment.fn.getFerie = function () { 139 | for (var key in listeFerie) { 140 | if (listeFerie.hasOwnProperty(key)) { 141 | if (this.isSame(listeFerie[key].call(this), 'days')) { 142 | return key; 143 | } 144 | } 145 | } 146 | return null; 147 | }; 148 | 149 | moment.fn.isFerie = function () { 150 | return (this.getFerie() !== null); 151 | }; 152 | 153 | moment.fn.isWeekEnd = function () { 154 | return (this.day() === 0 || this.day() === 6); 155 | }; 156 | 157 | moment.fn.isWorkingDay = function () { 158 | return (!this.isWeekEnd() && !this.isFerie()); 159 | }; 160 | 161 | return moment; 162 | }; 163 | 164 | if (typeof define === "function" && define.amd) { 165 | define("moment-ferie-fr", ["moment"], function (moment) { 166 | return this.moment = initialize(moment); 167 | }); 168 | } else if (typeof module !== "undefined") { 169 | module.exports = initialize(require("moment")); 170 | } else if (typeof window !== "undefined" && window.moment) { 171 | this.moment = initialize(this.moment); 172 | } 173 | 174 | }).call(this); --------------------------------------------------------------------------------