Skip to content

Instantly share code, notes, and snippets.

@jamesgdahl jamesgdahl/RevDate.js forked from anonymous/RevDate.js
Last active Aug 27, 2019

Embed
What would you like to do?
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var RevDate = function RevDate(dateparse) {
_classCallCheck(this, RevDate);
var moment = new Date();
if (typeof dateparse !== 'undefined') {
moment = new Date(dateparse);
}
var raisin = new Date('22 Sep 1792');
var adjMoment = moment.getTime() - raisin.getTime();
var d = 86400000;
var leapAmt = 20925216;
var eqStart = 34284216; //offset
var now = Math.floor(adjMoment % d);
this.hours = Math.floor(now % d * 10 / d);
this.minutes = Math.floor(now % d * 10 % d * 100 / d);
this.seconds = Math.floor(now % d * 10 % d * 100 % d * 100 / d);
var days = Math.floor(adjMoment / d);
var yesterdays = days-1;
var unadjYears = Math.floor(days / 365);
var leapYears = Math.floor(((leapAmt*unadjYears)+eqStart)/d);
var yesterdayLeapYears = Math.floor(((leapAmt*Math.floor(yesterdays / 365))+eqStart)/d);
var isLeapDay = false;
this.years = Math.floor((days-leapYears)/365);
if(yesterdayLeapYears != leapYears) {
var isLeapDay = true;
}
this.yeardays = (days-leapYears)%365;
if(isLeapDay) {
this.yeardays++;
}
this.years++; // year starts as year 1
this.date = (this.yeardays % 30);
this.date++; // calendar starts on day 1
this.monthNum = Math.floor(this.yeardays / 30);
var monStrs = [
{fr: "Vendémiaire", en: "Vintnuary" },
{fr: "Brumaire", en: "Mistuary" },
{fr: "Frimaire", en: "Frostuary" },
{fr: "Nivôse", en: "Snowus" },
{fr: "Pluviôse", en: "Rainus" },
{fr: "Ventôse", en: "Windus" },
{fr: "Germinal", en: "Germinal" },
{fr: "Floréal", en: "Floweral" },
{fr: "Prairial", en: "Meadowal" },
{fr: "Messidor", en: "Harvestior" },
{fr: "Thermidor", en: "Heatior" },
{fr: "Fructidor", en: "Fruitior" },
{fr: "Sansculottides", en: "Proletarianides" }
];
this.month = monStrs[this.monthNum];
var dayStrs = [
{fr: "Raisin", en: "Grape"}, {fr: "Safran", en: "Saffron"}, {fr: "Châtaigne", en: "Chestnut"}, {fr: "Colchique", en: "Crocus"}, {fr: "Cheval", en: "Horse"}, {fr: "Balsamine", en: "Impatiens"}, {fr: "Carotte", en: "Carrot"}, {fr: "Amaranthe", en: "Amaranth"}, {fr: "Panais", en: "Parsnip"}, {fr: "Cuve", en: "Vat"},
{fr: "Pomme de terre", en: "Potato"}, {fr: "Immortelle", en: "Strawflower"}, {fr: "Potiron", en: "Winter squash"}, {fr: "Réséda", en: "Mignonette"}, {fr: "Âne", en: "Donkey"}, {fr: "Belle de nuit", en: "Four o'clock flower"}, {fr: "Citrouille", en: "Pumpkin"}, {fr: "Sarrasin", en: "Buckwheat"}, {fr: "Tournesol", en: "Sunflower"}, {fr: "Pressoir", en: "Wine-Press"},
{fr: "Chanvre", en: "Hemp"}, {fr: "Pêche", en: "Peach"}, {fr: "Navet", en: "Turnip"}, {fr: "Amaryllis", en: "Amaryllis"}, {fr: "Bœuf", en: "Ox"}, {fr: "Aubergine", en: "Eggplant"}, {fr: "Piment", en: "Chili pepper"}, {fr: "Tomate", en: "Tomato"}, {fr: "Orge", en: "Barley"}, {fr: "Tonneau", en: "Barrel"},
{fr: "Pomme", en: "Apple"}, {fr: "Céleri", en: "Celery"}, {fr: "Poire", en: "Pear"}, {fr: "Betterave", en: "Beetroot"}, {fr: "Oie", en: "Goose"}, {fr: "Héliotrope", en: "Heliotrope"}, {fr: "Figue", en: "Common fig"}, {fr: "Scorsonère", en: "Black Salsify"}, {fr: "Alisier", en: "Chequer Tree"}, {fr: "Charrue", en: "Plough"},
{fr: "Salsifis", en: "Salsify"}, {fr: "Mâcre", en: "Water chestnut"}, {fr: "Topinambour", en: "Jerusalem artichoke"}, {fr: "Endive", en: "Endive"}, {fr: "Dindon", en: "Turkey"}, {fr: "Chervis", en: "Skirret"}, {fr: "Cresson", en: "Watercress"}, {fr: "Dentelaire", en: "Leadworts"}, {fr: "Grenade", en: "Pomegranate"}, {fr: "Herse", en: "Harrow"},
{fr: "Bacchante", en: "Baccharis"}, {fr: "Azerole", en: "Azarole"}, {fr: "Garance", en: "Madder"}, {fr: "Orange", en: "Orange"}, {fr: "Faisan", en: "Pheasant"}, {fr: "Pistache", en: "Pistachio"}, {fr: "Macjonc", en: "Tuberous pea"}, {fr: "Coing", en: "Quince"}, {fr: "Cormier", en: "Service tree"}, {fr: "Rouleau", en: "Roller"},
{fr: "Raiponce", en: "Rampion"}, {fr: "Turneps", en: "Turnip"}, {fr: "Chicorée", en: "Chicory"}, {fr: "Nèfle", en: "Medlar"}, {fr: "Cochon", en: "Pig"}, {fr: "Mâche", en: "Lamb's lettuce"}, {fr: "Chou-fleur", en: "Cauliflower"}, {fr: "Miel", en: "Honey"}, {fr: "Genièvre", en: "Juniper"}, {fr: "Pioche", en: "Pickaxe"},
{fr: "Cire", en: "Wax"}, {fr: "Raifort", en: "Horseradish"}, {fr: "Cèdre", en: "Cedar tree"}, {fr: "Sapin", en: "Fir"}, {fr: "Chevreuil", en: "Roe deer"}, {fr: "Ajonc", en: "Gorse"}, {fr: "Cyprès", en: "Cypress Tree"}, {fr: "Lierre", en: "Ivy"}, {fr: "Sabine", en: "Savin Juniper"}, {fr: "Hoyau", en: "Grub-hoe"},
{fr: "Érable à sucre", en: "Sugar Maple"}, {fr: "Bruyère", en: "Heather"}, {fr: "Roseau", en: "Reed plant"}, {fr: "Oseille", en: "Sorrel"}, {fr: "Grillon", en: "Cricket"}, {fr: "Pignon", en: "Pine nut"}, {fr: "Liège", en: "Cork"}, {fr: "Truffe", en: "Truffle"}, {fr: "Olive", en: "Olive"}, {fr: "Pelle", en: "Shovel"},
{fr: "Tourbe", en: "Peat"}, {fr: "Houille", en: "Coal"}, {fr: "Bitume", en: "Bitumen"}, {fr: "Soufre", en: "Sulphur"}, {fr: "Chien", en: "Dog"}, {fr: "Lave", en: "Lava"}, {fr: "Terre végétale", en: "Topsoil"}, {fr: "Fumier", en: "Manure"}, {fr: "Salpêtre", en: "Saltpeter"}, {fr: "Fléau", en: "Flail"},
{fr: "Granit", en: "Granite"}, {fr: "Argile", en: "Clay"}, {fr: "Ardoise", en: "Slate"}, {fr: "Grès", en: "Sandstone"}, {fr: "Lapin", en: "Rabbit"}, {fr: "Silex", en: "Flint"}, {fr: "Marne", en: "Marl"}, {fr: "Pierre à chaux", en: "Limestone"}, {fr: "Marbre", en: "Marble"}, {fr: "Van", en: "Winnowing basket"},
{fr: "Pierre à plâtre", en: "Gypsum"}, {fr: "Sel", en: "Salt"}, {fr: "Fer", en: "Iron"}, {fr: "Cuivre", en: "Copper"}, {fr: "Chat", en: "Cat"}, {fr: "Étain", en: "Tin"}, {fr: "Plomb", en: "Lead"}, {fr: "Zinc", en: "Zinc"}, {fr: "Mercure", en: "Mercury"}, {fr: "Crible", en: "Sieve"},
{fr: "Lauréole", en: "Spurge-laurel"}, {fr: "Mousse", en: "Moss"}, {fr: "Fragon", en: "Butcher's Broom"}, {fr: "Perce-neige", en: "Snowdrop"}, {fr: "Taureau", en: "Bull"}, {fr: "Laurier-thym", en: "Laurustinus"}, {fr: "Amadouvier", en: "Tinder polypore"}, {fr: "Mézéréon", en: "Daphne mezereum"}, {fr: "Peuplier", en: "Poplar"}, {fr: "Coignée", en: "Axe"},
{fr: "Ellébore", en: "Hellebore"}, {fr: "Brocoli", en: "Broccoli"}, {fr: "Laurier", en: "Bay laurel"}, {fr: "Avelinier", en: "Filbert"}, {fr: "Vache", en: "Cow"}, {fr: "Buis", en: "Box Tree"}, {fr: "Lichen", en: "Lichen"}, {fr: "If", en: "Yew tree"}, {fr: "Pulmonaire", en: "Lungwort"}, {fr: "Serpette", en: "Billhook"},
{fr: "Thlaspi", en: "Pennycress"}, {fr: "Thimelé", en: "Rose Daphne"}, {fr: "Chiendent", en: "Couch grass"}, {fr: "Trainasse", en: "Common Knotgrass"}, {fr: "Lièvre", en: "Hare"}, {fr: "Guède", en: "Woad"}, {fr: "Noisetier", en: "Hazel"}, {fr: "Cyclamen", en: "Cyclamen"}, {fr: "Chélidoine", en: "Celandine"}, {fr: "Traîneau", en: "Sleigh"},
{fr: "Tussilage", en: "Coltsfoot"}, {fr: "Cornouiller", en: "Dogwood"}, {fr: "Violier", en: "Matthiola"}, {fr: "Troène", en: "Privet"}, {fr: "Bouc", en: "Billygoat"}, {fr: "Asaret", en: "Wild Ginger"}, {fr: "Alaterne", en: "Italian Buckthorn"}, {fr: "Violette", en: "Violet"}, {fr: "Marceau", en: "Goat Willow"}, {fr: "Bêche", en: "Spade"},
{fr: "Narcisse", en: "Narcissus"}, {fr: "Orme", en: "Elm"}, {fr: "Fumeterre", en: "Common fumitory"}, {fr: "Vélar", en: "Hedge mustard"}, {fr: "Chèvre", en: "Goat"}, {fr: "Épinard", en: "Spinach"}, {fr: "Doronic", en: "Doronicum"}, {fr: "Mouron", en: "Pimpernel"}, {fr: "Cerfeuil", en: "Chervil"}, {fr: "Cordeau", en: "Twine"},
{fr: "Mandragore", en: "Mandrake"}, {fr: "Persil", en: "Parsley"}, {fr: "Cochléaria", en: "Scurvy-grass"}, {fr: "Pâquerette", en: "Daisy"}, {fr: "Thon", en: "Tuna"}, {fr: "Pissenlit", en: "Dandelion"}, {fr: "Sylvie", en: "Wood Anemone"}, {fr: "Capillaire", en: "Maidenhair fern"}, {fr: "Frêne", en: "Ash tree"}, {fr: "Plantoir", en: "Dibber"},
{fr: "Primevère", en: "Primrose"}, {fr: "Platane", en: "Plane Tree"}, {fr: "Asperge", en: "Asparagus"}, {fr: "Tulipe", en: "Tulip"}, {fr: "Poule", en: "Hen"}, {fr: "Bette", en: "Chard"}, {fr: "Bouleau", en: "Birch"}, {fr: "Jonquille", en: "Daffodil"}, {fr: "Aulne", en: "Alder"}, {fr: "Couvoir", en: "Hatchery"},
{fr: "Pervenche", en: "Periwinkle"}, {fr: "Charme", en: "Hornbeam"}, {fr: "Morille", en: "Morel"}, {fr: "Hêtre", en: "Beech Tree"}, {fr: "Abeille", en: "Bee"}, {fr: "Laitue", en: "Lettuce"}, {fr: "Mélèze", en: "Larch"}, {fr: "Ciguë", en: "Hemlock"}, {fr: "Radis", en: "Radish"}, {fr: "Ruche", en: "Hive"},
{fr: "Gainier", en: "Judas tree"}, {fr: "Romaine", en: "Romaine lettuce"}, {fr: "Marronnier", en: "Horse chestnut"}, {fr: "Roquette", en: "Arugula or Rocket"}, {fr: "Pigeon", en: "Pigeon"}, {fr: "Lilas", en: "Lilac"}, {fr: "Anémone", en: "Anemone"}, {fr: "Pensée", en: "Pansy"}, {fr: "Myrtille", en: "Bilberry"}, {fr: "Greffoir", en: "Knife"},
{fr: "Rose", en: "Rose"}, {fr: "Chêne", en: "Oak Tree"}, {fr: "Fougère", en: "Fern"}, {fr: "Aubépine", en: "Hawthorn"}, {fr: "Rossignol", en: "Nightingale"}, {fr: "Ancolie", en: "Common Columbine"}, {fr: "Muguet", en: "Lily of the valley"}, {fr: "Champignon", en: "Button mushroom"}, {fr: "Hyacinthe", en: "Hyacinth"}, {fr: "Râteau", en: "Rake"},
{fr: "Rhubarbe", en: "Rhubarb"}, {fr: "Sainfoin", en: "Sainfoin"}, {fr: "Bâton d'or", en: "Wallflower"}, {fr: "Chamerisier", en: "Fan Palm tree"}, {fr: "Ver à soie", en: "Silkworm"}, {fr: "Consoude", en: "Comfrey"}, {fr: "Pimprenelle", en: "Salad burnet"}, {fr: "Corbeille d'or", en: "Basket of Gold"}, {fr: "Arroche", en: "Orache"}, {fr: "Sarcloir", en: "Garden hoe"},
{fr: "Statice", en: "Thrift"}, {fr: "Fritillaire", en: "Fritillary"}, {fr: "Bourrache", en: "Borage"}, {fr: "Valériane", en: "Valerian"}, {fr: "Carpe", en: "Carp"}, {fr: "Fusain", en: "Spindle", en: "shrub)"}, {fr: "Civette", en: "Chive"}, {fr: "Buglosse", en: "Bugloss"}, {fr: "Sénevé", en: "Wild mustard"}, {fr: "Houlette", en: "Shepherd's crook"},
{fr: "Luzerne", en: "Alfalfa"}, {fr: "Hémérocalle", en: "Daylily"}, {fr: "Trèfle", en: "Clover"}, {fr: "Angélique", en: "Angelica"}, {fr: "Canard", en: "Duck"}, {fr: "Mélisse", en: "Lemon balm"}, {fr: "Fromental", en: "Oat grass"}, {fr: "Martagon", en: "Martagon lily"}, {fr: "Serpolet", en: "Wild Thyme"}, {fr: "Faux", en: "Scythe"},
{fr: "Fraise", en: "Strawberry"}, {fr: "Bétoine", en: "Woundwort"}, {fr: "Pois", en: "Pea"}, {fr: "Acacia", en: "Acacia"}, {fr: "Caille", en: "Quail"}, {fr: "Œillet", en: "Carnation"}, {fr: "Sureau", en: "Elderberry"}, {fr: "Pavot", en: "Poppy plant"}, {fr: "Tilleul", en: "Linden or Lime tree"}, {fr: "Fourche", en: "Pitchfork"},
{fr: "Barbeau", en: "Cornflower"}, {fr: "Camomille", en: "Camomile"}, {fr: "Chèvrefeuille", en: "Honeysuckle"}, {fr: "Caille-lait", en: "Bedstraw"}, {fr: "Tanche", en: "Tench"}, {fr: "Jasmin", en: "Jasmine"}, {fr: "Verveine", en: "Verbena"}, {fr: "Thym", en: "Thyme"}, {fr: "Pivoine", en: "Peony"}, {fr: "Chariot", en: "Hand Cart"},
{fr: "Seigle", en: "Rye"}, {fr: "Avoine", en: "Oat"}, {fr: "Oignon", en: "Onion"}, {fr: "Véronique", en: "Speedwell"}, {fr: "Mulet", en: "Mule"}, {fr: "Romarin", en: "Rosemary"}, {fr: "Concombre", en: "Cucumber"}, {fr: "Échalote", en: "Shallot"}, {fr: "Absinthe", en: "Wormwood"}, {fr: "Faucille", en: "Sickle"},
{fr: "Coriandre", en: "Coriander"}, {fr: "Artichaut", en: "Artichoke"}, {fr: "Girofle", en: "Clove"}, {fr: "Lavande", en: "Lavender"}, {fr: "Chamois", en: "Chamois"}, {fr: "Tabac", en: "Tobacco"}, {fr: "Groseille", en: "Redcurrant"}, {fr: "Gesse", en: "Hairy Vetchling"}, {fr: "Cerise", en: "Cherry"}, {fr: "Parc", en: "Park"},
{fr: "Menthe", en: "Mint"}, {fr: "Cumin", en: "Cumin"}, {fr: "Haricot", en: "Bean"}, {fr: "Orcanète", en: "Alkanet"}, {fr: "Pintade", en: "Guinea fowl"}, {fr: "Sauge", en: "Sage Plant"}, {fr: "Ail", en: "Garlic"}, {fr: "Vesce", en: "Tare"}, {fr: "Blé", en: "Wheat"}, {fr: "Chalémie", en: "Shawm"},
{fr: "Épeautre", en: "Spelt"}, {fr: "Bouillon blanc", en: "Common mullein"}, {fr: "Melon", en: "Melon"}, {fr: "Ivraie", en: "Ryegrass"}, {fr: "Bélier", en: "Ram"}, {fr: "Prêle", en: "Horsetail"}, {fr: "Armoise", en: "Mugwort"}, {fr: "Carthame", en: "Safflower"}, {fr: "Mûre", en: "Blackberry"}, {fr: "Arrosoir", en: "Watering can"},
{fr: "Panic", en: "Switchgrass"}, {fr: "Salicorne", en: "Common Glasswort"}, {fr: "Abricot", en: "Apricot"}, {fr: "Basilic", en: "Basil"}, {fr: "Brebis", en: "Ewe"}, {fr: "Guimauve", en: "Marshmallow"}, {fr: "Lin", en: "Flax"}, {fr: "Amande", en: "Almond"}, {fr: "Gentiane", en: "Gentian"}, {fr: "Écluse", en: "Lock"},
{fr: "Carline", en: "Carline thistle"}, {fr: "Câprier", en: "Caper"}, {fr: "Lentille", en: "Lentil"}, {fr: "Aunée", en: "Inula"}, {fr: "Loutre", en: "Otter"}, {fr: "Myrte", en: "Myrtle"}, {fr: "Colza", en: "Rapeseed"}, {fr: "Lupin", en: "Lupin"}, {fr: "Coton", en: "Cotton"}, {fr: "Moulin", en: "Mill"},
{fr: "Prune", en: "Plum"}, {fr: "Millet", en: "Millet"}, {fr: "Lycoperdon", en: "Puffball"}, {fr: "Escourgeon", en: "Six-row Barley"}, {fr: "Saumon", en: "Salmon"}, {fr: "Tubéreuse", en: "Tuberose"}, {fr: "Sucrion", en: "Winter Barley"}, {fr: "Apocyn", en: "Apocynum"}, {fr: "Réglisse", en: "Liquorice"}, {fr: "Échelle", en: "Ladder"},
{fr: "Pastèque", en: "Watermelon"}, {fr: "Fenouil", en: "Fennel"}, {fr: "Épine vinette", en: "Barberry"}, {fr: "Noix", en: "Walnut"}, {fr: "Truite", en: "Trout"}, {fr: "Citron", en: "Lemon"}, {fr: "Cardère", en: "Teasel"}, {fr: "Nerprun", en: "Buckthorn"}, {fr: "Tagette", en: "Mexican Marigold"}, {fr: "Hotte", en: "Harvesting basket"},
{fr: "Églantier", en: "Wild Rose"}, {fr: "Noisette", en: "Hazelnut"}, {fr: "Houblon", en: "Hops"}, {fr: "Sorgho", en: "Sorghum"}, {fr: "Écrevisse", en: "Crayfish"}, {fr: "Bigarade", en: "Bitter orange"}, {fr: "Verge d'or", en: "Goldenrod"}, {fr: "Maïs", en: "Maize or Corn"}, {fr: "Marron", en: "Sweet Chestnut"}, {fr: "Panier", en: "Pack Basket"},
{fr: "la Vertu", en: "Virtue"}, {fr: "Génie", en: "Talent"}, {fr: "Travail", en: "Labour"}, {fr: "l'Opinion", en: "Convictions"}, {fr: "Récompenses", en: "Honors"}, {fr: "la Révolution", en: "Revolution"}
]
this.dateStr = dayStrs[this.yeardays];
var weekStrs = [
{fr:"Décadi", en:"Decaday"},
{fr:"Primidi", en: "Monaday"},
{fr:"Duodi", en: "Duoday"},
{fr:"Tridi", en: "Triday"},
{fr:"Quartidi", en: "Quadraday"},
{fr:"Quintidi", en: "Pentaday"},
{fr:"Sextidi", en: "Hexaday"},
{fr:"Septidi", en: "Heptaday"},
{fr:"Octidi", en: "Octaday"},
{fr:"Nonidi", en: "Nonaday"}
];
this.weekday = weekStrs[this.date % 10];
this.decade = Math.floor(this.yeardays / 10) + 1;
this.toString = function (lang) {
var langStr = "fr";
if(typeof lang !== 'undefined') {
langStr = lang;
}
var week = {fr: "décade", en: "week" }
return this.weekday[langStr] + " (" + this.dateStr[langStr] + "), " + this.date + " " + this.month[langStr] + " " + this.years + ", " + week[langStr] + " " + this.decade;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.