Author SHA1 Message Date
brausjonas dd6f08880a Function Status Bar and Time Validation 2023-06-18 11:29:06 +02:00
AlexE030 b3fb3b1b8f Added Status Bar for Admins
There are still some minor Bugs to fix, but it works
2023-06-16 22:38:19 +02:00
AlexE030 dc20f35fb8 Finished Status Bar
Submit-Validation not yet implemented
2023-06-16 16:49:21 +02:00
AlexE030 9024dbc26e Bugfix localStorage is not defined 2023-06-16 12:35:37 +02:00
AlexE030 05a6a3ee23 Zwischenpush 2023-06-16 12:13:20 +02:00
brausjonas c9f3efd7f9 Merge branch 'AlexUndMikeBranch' of https://github.com/DHBWLoerrach/TIF22A_AnwProjekt_B into AlexUndMikeBranch 2023-06-16 11:59:09 +02:00
brausjonas 7983e23815 Calender View Module and Semester names and Numbers are shown
Also in the Dashboard for Lecturers
2023-06-16 11:59:06 +02:00
AliGitGut 5446b2d1cb Input Form Bugfix
Kursname, Theorieanfang und Ende müssen nun gesetzt werden sonst kann kein Kurs angelegt werden
2023-06-16 11:48:34 +02:00
brausjonas 8205b7d9d9 Calender View Angepasst auf die Module ID eines Entries 2023-06-16 11:33:36 +02:00
brausjonas 53ac8ff0bf Merge Of Branches Multiselect 2023-06-16 10:33:04 +02:00
AlexE030 e436e61041 Added Status Check 2023-06-16 10:02:57 +02:00
87 changed files with 575576 additions and 10132 deletions

No files matched your search

Vendored
BIN
View File
Binary file not shown.
-12
View File
@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
-16
View File
@@ -1,16 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="CssUnknownProperty" enabled="true" level="WARNING" enabled_by_default="true">
<option name="myCustomPropertiesEnabled" value="true" />
<option name="myIgnoreVendorSpecificProperties" value="false" />
<option name="myCustomPropertiesList">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="font-color" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>
-6
View File
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<includedPredefinedLibrary name="Node.js Core" />
</component>
</project>
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/anwendungsprojekt.iml" filepath="$PROJECT_DIR$/.idea/anwendungsprojekt.iml" />
</modules>
</component>
</project>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

-4
View File
@@ -1,4 +0,0 @@
# TIF22A_AnwProjekt_B
Team B im Anwendungsprojekt (TIF22A)
Website can be accessed under: http://lectureplanner.de/ (caution no https, only http)
-5
View File
@@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
+9
View File
@@ -9,6 +9,7 @@
"version": "0.1.0",
"dependencies": {
"autoprefixer": "10.4.14",
"feiertagejs": "^1.3.9",
"next": "13.3.4",
"postcss": "8.4.23",
"react": "18.2.0",
@@ -530,6 +531,14 @@
"reusify": "^1.0.4"
}
},
"node_modules/feiertagejs": {
"version": "1.3.9",
"resolved": "https://registry.npmjs.org/feiertagejs/-/feiertagejs-1.3.9.tgz",
"integrity": "sha512-tUP+WBv2OWBhPwe3NfqwCtjMq+ym598a42tfqmL0FySswEb9xs96p2iKwqqx+lxKieu1njJBRZKsFm92bJhxZw==",
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
+1
View File
@@ -10,6 +10,7 @@
},
"dependencies": {
"autoprefixer": "10.4.14",
"feiertagejs": "^1.3.9",
"next": "13.3.4",
"postcss": "8.4.23",
"react": "18.2.0",
File diff suppressed because it is too large. Load diff
+28 -21
View File
@@ -34,23 +34,29 @@ export default function InputForm(p) {
useEffect(() => {
let base = baseURL + "/semester/id?sessionid=" + localStorage.getItem("sessionid") + "&id=" + localStorage.getItem("currentsid")
fetch(base).then(r => r.json()).then(j => {
setCourseName(j.name)
setTimeout(() => {
update = false;
baseMapping = []
let tempStartDate = new Date(parseInt(j.startyear), 0, parseInt(j.startday))
let tempEndDate = new Date(parseInt(j.endyear), 0, parseInt(j.endday))
let base = baseURL + "/semester/id?sessionid=" + localStorage.getItem("sessionid") + "&id=" + localStorage.getItem("currentsid")
fetch(base).then(r => r.json()).then(j => {
setStartDate(tempStartDate.getFullYear() + "-" + ((tempStartDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempStartDate.getDate().toString().padStart(2, "0"))
setEndDate(tempEndDate.getFullYear() + "-" + ((tempEndDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempEndDate.getDate().toString().padStart(2, "0"))
tempSemesterNumber = j.number
setSemesterNumber(j.number)
setSemesterNumber(j.number)
tempSemesterNumber = j.number
}).then(() => {
readModules()
update = true
}).catch(() => readModules())
setCourseName(j.name)
let tempStartDate = new Date(parseInt(j.startyear), 0, parseInt(j.startday))
let tempEndDate = new Date(parseInt(j.endyear), 0, parseInt(j.endday))
setStartDate(tempStartDate.getFullYear() + "-" + ((tempStartDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempStartDate.getDate().toString().padStart(2, "0"))
setEndDate(tempEndDate.getFullYear() + "-" + ((tempEndDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempEndDate.getDate().toString().padStart(2, "0"))
}).then(() => {
readModules()
update = true
}).catch(() => readModules())
}, 100)
}, [])
@@ -103,9 +109,9 @@ export default function InputForm(p) {
setIsChecked(temp)
setIsActivated(temp2)
}).then(() => {
setModulesSelectorValues(modulesDummy[tempSemesterNumber])
})
}).then(() => {
setModulesSelectorValues(modulesDummy[tempSemesterNumber])
})
}
@@ -260,13 +266,12 @@ export default function InputForm(p) {
userModulesMapping[i].semesterid = semesterID
setTimeout(() => {
console.log(userModulesMapping[i])
fetch(baseURL + "/module?sessionid=" + localStorage.getItem("sessionid"), {
method: userModulesMapping[i].id === -1 ? "POST" : "PUT",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(userModulesMapping[i])
})
}, i * 100)
}, i * 200)
}
})
@@ -280,7 +285,7 @@ export default function InputForm(p) {
<div className={"box-shadow input-form round-border"}>
<p>Kursname</p>
<input type={"text"} className={"box-shadow round-border"} style={{padding: 8, width: "100%"}}
<input type={"text"} className={"box-shadow round-border"} style={{padding: 8, width: "100%", backgroundColor: (courseName == "") ? "#E44747" : "white"}}
onChange={e => onCourseNameChange(e)} value={courseName}/>
<div style={{display: "flex", justifyContent: "flex-start", gap: 40}}>
@@ -288,9 +293,11 @@ export default function InputForm(p) {
<p>Theorie Ende</p>
</div>
<div style={{display: "flex", justifyContent: "flex-start", gap: 20}}>
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8}}
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8, backgroundColor: (startDate == "" || startDate >= endDate) ? "#E44747" : "white"
}}
onChange={e => onStartDateChange(e)} value={startDate}/>
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8}}
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8, backgroundColor: (endDate == "" || startDate >= endDate) ? "#E44747" : "white"
}}
onChange={e => onEndDateChange(e)} value={endDate}/>
</div>
@@ -353,7 +360,7 @@ export default function InputForm(p) {
gap: 10
}}>
<Button text={"Abbrechen"} onClick={onButtonAbort}/>
<Button text={"Speichern"} color={"#77932b"} onClick={onButtonSave}/>
<Button text={"Speichern"} color={"#77932b"} onClick={() => { (startDate == "" || endDate == ""|| startDate >= endDate || courseName == "") ? () => {} : onButtonSave()}}/>
</div>
</div>
</>
+2 -1
View File
@@ -9,7 +9,8 @@ export default function PopUp(p) {
return (
<>
<div style={{
display: p.displayState
display: p.displayState,
zIndex: 1000
}}>
<div className={"modal-container"}>
@@ -1,8 +1,4 @@
import StatusBar from "@/components/StatusBar";
import React, {useEffect} from "react";
import Button from "@/components/Button";
import {deleteItem, editItem} from "@/components/Icons";
export default function SemesterTile(p)
{
let editable = true;
+3 -1
View File
@@ -1,4 +1,6 @@
import React from "react"
import React, {useState} from "react"
import {baseURL} from "@/components/Constants";
import {console} from "next/dist/compiled/@edge-runtime/primitives/console";
export default function StatusBar(p)
{
-21
View File
@@ -1,21 +0,0 @@
import Button from "@/components/Button";
import { baseURL } from "@/components/Constants";
import {useRouter} from "next/router";
export default function SubmitButton() {
const router = useRouter();
return (
<div
style={{
position: "absolute",
right: 70,
bottom: 20,
borderBottomRightRadius: 10,
}}
>
<Button onClick={() => router.push("/submit")} text={"Abgeben"} color={"#77932b"} width={100} height={40} />
</div>
);
}
@@ -1,56 +0,0 @@
import {baseURL} from "@/components/Constants";
import Button from "@/components/Button";
export default function SubmitWarning(p){
async function submit() {
let url = baseURL + "/module?sessionid=" + localStorage.getItem("sessionid");
let json1 = {
"id": 0,
"userid": localStorage.getItem("userid"),
"semesterid": localStorage.getItem("currentsid"),
"name": localStorage.getItem("currentmodulename"),
"activated": 0
}
await fetch(url, {
method: "PUT",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(json1)
})
p.onClick();
p.onClick();
}
return (
<div className="box-shadow" style={{
position: "absolute",
top: 300,
left: 0,
right: 0,
borderRadius: 5,
textAlign: "center",
fontSize: 20,
margin: "auto",
width: 600
}}>
<p style={{paddingTop: 20, paddingBottom: 5}}>Möchten Sie wirklich abgeben?</p>
<p>Danach können Sie keine Änderungen mehr vornehmen!</p>
<div style={{
display: "flex",
flexDirection: "row",
justifyContent: "center",
paddingTop: 40,
paddingBottom: 20
}}>
<Button onClick={() => submit()} text={"Bestätigen"} color={"#77932b"} width={100} height={40} />
<div style={{width: 20}}></div>
<Button onClick={() => p.onClick()} text={"Abbrechen"} color={"red"} width={100} height={40} />
</div>
</div>
)
}
+8 -3
View File
@@ -5,21 +5,26 @@ import Back from "@/components/Back";
import BasicDateCalendar from "@/components/CalendarSideBar";
import {useRouter} from "next/router";
import HelpButton from "@/components/HelpButton";
import SubmitButton from "@/components/SubmitButton";
export default function planning(p)
{
let router = useRouter()
let semesterName;
if (typeof window !== 'undefined'){
semesterName = localStorage.getItem("semestername") + " " + (localStorage.getItem("admin") == 1 ? "" : localStorage.getItem("currentmodulename"))
}
return (
<div className={"normal-centered"}>
<Logout/>
<Back onClick={() => router.back()}/>
<HelpButton/>
<Background/>
<CalenderView/>
<SubmitButton />
<CalenderView semesterName={semesterName}/>
</div>
)
}
+86 -15
View File
@@ -12,12 +12,76 @@ import StatusBar from "@/components/StatusBar";
import {deleteItem, editItem} from "@/components/Icons";
export default function SemesterOverview(p) {
async function getSemesters() {
const [progresses, setProgresses] = useState([])
async function getSemesters(set) {
let urlTest = baseURL + "/semester/all?sessionid=" + localStorage.getItem("sessionid");
let allSemesters
let allModules
let allEntries
await fetch(urlTest).then(response => response.json()).then(s => {
setEntries(s)
allSemesters = s
if (set) {
setEntries(s)
}
}).then(() => {
if(!set)
{
fetch(baseURL + "/module/all?sessionid=" + localStorage.getItem("sessionid")).then(r => r.json()).then(mod => {
allModules = mod
}).then(() => {
fetch(baseURL + "/entries/all?sessionid=" + localStorage.getItem("sessionid")).then(r => r.json()).then(en => {
allEntries = en
}).then(() => {
let modulesCountInSemester = []
for (let i = 0; i < allSemesters.length; i++) {
let count = 0
for (let j = 0; j < allModules.length; j++) {
if (allSemesters[i].id === allModules[j].semesterid) {
count++;
}
}
modulesCountInSemester.push(count)
}
let temp = []
for (let s = 0; s < allSemesters.length; s++) {
let count = 0;
for (let i = 0; i < allModules.length; i++) {
if (allModules[i].semesterid === allSemesters[s].id) {
let sum = 0
let ent = allEntries.filter(e => e.moduleid === allModules[i].id)
for (let j = 0; j < ent.length; j++) {
sum += ent[j].timeend - ent[j].timestart
}
sum /= 3
if (sum >= 20 && allModules[i].activated === 0) {
count++;
}
}
}
if (count === 0) {
temp.push(0)
} else if (count >= 1 && count !== modulesCountInSemester[s]) {
temp.push(50)
} else {
temp.push(100)
}
setProgresses(temp)
}
})
})
}
})
}
@@ -26,6 +90,7 @@ export default function SemesterOverview(p) {
if (m.target === m.currentTarget) {
localStorage.setItem("currentsid", e.id)
router.push("/planning")
localStorage.setItem("semestername", e.name + " Sem. " + (e.number + 1))
}
}
@@ -56,7 +121,7 @@ export default function SemesterOverview(p) {
});
togglePopup();
getSemesters();
getSemesters(true);
}
async function funcButtonEdit(e, m) {
@@ -80,13 +145,18 @@ export default function SemesterOverview(p) {
endDate: endDate.toISOString().slice(0, 10)
},
});
getSemesters();
}
useEffect(() => {
getSemesters();
getSemesters(true);
}, [])
useEffect(() => {
setTimeout(() => {
getSemesters(false)
}, 1000)
})
const [entries, setEntries] = useState([])
@@ -100,22 +170,23 @@ export default function SemesterOverview(p) {
<HelpButton/>
<Background/>
{
entries.map(e => (
entries.map((e, index) => (
<div className={"semester-tile box-shadow"} onClick={(f) => onClickSemester(e, f)}>
<SemesterTile text={e.name} onClick={(f) => onClickSemester(e, f)} onButtonDeleteClick={() => {
localStorage.setItem("currentsid", e.id)
setModalHint(e.name + " Löschen?");
togglePopup();
}} onButtonEditClick={(m) => {
<SemesterTile text={e.name + " Sem. " + (e.number + 1)} onClick={(f) => onClickSemester(e, f)}
onButtonDeleteClick={() => {
localStorage.setItem("currentsid", e.id)
setModalHint(e.name + " Löschen?");
togglePopup();
}} onButtonEditClick={(m) => {
localStorage.setItem("currentsid", e.id)
funcButtonEdit(e, m);
}}/>
<StatusBar progress={0}/>
<StatusBar progress={progresses[index]}/>
<div style={
{
display:"flex",
justifyContent:"center",
alignItems:"center"
display: "flex",
justifyContent: "center",
alignItems: "center"
}
}>
<Button icon={deleteItem} width={30} height={30} color={"#ffffff"}
@@ -8,6 +8,9 @@ import HelpButton from "@/components/HelpButton";
import StatusBar from "@/components/StatusBar";
export default function SemesteroverviewLecturer(p) {
const [timeStamps, setTimeStamps] = useState([])
function getModules() {
let urlTest = baseURL + "/module/id?sessionid=" + localStorage.getItem("sessionid");
@@ -26,19 +29,43 @@ export default function SemesteroverviewLecturer(p) {
let semesterURL = baseURL + "/semester/id/all?ids=" + args + "&sessionid=" + localStorage.getItem("sessionid");
fetch(semesterURL).then(r => r.json()).then(sem => {
sem.map(e => {
temp.push(e.name)
temp.push(e.name + " Sem. " + (e.number + 1))
})
}).then(() => setSemesterNames(temp))
}).then(() => setSemesterNames(temp)).then(() => {
let entriesURL = baseURL + "/entries/all?sessionid=" + localStorage.getItem("sessionid")
fetch(entriesURL).then(r => r.json()).then(en => {
let tempTimeStamps = []
for(let j = 0; j < m.length; j++)
{
let sum = 0
let currentModule = m[j]
for (let i = 0; i < en.length; i++)
{
if(currentModule.id === en[i].moduleid)
{
sum += en[i].timeend - en[i].timestart
}
}
sum /= 3
tempTimeStamps.push(sum)
}
setTimeStamps(tempTimeStamps)
})
})
})
}
function onClickSemester(e, m) {
function onClickSemester(e, m, name) {
if (e.activated == 1) {
if (m.target === m.currentTarget) {
localStorage.setItem("currentsid", e.semesterid)
localStorage.setItem("currentmodulename", e.name)
localStorage.setItem("moduleid", e.id)
localStorage.setItem("semestername", name)
router.push("/planning")
}
}
@@ -46,13 +73,32 @@ export default function SemesteroverviewLecturer(p) {
useEffect(() => {
getModules();
setTimeout(() => {
getModules();
}, 1000)
}, [])
const [entries, setEntries] = useState([]);
const [semesterNames, setSemesterNames] = useState([]);
const router = useRouter();
function getProgressForTime(time, activated)
{
console.log(activated)
if(time === 0)
{
return 0
}
else if( 20 >= time > 0 && activated === 1)
{
return 50
}
else if(time >= 20 && activated === 0)
{
return 100
}
}
return (
<div className={"semester-overview"}>
@@ -62,12 +108,12 @@ export default function SemesteroverviewLecturer(p) {
{entries.map((e, index) => (
<div className={"semester-tile box-shadow"} style={{
backgroundColor: e.activated == 1 ? "#ffffff" : "#aaaaaa"
}} onClick={(f) => onClickSemester(e, f)}>
}} onClick={(f) => onClickSemester(e, f, semesterNames[index])}>
<SemesterTile
editable={false} text={semesterNames[index]} text2={e.name}
onClick={(f) => onClickSemester(e, f)}
onClick={(f) => onClickSemester(e, f, semesterNames[index])}
/>
<StatusBar progress={0}/>
<StatusBar progress={getProgressForTime(timeStamps[index], e.activated)} module={e}/>
</div>
))}
</div>
-19
View File
@@ -1,19 +0,0 @@
import Logout from "@/components/Logout";
import SubmitWarning from "@/components/SubmitWarning";
import Back from "@/components/Back";
import {useRouter} from "next/router";
import Background from "@/components/Background";
export default function Submit(){
const router = useRouter();
return(
<div>
<Background />
<Logout />
<SubmitWarning onClick={() => router.back()}/>
<Back onClick={() => router.back()}/>
</div>
)
}
+2 -1
View File
@@ -183,6 +183,7 @@ Step Progress Bar
color: white;
font-weight: bold;
pointer-events: none;
z-index: 101;
}
.steps .not-started {
@@ -213,7 +214,7 @@ Step Progress Bar
position: absolute;
height: 8px;
background-color: #5d606e;
z-index: -1;
z-index: 100;
}
/*
-33
View File
@@ -1,33 +0,0 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
+3
View File
@@ -3,3 +3,6 @@
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="backend" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="backend" options="-parameters" />
</option>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
</component>
</project>
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK" />
</project>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
Binary file not shown.
+574607 -7075
View File
File diff suppressed because it is too large. Load diff
@@ -42,13 +42,17 @@ public class DataBaseHandler {
/**
* ENTRIES
*/
public void addEntry(Entry entry) {
try {
st.executeUpdate("insert into entries (daynumber, yearnumber, semesterid, usercreatedbyid, timestart, timeend, info) values (" +
public void addEntry(Entry entry)
{
try
{
st.executeUpdate("insert into entries (daynumber, yearnumber, semesterid, usercreatedbyid, timestart, timeend, moduleid, info) values (" +
entry.getDaynumber() + ", " + entry.getYearnumber() + ", " + entry.getSemesterid() + ", " +
entry.getUsercreatedbyid() + ", " + entry.getTimestart() + ", " + entry.getTimeend() + ", '" + entry.getInfo() + "')"
entry.getUsercreatedbyid() + ", " + entry.getTimestart() + ", " + entry.getTimeend() + ", " + entry.getModuleid() + " ,'" + entry.getInfo() + "')"
);
} catch (Exception e) {
}
catch(Exception e)
{
e.printStackTrace();
}
}
@@ -114,22 +118,44 @@ public class DataBaseHandler {
}
}
public Entry[] getAllEntries(int semesterid, int userid) {
public Entry[] getAllEntries()
{
try {
ResultSet rs = st.executeQuery("select * from entries where " +
"semesterid=" + semesterid +
" and usercreatedbyid=" + userid);
ResultSet rs = st.executeQuery("select * from entries");
List<Entry> entriestate = new ArrayList<>();
Entry current = null;
while ((current = resultSetToEntry(rs)) != null) {
Entry current = null;
while((current = resultSetToEntry(rs)) != null)
{
entriestate.add(current);
}
return entriestate.toArray(new Entry[0]);
} catch (Exception e) {
}catch (Exception e){
System.out.println(e.getMessage());
return null;
}
}
public Entry[] getAllEntriesModule(int moduleid)
{
try {
ResultSet rs = st.executeQuery("select * from entries where moduleid=" + moduleid);
List<Entry> result = new ArrayList<>();
Entry current = null;
while((current = resultSetToEntry(rs)) != null)
{
result.add(current);
}
return result.toArray(new Entry[0]);
}
catch(Exception e)
{
return new Entry[]{};
}
}
public void deleteEntry(int id) {
try {
st.executeUpdate("delete from entries where id=" + id);
@@ -146,8 +172,10 @@ public class DataBaseHandler {
}
}
public Entry resultSetToEntry(ResultSet rs) {
try {
public Entry resultSetToEntry(ResultSet rs)
{
try
{
rs.next();
return new Entry(
rs.getInt("id"),
@@ -157,9 +185,12 @@ public class DataBaseHandler {
rs.getInt("timestart"),
rs.getInt("timeend"),
rs.getInt("semesterid"),
rs.getInt("moduleid"),
rs.getString("info")
);
} catch (Exception e) {
}
catch(Exception e)
{
return null;
}
}
@@ -232,8 +263,8 @@ public class DataBaseHandler {
public void deleteSemester(int id) {
try {
st.executeUpdate("DELETE FROM modules WHERE semesterid=" + id);
st.executeUpdate("delete from semester where id=" + id);
st.executeUpdate("delete from entries where semesterid=" + id);
} catch (Exception e) {
}
@@ -332,16 +363,29 @@ public class DataBaseHandler {
st.executeUpdate("update modules set activated=" + m.getActivated() + ", semesterid=" + m.getsemesterid() + ", name='" + m.getName() + "' where id=" + m.getid());
return null;
return getModule(m.getid());
} catch (SQLException ex) {
ex.printStackTrace();
return null;
}
}
public void submitModule(int id)
{
try
{
st.executeUpdate("update modules set activated=0 where id=" + id);
}
catch(Exception e)
{
}
}
public boolean deleteModule(int id) {
try {
st.executeUpdate("delete from modules where id=" + id);
st.executeUpdate("delete from entries where moduleid=" + id);
return true;
} catch (Exception ex) {
return false;
@@ -10,9 +10,10 @@ public class Entry
private int timestart;
private int timeend;
private int semesterid;
private int moduleid;
private String info;
public Entry(int id, int daynumber, int yearnumber, int usercreatedbyid, int timestart, int timeend, int semesterid, String info)
public Entry(int id, int daynumber, int yearnumber, int usercreatedbyid, int timestart, int timeend, int semesterid, int moduleid, String info)
{
this.id = id;
this.daynumber = daynumber;
@@ -21,6 +22,7 @@ public class Entry
this.timestart = timestart;
this.timeend = timeend;
this.semesterid = semesterid;
this.moduleid = moduleid;
this.info = info;
}
@@ -59,6 +61,8 @@ public class Entry
return semesterid;
}
public int getModuleid() {return moduleid;}
public String getInfo()
{
return info;
@@ -59,23 +59,49 @@ public class EntriesController
}
@CrossOrigin
@GetMapping("/entries/planned")
public ResponseEntity<Integer[]> getEntries(@RequestParam(name = "semesterid") int semesterid,
@RequestParam(name = "sessionid") String sessionid)
@GetMapping("/entries/all")
public ResponseEntity<Entry[]> getAllEntries(@RequestParam(name = "sessionid") String sessionid)
{
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
if (sessionUser != null)
{
var entries = db.getAllEntries(semesterid, sessionUser.getId());
var count = 0;
for (int i = 0; i < entries.length; i++) {
count += entries[i].getTimeend()-entries[i].getTimestart();
}
return new ResponseEntity<>(new Integer[]{count}, HttpStatus.OK);
var entries = db.getAllEntries();
return new ResponseEntity<>(entries, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
@CrossOrigin
@GetMapping("/entries/all/module")
public ResponseEntity<Entry[]> getAllEntriesModule(@RequestParam(name="sessionid") String sessionid, @RequestParam(name="moduleid") int moduleid)
{
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
if (sessionUser != null)
{
return new ResponseEntity<>(db.getAllEntriesModule(moduleid), HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
// @CrossOrigin
// @GetMapping("/entries")
// public ResponseEntity<Integer[]> getEntries(@RequestParam(name = "semesterid") int semesterid,
// @RequestParam(name = "sessionid") String sessionid)
// {
// User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
// if (sessionUser != null)
// {
// var entries = db.getAllEntries(semesterid, sessionUser.getId());
// var count = 0;
// for (int i = 0; i < entries.length; i++) {
// count += entries[i].getTimeend()-entries[i].getTimestart();
// }
// return new ResponseEntity<>(new Integer[]{count}, HttpStatus.OK);
// }
// return new ResponseEntity<>(HttpStatus.FORBIDDEN);
// }
/**
POST
A new entry to the database. Every user except of admins is allowed
@@ -99,6 +99,7 @@ public class ModuleController
return null;
}
/**
POST
a new module entry. (When a user is selected in a semester.)
@@ -143,13 +144,27 @@ public class ModuleController
{
return new ResponseEntity<>(m, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
@CrossOrigin
@PutMapping("/module/submit")
public ResponseEntity<Module> submitModule(@RequestParam(name="sessionid") String sessionID, @RequestParam(name="id") int id)
{
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
if (u != null)
{
db.submitModule(id);
return new ResponseEntity<>(null, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
/**
DELETE
Delete A Module
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
@@ -0,0 +1,3 @@
artifactId=backend
groupId=com.example
version=0.0.1-SNAPSHOT
@@ -0,0 +1,17 @@
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\controller\EntriesController.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\discard\WeekController.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\BackendApplication.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\controller\ModuleController.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\Users\UserSessionIDHandler.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\controller\UserController.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\discard\Week\Week.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\discard\Encryption\RSA.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\Users\User.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\Semesters\Semester.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\Users\UserPermissions.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\discard\Days\Day.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\controller\SemesterController.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\Entries\Entry.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\Module\Module.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\discard\DayController.java
D:\DH\TIF22A_AnwProjekt_B\backend\src\main\java\com\example\backend\anwprj\Database\DataBaseHandler.java
@@ -0,0 +1 @@
com\example\backend\BackendApplicationTests.class
@@ -0,0 +1 @@
D:\DH\TIF22A_AnwProjekt_B\backend\src\test\java\com\example\backend\BackendApplicationTests.java
@@ -0,0 +1,14 @@
# Created at 2023-06-07T22:11:58.299
System.exit() or native command error interrupted process checker.
java.lang.IllegalStateException: error [STOPPED] to read process 132
at org.apache.maven.surefire.booter.PpidChecker.checkProcessInfo(PpidChecker.java:145)
at org.apache.maven.surefire.booter.PpidChecker.isProcessAlive(PpidChecker.java:116)
at org.apache.maven.surefire.booter.ForkedBooter$2.run(ForkedBooter.java:214)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1623)
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="com.example.backend.BackendApplicationTests" time="3.552" tests="1" errors="0" skipped="0" failures="0">
<properties>
<property name="java.specification.version" value="20"/>
<property name="sun.cpu.isalist" value="amd64"/>
<property name="sun.jnu.encoding" value="Cp1252"/>
<property name="java.class.path" value="D:\DH\TIF22A_AnwProjekt_B\backend\target\test-classes;D:\DH\TIF22A_AnwProjekt_B\backend\target\classes;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-web\3.0.6\spring-boot-starter-web-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter\3.0.6\spring-boot-starter-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot\3.0.6\spring-boot-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\3.0.6\spring-boot-autoconfigure-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.0.6\spring-boot-starter-logging-3.0.6.jar;C:\Users\braus\.m2\repository\ch\qos\logback\logback-classic\1.4.7\logback-classic-1.4.7.jar;C:\Users\braus\.m2\repository\ch\qos\logback\logback-core\1.4.7\logback-core-1.4.7.jar;C:\Users\braus\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.19.0\log4j-to-slf4j-2.19.0.jar;C:\Users\braus\.m2\repository\org\apache\logging\log4j\log4j-api\2.19.0\log4j-api-2.19.0.jar;C:\Users\braus\.m2\repository\org\slf4j\jul-to-slf4j\2.0.7\jul-to-slf4j-2.0.7.jar;C:\Users\braus\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\braus\.m2\repository\org\yaml\snakeyaml\1.33\snakeyaml-1.33.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-json\3.0.6\spring-boot-starter-json-3.0.6.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.14.2\jackson-databind-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.2\jackson-annotations-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.14.2\jackson-core-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.14.2\jackson-datatype-jdk8-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.14.2\jackson-datatype-jsr310-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.14.2\jackson-module-parameter-names-2.14.2.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\3.0.6\spring-boot-starter-tomcat-3.0.6.jar;C:\Users\braus\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.8\tomcat-embed-core-10.1.8.jar;C:\Users\braus\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.8\tomcat-embed-el-10.1.8.jar;C:\Users\braus\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.8\tomcat-embed-websocket-10.1.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-web\6.0.8\spring-web-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-beans\6.0.8\spring-beans-6.0.8.jar;C:\Users\braus\.m2\repository\io\micrometer\micrometer-observation\1.10.6\micrometer-observation-1.10.6.jar;C:\Users\braus\.m2\repository\io\micrometer\micrometer-commons\1.10.6\micrometer-commons-1.10.6.jar;C:\Users\braus\.m2\repository\org\springframework\spring-webmvc\6.0.8\spring-webmvc-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-aop\6.0.8\spring-aop-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-context\6.0.8\spring-context-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-expression\6.0.8\spring-expression-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-test\3.0.6\spring-boot-starter-test-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-test\3.0.6\spring-boot-test-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-test-autoconfigure\3.0.6\spring-boot-test-autoconfigure-3.0.6.jar;C:\Users\braus\.m2\repository\com\jayway\jsonpath\json-path\2.7.0\json-path-2.7.0.jar;C:\Users\braus\.m2\repository\net\minidev\json-smart\2.4.10\json-smart-2.4.10.jar;C:\Users\braus\.m2\repository\net\minidev\accessors-smart\2.4.9\accessors-smart-2.4.9.jar;C:\Users\braus\.m2\repository\org\ow2\asm\asm\9.3\asm-9.3.jar;C:\Users\braus\.m2\repository\org\slf4j\slf4j-api\2.0.7\slf4j-api-2.0.7.jar;C:\Users\braus\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\4.0.0\jakarta.xml.bind-api-4.0.0.jar;C:\Users\braus\.m2\repository\jakarta\activation\jakarta.activation-api\2.1.1\jakarta.activation-api-2.1.1.jar;C:\Users\braus\.m2\repository\org\assertj\assertj-core\3.23.1\assertj-core-3.23.1.jar;C:\Users\braus\.m2\repository\net\bytebuddy\byte-buddy\1.12.23\byte-buddy-1.12.23.jar;C:\Users\braus\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\braus\.m2\repository\org\junit\jupiter\junit-jupiter\5.9.2\junit-jupiter-5.9.2.jar;C:\Users\braus\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.9.2\junit-jupiter-api-5.9.2.jar;C:\Users\braus\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\braus\.m2\repository\org\junit\platform\junit-platform-commons\1.9.2\junit-plLine truncated
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="sun.arch.data.model" value="64"/>
<property name="user.variant" value=""/>
<property name="java.vendor.url" value="https://java.oracle.com/"/>
<property name="user.timezone" value="Europe/Berlin"/>
<property name="os.name" value="Windows 10"/>
<property name="java.vm.specification.version" value="20"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="user.country" value="DE"/>
<property name="sun.boot.library.path" value="C:\Program Files\Java\jdk-20\bin"/>
<property name="sun.java.command" value="C:\Users\braus\AppData\Local\Temp\surefire15225856924068768135\surefirebooter10166169173719473359.jar C:\Users\braus\AppData\Local\Temp\surefire15225856924068768135 2023-06-09T22-50-22_049-jvmRun1 surefire10641026690989140399tmp surefire_017224228111119904739tmp"/>
<property name="jdk.debug" value="release"/>
<property name="surefire.test.class.path" value="D:\DH\TIF22A_AnwProjekt_B\backend\target\test-classes;D:\DH\TIF22A_AnwProjekt_B\backend\target\classes;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-web\3.0.6\spring-boot-starter-web-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter\3.0.6\spring-boot-starter-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot\3.0.6\spring-boot-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\3.0.6\spring-boot-autoconfigure-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.0.6\spring-boot-starter-logging-3.0.6.jar;C:\Users\braus\.m2\repository\ch\qos\logback\logback-classic\1.4.7\logback-classic-1.4.7.jar;C:\Users\braus\.m2\repository\ch\qos\logback\logback-core\1.4.7\logback-core-1.4.7.jar;C:\Users\braus\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.19.0\log4j-to-slf4j-2.19.0.jar;C:\Users\braus\.m2\repository\org\apache\logging\log4j\log4j-api\2.19.0\log4j-api-2.19.0.jar;C:\Users\braus\.m2\repository\org\slf4j\jul-to-slf4j\2.0.7\jul-to-slf4j-2.0.7.jar;C:\Users\braus\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\braus\.m2\repository\org\yaml\snakeyaml\1.33\snakeyaml-1.33.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-json\3.0.6\spring-boot-starter-json-3.0.6.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.14.2\jackson-databind-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.2\jackson-annotations-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.14.2\jackson-core-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.14.2\jackson-datatype-jdk8-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.14.2\jackson-datatype-jsr310-2.14.2.jar;C:\Users\braus\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.14.2\jackson-module-parameter-names-2.14.2.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\3.0.6\spring-boot-starter-tomcat-3.0.6.jar;C:\Users\braus\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.8\tomcat-embed-core-10.1.8.jar;C:\Users\braus\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.8\tomcat-embed-el-10.1.8.jar;C:\Users\braus\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.8\tomcat-embed-websocket-10.1.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-web\6.0.8\spring-web-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-beans\6.0.8\spring-beans-6.0.8.jar;C:\Users\braus\.m2\repository\io\micrometer\micrometer-observation\1.10.6\micrometer-observation-1.10.6.jar;C:\Users\braus\.m2\repository\io\micrometer\micrometer-commons\1.10.6\micrometer-commons-1.10.6.jar;C:\Users\braus\.m2\repository\org\springframework\spring-webmvc\6.0.8\spring-webmvc-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-aop\6.0.8\spring-aop-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-context\6.0.8\spring-context-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\spring-expression\6.0.8\spring-expression-6.0.8.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-starter-test\3.0.6\spring-boot-starter-test-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-test\3.0.6\spring-boot-test-3.0.6.jar;C:\Users\braus\.m2\repository\org\springframework\boot\spring-boot-test-autoconfigure\3.0.6\spring-boot-test-autoconfigure-3.0.6.jar;C:\Users\braus\.m2\repository\com\jayway\jsonpath\json-path\2.7.0\json-path-2.7.0.jar;C:\Users\braus\.m2\repository\net\minidev\json-smart\2.4.10\json-smart-2.4.10.jar;C:\Users\braus\.m2\repository\net\minidev\accessors-smart\2.4.9\accessors-smart-2.4.9.jar;C:\Users\braus\.m2\repository\org\ow2\asm\asm\9.3\asm-9.3.jar;C:\Users\braus\.m2\repository\org\slf4j\slf4j-api\2.0.7\slf4j-api-2.0.7.jar;C:\Users\braus\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\4.0.0\jakarta.xml.bind-api-4.0.0.jar;C:\Users\braus\.m2\repository\jakarta\activation\jakarta.activation-api\2.1.1\jakarta.activation-api-2.1.1.jar;C:\Users\braus\.m2\repository\org\assertj\assertj-core\3.23.1\assertj-core-3.23.1.jar;C:\Users\braus\.m2\repository\net\bytebuddy\byte-buddy\1.12.23\byte-buddy-1.12.23.jar;C:\Users\braus\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\braus\.m2\repository\org\junit\jupiter\junit-jupiter\5.9.2\junit-jupiter-5.9.2.jar;C:\Users\braus\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.9.2\junit-jupiter-api-5.9.2.jar;C:\Users\braus\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\braus\.m2\repository\org\junit\platform\junit-platform-commons\1.9.2Line truncated
<property name="sun.cpu.endian" value="little"/>
<property name="user.home" value="C:\Users\braus"/>
<property name="user.language" value="de"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.version.date" value="2023-03-21"/>
<property name="java.home" value="C:\Program Files\Java\jdk-20"/>
<property name="file.separator" value="\"/>
<property name="basedir" value="D:\DH\TIF22A_AnwProjekt_B\backend"/>
<property name="java.vm.compressedOopsMode" value="Zero based"/>
<property name="line.separator" value="&#10;"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="surefire.real.class.path" value="C:\Users\braus\AppData\Local\Temp\surefire15225856924068768135\surefirebooter10166169173719473359.jar"/>
<property name="user.script" value=""/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="java.runtime.version" value="20+36-2344"/>
<property name="user.name" value="braus"/>
<property name="stdout.encoding" value="Cp1252"/>
<property name="path.separator" value=";"/>
<property name="os.version" value="10.0"/>
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
<property name="localRepository" value="C:\Users\braus\.m2\repository"/>
<property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/>
<property name="java.io.tmpdir" value="C:\Users\braus\AppData\Local\Temp\"/>
<property name="idea.version" value="2023.1"/>
<property name="java.version" value="20"/>
<property name="user.dir" value="D:\DH\TIF22A_AnwProjekt_B\backend"/>
<property name="os.arch" value="amd64"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="sun.os.patch.level" value=""/>
<property name="native.encoding" value="Cp1252"/>
<property name="java.library.path" value="C:\Program Files\Java\jdk-20\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\VMware\VMware Player\bin\;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet\;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\swipl\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\resources\bin;C:\Users\braus\AppData\Local\Microsoft\WindowsApps;C:\Users\braus\AppData\Local\GitHubDesktop\bin;C:\Users\braus\AppData\Local\JetBrains\Toolbox\scripts;C:\Users\braus\.dotnet\tools;C:\Users\braus\AppData\Local\gitkraken\bin;C:\Users\braus\AppData\Roaming\npm;."/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="stderr.encoding" value="Cp1252"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="java.vm.version" value="20+36-2344"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="64.0"/>
</properties>
<testcase name="contextLoads" classname="com.example.backend.BackendApplicationTests" time="0.649"/>
</testsuite>
@@ -0,0 +1,4 @@
-------------------------------------------------------------------------------
Test set: com.example.backend.BackendApplicationTests
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.552 s - in com.example.backend.BackendApplicationTests
-15
View File
@@ -1,15 +0,0 @@
{
"name": "TIF22A_AnwProjekt_B",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/feiertagejs": {
"version": "1.3.9",
"resolved": "https://registry.npmjs.org/feiertagejs/-/feiertagejs-1.3.9.tgz",
"integrity": "sha512-tUP+WBv2OWBhPwe3NfqwCtjMq+ym598a42tfqmL0FySswEb9xs96p2iKwqqx+lxKieu1njJBRZKsFm92bJhxZw==",
"engines": {
"node": ">=8.0.0"
}
}
}
}
-22
View File
@@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Simon Fakir
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-93
View File
@@ -1,93 +0,0 @@
# Feiertage.js
[![npm version](https://badge.fury.io/js/feiertagejs.svg)](https://badge.fury.io/js/feiertagejs)
[![Build Status](https://travis-ci.org/sfakir/feiertagejs.svg?branch=master)](https://travis-ci.org/sfakir/feiertagejs)
Feiertage.js is a small *typescript* npm module without dependencies to calculate German holidays for each Bundesland.
## Installation
- [yarn](https://yarnpkg.com/en/): `yarn add feiertagejs`
- [npm](https://www.npmjs.com/): `npm install feiertagejs`
- [bower](https://bower.io/): `bower install feiertagejs` *outdated!*
- [Plain Javascript](http://extern.fakir.it/feiertagejs/feiertagejs.zip) *outdated!*
## Quick Examples
### ES Modules (Typescript/Javasript)
The prefered whay is to directly import the typescript module. However, you can also use .js.
Please find here some examples and full api [here](docs.md).
```javascript
import { getHolidays, isHoliday, isSpecificHoliday } from 'feiertagejs';
const today = new Date();
console.log(isHoliday(today, 'BW'));
// probably false, because you are working ;)
// check if a day is a specific holiday:
console.log(isSpecificHoliday(today, 'CHRISTIHIMMELFAHRT','ALL'));
// get all holiday for a single year: getHolidays()
// returns an array of "Holiday" Objects. Please see the docs.md for all properties.
const holidays2023 = getHolidays('2023','BUND');
console.log('date', holidays2023[0].date); // = Date("2023-01-01");
console.log('name', holidays2023[0].name); // 'NEUJAHRSTAG' (constant)
console.log('translation', holidays2023[0].trans('de')); // German translation: Neujahrstag
console.log('equals?', holidays2023[0].equals(date)); // Compare days only (ignore time)
```
### Usage in Node.js
```javascript
var feiertagejs = require('feiertagejs');
var today = new Date();
console.log(feiertagejs.isHoliday(today, 'BW'));
// probably false, because you are working ;)
// check if a day is a specific holiday:
console.log(feiertagejs.isSpecificHoliday(today, 'CHRISTIHIMMELFAHRT'));
// get all holiday for a single year: getHolidays()
// returns an array of "Holiday" Objects. Please see the docs.md for all properties.
var holidays2023 = feiertagejs.getHolidays('2023', 'BUND');
console.log('date', holidays2023[0].date); // = Date("2023-01-01");
console.log('name', holidays2023[0].name); // 'NEUJAHRSTAG' (constant)
console.log('translation', holidays2023[0].translate()); // German translation: Neujahrstag
console.log('equals?', holidays2023[0].equals(date)); // Compare days only (ignore time)
```
## API doc
The full API doc can be found [here](docs.md).
## Feedback and Questions
You have two options two give feedback or ask questions:
* Comment the official release [post](https://fakir.tech/de/feiertage-js-deutsche-feiertage-fuer-node-js-und-browser-javascript/)
* Open issues or pullrequests on [github](https://github.com/sfakir/feiertagejs)
## Contributors
Thank you for contributing:
* thetric
* SteveOswald
## Feedback
If you have any questions, feel free to open an issue.
-476
View File
@@ -1,476 +0,0 @@
const germanTranslations = {
NEUJAHRSTAG: 'Neujahrstag',
HEILIGEDREIKOENIGE: 'Heilige Drei Könige',
KARFREITAG: 'Karfreitag',
OSTERSONNTAG: 'Ostersonntag',
OSTERMONTAG: 'Ostermontag',
TAG_DER_ARBEIT: 'Tag der Arbeit',
CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',
PFINGSTSONNTAG: 'Pfingstsonntag',
PFINGSTMONTAG: 'Pfingstmontag',
FRONLEICHNAM: 'Fronleichnam',
MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',
DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',
REFORMATIONSTAG: 'Reformationstag',
ALLERHEILIGEN: 'Allerheiligen',
BUBETAG: 'Buß- und Bettag',
ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',
ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',
WELTKINDERTAG: 'Weltkindertag',
WELTFRAUENTAG: 'Weltfrauentag',
AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',
};
const allHolidays = [
'NEUJAHRSTAG',
'HEILIGEDREIKOENIGE',
'KARFREITAG',
'OSTERSONNTAG',
'OSTERMONTAG',
'TAG_DER_ARBEIT',
'CHRISTIHIMMELFAHRT',
'MARIAHIMMELFAHRT',
'PFINGSTSONNTAG',
'PFINGSTMONTAG',
'FRONLEICHNAM',
'DEUTSCHEEINHEIT',
'REFORMATIONSTAG',
'ALLERHEILIGEN',
'BUBETAG',
'ERSTERWEIHNACHTSFEIERTAG',
'ZWEITERWEIHNACHTSFEIERTAG',
'WELTKINDERTAG',
'WELTFRAUENTAG',
'AUGSBURGER_FRIEDENSFEST',
];
const allRegions = [
'BW',
'BY',
'BE',
'BB',
'HB',
'HE',
'HH',
'MV',
'NI',
'NW',
'RP',
'SL',
'SN',
'ST',
'SH',
'TH',
'BUND',
'AUGSBURG',
'ALL',
];
/*!
* feiertage.js
* @repository https://github.com/sfakir/feiertagejs
* @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md
*
* Copyright 2015-2021 Simon Fakir
* Released under the MIT license
*/
// translations
const defaultLanguage = 'de';
let currentLanguage = defaultLanguage;
const translations = {
de: germanTranslations,
};
/**
* adds a translation for the holidays (e.g. english).
* This also allows to override the German names.
* Hint: Interpolates German for missing translations
* @param {string} isoCode of the new language
* @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg
*/
function addTranslation(isoCode, newTranslation) {
const code = isoCode.toLowerCase();
const defaultTranslation = translations[defaultLanguage];
let missingFields = false;
// fill new Translation with default Language
for (const holiday of allHolidays) {
if (!newTranslation[holiday]) {
missingFields = true;
newTranslation[holiday] = defaultTranslation[holiday];
}
}
if (missingFields) {
console.warn('[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback');
}
translations[code] = newTranslation;
}
/**
* Set a language to default language
* @param {string} isoCode
*/
function setLanguage(isoCode) {
const code = isoCode.toLowerCase();
if (!translations[code]) {
throw new TypeError(`[feiertagejs] tried to set language to ${code} but the translation is missing. Please use addTranslation(isoCode,object) first`);
}
currentLanguage = isoCode;
}
/**
* Get currently set language
* @returns {string}
*/
function getLanguage() {
return currentLanguage;
}
// holidays api
/**
* Checks if a specific date is sunday or holiday.
* @param date
* @param region
* @returns {boolean}
*/
function isSunOrHoliday(date, region) {
checkRegion(region);
return date.getDay() === 0 || isHoliday(date, region);
}
/**
* Check is specific date is holiday.
* @param date
* @param {Region} region two character {@link Region} code
* @returns {boolean}
*/
function isHoliday(date, region) {
checkRegion(region);
const year = date.getFullYear();
const internalDate = toUtcTimestamp(date);
const holidays = getHolidaysAsUtcTimestamps(year, region);
return holidays.indexOf(internalDate) !== -1;
}
function getHolidayByDate(date, region = 'ALL') {
checkRegion(region);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
return holidays.find((holiday) => holiday.equals(date));
}
// additional runtime checks
/**
* Checks if the given region is a valid {@link Region}.
*
* @param region {@link Region} to check
* @throws {Error}
* @private
*/
function checkRegion(region) {
if (region === null || region === undefined) {
throw new Error(`Region must not be undefined or null`);
}
if (allRegions.indexOf(region) === -1) {
throw new Error(`Invalid region: ${region}! Must be one of ${allRegions.toString()}`);
}
}
/**
* Checks if the given holidayName is a valid {@link HolidayType}.
* @param holidayName {@link HolidayType} to check
* @throws {Error}
* @private
*/
function checkHolidayType(holidayName) {
if (holidayName === null || holidayName === undefined) {
throw new TypeError('holidayName must not be null or undefined');
}
if (allHolidays.indexOf(holidayName) === -1) {
throw new Error(`feiertage.js: invalid holiday type "${holidayName}"! Must be one of ${allHolidays.toString()}`);
}
}
function isSpecificHoliday(date, holidayName, region = 'ALL') {
checkRegion(region);
checkHolidayType(holidayName);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
const foundHoliday = holidays.find((holiday) => holiday.equals(date));
if (!foundHoliday) {
return false;
}
return foundHoliday.name === holidayName;
}
/**
* Returns all holidays of a year in a {@link Region}.
* @param year
* @param region
* @returns {Array.<Holiday>}
*/
function getHolidays(year, region) {
let y;
if (typeof year === 'string') {
y = parseInt(year, 10);
}
else {
y = year;
}
checkRegion(region);
return getHolidaysOfYear(y, region);
}
/**
*
* @param {number} year
* @param region
* @returns {number[]}
* @private
*/
function getHolidaysAsUtcTimestamps(year, region) {
const holidays = getHolidaysOfYear(year, region);
return holidays.map((holiday) => toUtcTimestamp(holiday.date));
}
/**
*
* @param {number} year
* @param region
* @returns {{objects: Array.<Holiday>, integers}}
* @private
*/
function getHolidaysOfYear(year, region) {
const easterDate = getEasterDate(year);
const karfreitag = addDays(new Date(easterDate.getTime()), -2);
const ostermontag = addDays(new Date(easterDate.getTime()), 1);
const christiHimmelfahrt = addDays(new Date(easterDate.getTime()), 39);
const pfingstsonntag = addDays(new Date(easterDate.getTime()), 49);
const pfingstmontag = addDays(new Date(easterDate.getTime()), 50);
const holidays = [
...getCommonHolidays(year),
newHoliday('KARFREITAG', karfreitag),
newHoliday('OSTERMONTAG', ostermontag),
newHoliday('CHRISTIHIMMELFAHRT', christiHimmelfahrt),
newHoliday('PFINGSTMONTAG', pfingstmontag),
];
addHeiligeDreiKoenige(year, region, holidays);
addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, holidays);
addFronleichnam(region, easterDate, holidays);
addMariaeHimmelfahrt(year, region, holidays);
addReformationstag(year, region, holidays);
addAllerheiligen(year, region, holidays);
addBussUndBetttag(year, region, holidays);
addWeltkindertag(year, region, holidays);
addWeltfrauenTag(year, region, holidays);
addRegionalHolidays(year, region, holidays);
return holidays.sort((a, b) => a.date.getTime() - b.date.getTime());
}
function getCommonHolidays(year) {
return [
newHoliday('NEUJAHRSTAG', makeDate(year, 1, 1)),
newHoliday('TAG_DER_ARBEIT', makeDate(year, 5, 1)),
newHoliday('DEUTSCHEEINHEIT', makeDate(year, 10, 3)),
newHoliday('ERSTERWEIHNACHTSFEIERTAG', makeDate(year, 12, 25)),
newHoliday('ZWEITERWEIHNACHTSFEIERTAG', makeDate(year, 12, 26)),
];
}
function addRegionalHolidays(year, region, feiertageObjects) {
if (region === 'AUGSBURG') {
feiertageObjects.push(newHoliday('AUGSBURGER_FRIEDENSFEST', makeDate(year, 8, 8)));
}
}
function addHeiligeDreiKoenige(year, region, feiertageObjects) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ST' ||
region === 'ALL') {
feiertageObjects.push(newHoliday('HEILIGEDREIKOENIGE', makeDate(year, 1, 6)));
}
}
function addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, feiertageObjects) {
if (region === 'BB' || region === 'ALL') {
feiertageObjects.push(newHoliday('OSTERSONNTAG', easterDate), newHoliday('PFINGSTSONNTAG', pfingstsonntag));
}
}
function addFronleichnam(region, easterDate, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'HE' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
const fronleichnam = addDays(new Date(easterDate.getTime()), 60);
holidays.push(newHoliday('FRONLEICHNAM', fronleichnam));
}
}
function addMariaeHimmelfahrt(year, region, holidays) {
if (region === 'SL' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ALL') {
holidays.push(newHoliday('MARIAHIMMELFAHRT', makeDate(year, 8, 15)));
}
}
function addReformationstag(year, region, holidays) {
if (year === 2017 ||
region === 'NI' ||
region === 'BB' ||
region === 'HB' ||
region === 'HH' ||
region === 'MV' ||
region === 'SN' ||
region === 'ST' ||
region === 'TH' ||
region === 'SH' ||
region === 'ALL') {
holidays.push(newHoliday('REFORMATIONSTAG', makeDate(year, 10, 31)));
}
}
function addAllerheiligen(year, region, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
holidays.push(newHoliday('ALLERHEILIGEN', makeDate(year, 11, 1)));
}
}
function addBussUndBetttag(year, region, holidays) {
if (region === 'SN' || region === 'ALL') {
// @todo write test
const bussbettag = getBussBettag(year);
holidays.push(newHoliday('BUBETAG', makeDate(bussbettag.getUTCFullYear(), bussbettag.getUTCMonth() + 1, bussbettag.getUTCDate())));
}
}
function addWeltkindertag(year, region, holidays) {
if (year >= 2019 && (region === 'TH' || region === 'ALL')) {
holidays.push(newHoliday('WELTKINDERTAG', makeDate(year, 9, 20)));
}
}
function addWeltfrauenTag(year, region, feiertageObjects) {
if (year <= 2018) {
return;
}
if (region === 'BE' || region === 'ALL') {
// in Berlin ist der Weltfrauentag ein Feiertag seit 2018
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
if (region === 'MV' && year >= 2023) {
// in MV wird der Weltfrauentag erst ab 2023 eingeführt
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
}
/**
* Calculates the Easter date of a given year.
* @param year {number}
* @returns {Date} Easter date
* @private
*/
function getEasterDate(year) {
const C = Math.floor(year / 100);
// tslint:disable:binary-expression-operand-order
// tslint generates false positives in the following blocks
const N = year - 19 * Math.floor(year / 19);
const K = Math.floor((C - 17) / 25);
let I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
I -= 30 * Math.floor(I / 30);
I -=
Math.floor(I / 28) *
(1 -
Math.floor(I / 28) *
Math.floor(29 / (I + 1)) *
Math.floor((21 - N) / 11));
let J = year + Math.floor(year / 4) + I + 2 - C + Math.floor(C / 4);
J -= 7 * Math.floor(J / 7);
const L = I - J;
const M = 3 + Math.floor((L + 40) / 44);
const D = L + 28 - 31 * Math.floor(M / 4);
// tslint:enable:binary-expression-operand-order
return new Date(year, M - 1, D);
}
/**
* Computes the "Buss- und Bettag"'s date.
* @param jahr {number}
* @returns {Date} the year's "Buss- und Bettag" date
* @private
*/
function getBussBettag(jahr) {
const weihnachten = new Date(jahr, 11, 25, 12, 0, 0);
const ersterAdventOffset = 32;
let wochenTagOffset = weihnachten.getDay() % 7;
if (wochenTagOffset === 0) {
wochenTagOffset = 7;
}
const tageVorWeihnachten = wochenTagOffset + ersterAdventOffset;
let bbtag = new Date(weihnachten.getTime());
bbtag = addDays(bbtag, -tageVorWeihnachten);
return bbtag;
}
/**
* Adds {@code days} days to the given {@link Date}.
* @param date
* @param days
* @returns {Date}
* @private
*/
function addDays(date, days) {
const changedDate = new Date(date);
changedDate.setDate(date.getDate() + days);
return changedDate;
}
/**
* Creates a new {@link Date}.
* @param year
* @param naturalMonth month (1-12)
* @param day
* @returns {Date}
* @private
*/
function makeDate(year, naturalMonth, day) {
return new Date(year, naturalMonth - 1, day);
}
/**
*
* @param name
* @param date
* @returns {Holiday}
* @private
*/
function newHoliday(name, date) {
return {
name,
date,
dateString: localeDateObjectToDateString(date),
trans(lang = currentLanguage) {
console.warn('FeiertageJs: You are using "Holiday.trans() method. This will be replaced in the next major version with translate()"');
return this.translate(lang);
},
translate(lang = currentLanguage) {
return lang === undefined || lang === null
? undefined
: translations[lang][this.name];
},
getNormalizedDate() {
return toUtcTimestamp(this.date);
},
equals(otherDate) {
const dateString = localeDateObjectToDateString(otherDate);
return this.dateString === dateString;
},
};
}
/**
*
* @param date
* @returns {string}
* @private
*/
function localeDateObjectToDateString(date) {
const normalizedDate = new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
normalizedDate.setUTCHours(0, 0, 0, 0);
return normalizedDate.toISOString().slice(0, 10);
}
/**
* Returns the UTC timestamp of the given date with hours, minutes, seconds, and milliseconds set to zero.
* @param date
* @returns {number} UTC timestamp
*/
function toUtcTimestamp(date) {
const internalDate = new Date(date);
internalDate.setHours(0, 0, 0, 0);
return internalDate.getTime();
}
export { addTranslation, getHolidayByDate, getHolidays, getLanguage, isHoliday, isSpecificHoliday, isSunOrHoliday, setLanguage };
//# sourceMappingURL=feiertage.esm.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"feiertage.esm.js","sources":["../src/german-translations.ts","../src/holiday-type.ts","../src/regions.ts","../src/feiertage.ts"],"sourcesContent":["import { TranslationTable } from './feiertage';\n\nexport const germanTranslations: TranslationTable = {\n NEUJAHRSTAG: 'Neujahrstag',\n HEILIGEDREIKOENIGE: 'Heilige Drei Könige',\n KARFREITAG: 'Karfreitag',\n OSTERSONNTAG: 'Ostersonntag',\n OSTERMONTAG: 'Ostermontag',\n TAG_DER_ARBEIT: 'Tag der Arbeit',\n CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',\n PFINGSTSONNTAG: 'Pfingstsonntag',\n PFINGSTMONTAG: 'Pfingstmontag',\n FRONLEICHNAM: 'Fronleichnam',\n MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',\n DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',\n REFORMATIONSTAG: 'Reformationstag',\n ALLERHEILIGEN: 'Allerheiligen',\n BUBETAG: 'Buß- und Bettag',\n ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',\n ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',\n WELTKINDERTAG: 'Weltkindertag',\n WELTFRAUENTAG: 'Weltfrauentag',\n AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',\n};\n","export type HolidayType =\n | 'NEUJAHRSTAG'\n | 'HEILIGEDREIKOENIGE'\n | 'KARFREITAG'\n | 'OSTERSONNTAG'\n | 'OSTERMONTAG'\n | 'TAG_DER_ARBEIT'\n | 'CHRISTIHIMMELFAHRT'\n | 'MARIAHIMMELFAHRT'\n | 'PFINGSTSONNTAG'\n | 'PFINGSTMONTAG'\n | 'FRONLEICHNAM'\n | 'DEUTSCHEEINHEIT'\n | 'REFORMATIONSTAG'\n | 'ALLERHEILIGEN'\n | 'BUBETAG'\n | 'ERSTERWEIHNACHTSFEIERTAG'\n | 'ZWEITERWEIHNACHTSFEIERTAG'\n | 'WELTKINDERTAG'\n | 'WELTFRAUENTAG'\n | 'AUGSBURGER_FRIEDENSFEST';\n\nexport const allHolidays: HolidayType[] = [\n 'NEUJAHRSTAG',\n 'HEILIGEDREIKOENIGE',\n 'KARFREITAG',\n 'OSTERSONNTAG',\n 'OSTERMONTAG',\n 'TAG_DER_ARBEIT',\n 'CHRISTIHIMMELFAHRT',\n 'MARIAHIMMELFAHRT',\n 'PFINGSTSONNTAG',\n 'PFINGSTMONTAG',\n 'FRONLEICHNAM',\n 'DEUTSCHEEINHEIT',\n 'REFORMATIONSTAG',\n 'ALLERHEILIGEN',\n 'BUBETAG',\n 'ERSTERWEIHNACHTSFEIERTAG',\n 'ZWEITERWEIHNACHTSFEIERTAG',\n 'WELTKINDERTAG',\n 'WELTFRAUENTAG',\n 'AUGSBURGER_FRIEDENSFEST',\n];\n","export type Region =\n | 'BW' // Baden-Württemberg\n | 'BY' // Bayern\n | 'BE' // Berlin\n | 'BB' // Brandenburg\n | 'HB' // Bremen\n | 'HE' // Hessen\n | 'HH' // Hamburg\n | 'MV' // Mecklenburg-Vorpommern\n | 'NI' // Niedersachsen\n | 'NW' // Nordrhein-Westfalen\n | 'RP' // Rheinland-Pfalz\n | 'SL' // Saarland\n | 'SN' // Sachsen\n | 'ST' // Sachsen-Anhalt\n | 'SH' // Schleswig-Holstein\n | 'TH' // Thüringen\n | 'BUND' // Gesamt-Deutschland\n // Custom regions with local holidays (incompelte) !\n | 'AUGSBURG'\n | 'ALL';\n\nexport const allRegions: Region[] = [\n 'BW',\n 'BY',\n 'BE',\n 'BB',\n 'HB',\n 'HE',\n 'HH',\n 'MV',\n 'NI',\n 'NW',\n 'RP',\n 'SL',\n 'SN',\n 'ST',\n 'SH',\n 'TH',\n 'BUND',\n 'AUGSBURG',\n 'ALL',\n];\n","/*!\n * feiertage.js\n * @repository https://github.com/sfakir/feiertagejs\n * @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md\n *\n * Copyright 2015-2021 Simon Fakir\n * Released under the MIT license\n */\n\n//\n// Additional readings\n// - how to format a javascript date: http://blog.stevenlevithan.com/archives/date-time-format\n// - the right javascript date: http://stackoverflow.com/questions/10286204/the-right-json-date-format\n//\n\nimport { germanTranslations } from './german-translations';\nimport { Holiday } from './holiday';\nimport { allHolidays, HolidayType } from './holiday-type';\nimport { allRegions, Region } from './regions';\n\n// translations\n\nconst defaultLanguage = 'de';\nlet currentLanguage: string = defaultLanguage;\n\n/**\n * Map of {@link HolidayType} to translation string.\n */\nexport type TranslationTable = { [key in HolidayType]?: string };\n\nconst translations: { [key: string]: TranslationTable } = {\n de: germanTranslations,\n};\n\n/**\n * adds a translation for the holidays (e.g. english).\n * This also allows to override the German names.\n * Hint: Interpolates German for missing translations\n * @param {string} isoCode of the new language\n * @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg\n */\nexport function addTranslation(\n isoCode: string,\n newTranslation: TranslationTable,\n): void {\n const code = isoCode.toLowerCase();\n const defaultTranslation = translations[defaultLanguage];\n let missingFields = false;\n\n // fill new Translation with default Language\n for (const holiday of allHolidays) {\n if (!newTranslation[holiday]) {\n missingFields = true;\n newTranslation[holiday] = defaultTranslation[holiday];\n }\n }\n if (missingFields) {\n console.warn(\n '[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback',\n );\n }\n\n translations[code] = newTranslation;\n}\n\n/**\n * Set a language to default language\n * @param {string} isoCode\n */\nexport function setLanguage(isoCode: string): void {\n const code = isoCode.toLowerCase();\n if (!translations[code])Line truncated
-476
View File
@@ -1,476 +0,0 @@
const germanTranslations = {
NEUJAHRSTAG: 'Neujahrstag',
HEILIGEDREIKOENIGE: 'Heilige Drei Könige',
KARFREITAG: 'Karfreitag',
OSTERSONNTAG: 'Ostersonntag',
OSTERMONTAG: 'Ostermontag',
TAG_DER_ARBEIT: 'Tag der Arbeit',
CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',
PFINGSTSONNTAG: 'Pfingstsonntag',
PFINGSTMONTAG: 'Pfingstmontag',
FRONLEICHNAM: 'Fronleichnam',
MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',
DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',
REFORMATIONSTAG: 'Reformationstag',
ALLERHEILIGEN: 'Allerheiligen',
BUBETAG: 'Buß- und Bettag',
ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',
ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',
WELTKINDERTAG: 'Weltkindertag',
WELTFRAUENTAG: 'Weltfrauentag',
AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',
};
const allHolidays = [
'NEUJAHRSTAG',
'HEILIGEDREIKOENIGE',
'KARFREITAG',
'OSTERSONNTAG',
'OSTERMONTAG',
'TAG_DER_ARBEIT',
'CHRISTIHIMMELFAHRT',
'MARIAHIMMELFAHRT',
'PFINGSTSONNTAG',
'PFINGSTMONTAG',
'FRONLEICHNAM',
'DEUTSCHEEINHEIT',
'REFORMATIONSTAG',
'ALLERHEILIGEN',
'BUBETAG',
'ERSTERWEIHNACHTSFEIERTAG',
'ZWEITERWEIHNACHTSFEIERTAG',
'WELTKINDERTAG',
'WELTFRAUENTAG',
'AUGSBURGER_FRIEDENSFEST',
];
const allRegions = [
'BW',
'BY',
'BE',
'BB',
'HB',
'HE',
'HH',
'MV',
'NI',
'NW',
'RP',
'SL',
'SN',
'ST',
'SH',
'TH',
'BUND',
'AUGSBURG',
'ALL',
];
/*!
* feiertage.js
* @repository https://github.com/sfakir/feiertagejs
* @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md
*
* Copyright 2015-2021 Simon Fakir
* Released under the MIT license
*/
// translations
const defaultLanguage = 'de';
let currentLanguage = defaultLanguage;
const translations = {
de: germanTranslations,
};
/**
* adds a translation for the holidays (e.g. english).
* This also allows to override the German names.
* Hint: Interpolates German for missing translations
* @param {string} isoCode of the new language
* @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg
*/
function addTranslation(isoCode, newTranslation) {
const code = isoCode.toLowerCase();
const defaultTranslation = translations[defaultLanguage];
let missingFields = false;
// fill new Translation with default Language
for (const holiday of allHolidays) {
if (!newTranslation[holiday]) {
missingFields = true;
newTranslation[holiday] = defaultTranslation[holiday];
}
}
if (missingFields) {
console.warn('[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback');
}
translations[code] = newTranslation;
}
/**
* Set a language to default language
* @param {string} isoCode
*/
function setLanguage(isoCode) {
const code = isoCode.toLowerCase();
if (!translations[code]) {
throw new TypeError(`[feiertagejs] tried to set language to ${code} but the translation is missing. Please use addTranslation(isoCode,object) first`);
}
currentLanguage = isoCode;
}
/**
* Get currently set language
* @returns {string}
*/
function getLanguage() {
return currentLanguage;
}
// holidays api
/**
* Checks if a specific date is sunday or holiday.
* @param date
* @param region
* @returns {boolean}
*/
function isSunOrHoliday(date, region) {
checkRegion(region);
return date.getDay() === 0 || isHoliday(date, region);
}
/**
* Check is specific date is holiday.
* @param date
* @param {Region} region two character {@link Region} code
* @returns {boolean}
*/
function isHoliday(date, region) {
checkRegion(region);
const year = date.getFullYear();
const internalDate = toUtcTimestamp(date);
const holidays = getHolidaysAsUtcTimestamps(year, region);
return holidays.indexOf(internalDate) !== -1;
}
function getHolidayByDate(date, region = 'ALL') {
checkRegion(region);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
return holidays.find((holiday) => holiday.equals(date));
}
// additional runtime checks
/**
* Checks if the given region is a valid {@link Region}.
*
* @param region {@link Region} to check
* @throws {Error}
* @private
*/
function checkRegion(region) {
if (region === null || region === undefined) {
throw new Error(`Region must not be undefined or null`);
}
if (allRegions.indexOf(region) === -1) {
throw new Error(`Invalid region: ${region}! Must be one of ${allRegions.toString()}`);
}
}
/**
* Checks if the given holidayName is a valid {@link HolidayType}.
* @param holidayName {@link HolidayType} to check
* @throws {Error}
* @private
*/
function checkHolidayType(holidayName) {
if (holidayName === null || holidayName === undefined) {
throw new TypeError('holidayName must not be null or undefined');
}
if (allHolidays.indexOf(holidayName) === -1) {
throw new Error(`feiertage.js: invalid holiday type "${holidayName}"! Must be one of ${allHolidays.toString()}`);
}
}
function isSpecificHoliday(date, holidayName, region = 'ALL') {
checkRegion(region);
checkHolidayType(holidayName);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
const foundHoliday = holidays.find((holiday) => holiday.equals(date));
if (!foundHoliday) {
return false;
}
return foundHoliday.name === holidayName;
}
/**
* Returns all holidays of a year in a {@link Region}.
* @param year
* @param region
* @returns {Array.<Holiday>}
*/
function getHolidays(year, region) {
let y;
if (typeof year === 'string') {
y = parseInt(year, 10);
}
else {
y = year;
}
checkRegion(region);
return getHolidaysOfYear(y, region);
}
/**
*
* @param {number} year
* @param region
* @returns {number[]}
* @private
*/
function getHolidaysAsUtcTimestamps(year, region) {
const holidays = getHolidaysOfYear(year, region);
return holidays.map((holiday) => toUtcTimestamp(holiday.date));
}
/**
*
* @param {number} year
* @param region
* @returns {{objects: Array.<Holiday>, integers}}
* @private
*/
function getHolidaysOfYear(year, region) {
const easterDate = getEasterDate(year);
const karfreitag = addDays(new Date(easterDate.getTime()), -2);
const ostermontag = addDays(new Date(easterDate.getTime()), 1);
const christiHimmelfahrt = addDays(new Date(easterDate.getTime()), 39);
const pfingstsonntag = addDays(new Date(easterDate.getTime()), 49);
const pfingstmontag = addDays(new Date(easterDate.getTime()), 50);
const holidays = [
...getCommonHolidays(year),
newHoliday('KARFREITAG', karfreitag),
newHoliday('OSTERMONTAG', ostermontag),
newHoliday('CHRISTIHIMMELFAHRT', christiHimmelfahrt),
newHoliday('PFINGSTMONTAG', pfingstmontag),
];
addHeiligeDreiKoenige(year, region, holidays);
addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, holidays);
addFronleichnam(region, easterDate, holidays);
addMariaeHimmelfahrt(year, region, holidays);
addReformationstag(year, region, holidays);
addAllerheiligen(year, region, holidays);
addBussUndBetttag(year, region, holidays);
addWeltkindertag(year, region, holidays);
addWeltfrauenTag(year, region, holidays);
addRegionalHolidays(year, region, holidays);
return holidays.sort((a, b) => a.date.getTime() - b.date.getTime());
}
function getCommonHolidays(year) {
return [
newHoliday('NEUJAHRSTAG', makeDate(year, 1, 1)),
newHoliday('TAG_DER_ARBEIT', makeDate(year, 5, 1)),
newHoliday('DEUTSCHEEINHEIT', makeDate(year, 10, 3)),
newHoliday('ERSTERWEIHNACHTSFEIERTAG', makeDate(year, 12, 25)),
newHoliday('ZWEITERWEIHNACHTSFEIERTAG', makeDate(year, 12, 26)),
];
}
function addRegionalHolidays(year, region, feiertageObjects) {
if (region === 'AUGSBURG') {
feiertageObjects.push(newHoliday('AUGSBURGER_FRIEDENSFEST', makeDate(year, 8, 8)));
}
}
function addHeiligeDreiKoenige(year, region, feiertageObjects) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ST' ||
region === 'ALL') {
feiertageObjects.push(newHoliday('HEILIGEDREIKOENIGE', makeDate(year, 1, 6)));
}
}
function addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, feiertageObjects) {
if (region === 'BB' || region === 'ALL') {
feiertageObjects.push(newHoliday('OSTERSONNTAG', easterDate), newHoliday('PFINGSTSONNTAG', pfingstsonntag));
}
}
function addFronleichnam(region, easterDate, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'HE' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
const fronleichnam = addDays(new Date(easterDate.getTime()), 60);
holidays.push(newHoliday('FRONLEICHNAM', fronleichnam));
}
}
function addMariaeHimmelfahrt(year, region, holidays) {
if (region === 'SL' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ALL') {
holidays.push(newHoliday('MARIAHIMMELFAHRT', makeDate(year, 8, 15)));
}
}
function addReformationstag(year, region, holidays) {
if (year === 2017 ||
region === 'NI' ||
region === 'BB' ||
region === 'HB' ||
region === 'HH' ||
region === 'MV' ||
region === 'SN' ||
region === 'ST' ||
region === 'TH' ||
region === 'SH' ||
region === 'ALL') {
holidays.push(newHoliday('REFORMATIONSTAG', makeDate(year, 10, 31)));
}
}
function addAllerheiligen(year, region, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
holidays.push(newHoliday('ALLERHEILIGEN', makeDate(year, 11, 1)));
}
}
function addBussUndBetttag(year, region, holidays) {
if (region === 'SN' || region === 'ALL') {
// @todo write test
const bussbettag = getBussBettag(year);
holidays.push(newHoliday('BUBETAG', makeDate(bussbettag.getUTCFullYear(), bussbettag.getUTCMonth() + 1, bussbettag.getUTCDate())));
}
}
function addWeltkindertag(year, region, holidays) {
if (year >= 2019 && (region === 'TH' || region === 'ALL')) {
holidays.push(newHoliday('WELTKINDERTAG', makeDate(year, 9, 20)));
}
}
function addWeltfrauenTag(year, region, feiertageObjects) {
if (year <= 2018) {
return;
}
if (region === 'BE' || region === 'ALL') {
// in Berlin ist der Weltfrauentag ein Feiertag seit 2018
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
if (region === 'MV' && year >= 2023) {
// in MV wird der Weltfrauentag erst ab 2023 eingeführt
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
}
/**
* Calculates the Easter date of a given year.
* @param year {number}
* @returns {Date} Easter date
* @private
*/
function getEasterDate(year) {
const C = Math.floor(year / 100);
// tslint:disable:binary-expression-operand-order
// tslint generates false positives in the following blocks
const N = year - 19 * Math.floor(year / 19);
const K = Math.floor((C - 17) / 25);
let I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
I -= 30 * Math.floor(I / 30);
I -=
Math.floor(I / 28) *
(1 -
Math.floor(I / 28) *
Math.floor(29 / (I + 1)) *
Math.floor((21 - N) / 11));
let J = year + Math.floor(year / 4) + I + 2 - C + Math.floor(C / 4);
J -= 7 * Math.floor(J / 7);
const L = I - J;
const M = 3 + Math.floor((L + 40) / 44);
const D = L + 28 - 31 * Math.floor(M / 4);
// tslint:enable:binary-expression-operand-order
return new Date(year, M - 1, D);
}
/**
* Computes the "Buss- und Bettag"'s date.
* @param jahr {number}
* @returns {Date} the year's "Buss- und Bettag" date
* @private
*/
function getBussBettag(jahr) {
const weihnachten = new Date(jahr, 11, 25, 12, 0, 0);
const ersterAdventOffset = 32;
let wochenTagOffset = weihnachten.getDay() % 7;
if (wochenTagOffset === 0) {
wochenTagOffset = 7;
}
const tageVorWeihnachten = wochenTagOffset + ersterAdventOffset;
let bbtag = new Date(weihnachten.getTime());
bbtag = addDays(bbtag, -tageVorWeihnachten);
return bbtag;
}
/**
* Adds {@code days} days to the given {@link Date}.
* @param date
* @param days
* @returns {Date}
* @private
*/
function addDays(date, days) {
const changedDate = new Date(date);
changedDate.setDate(date.getDate() + days);
return changedDate;
}
/**
* Creates a new {@link Date}.
* @param year
* @param naturalMonth month (1-12)
* @param day
* @returns {Date}
* @private
*/
function makeDate(year, naturalMonth, day) {
return new Date(year, naturalMonth - 1, day);
}
/**
*
* @param name
* @param date
* @returns {Holiday}
* @private
*/
function newHoliday(name, date) {
return {
name,
date,
dateString: localeDateObjectToDateString(date),
trans(lang = currentLanguage) {
console.warn('FeiertageJs: You are using "Holiday.trans() method. This will be replaced in the next major version with translate()"');
return this.translate(lang);
},
translate(lang = currentLanguage) {
return lang === undefined || lang === null
? undefined
: translations[lang][this.name];
},
getNormalizedDate() {
return toUtcTimestamp(this.date);
},
equals(otherDate) {
const dateString = localeDateObjectToDateString(otherDate);
return this.dateString === dateString;
},
};
}
/**
*
* @param date
* @returns {string}
* @private
*/
function localeDateObjectToDateString(date) {
const normalizedDate = new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
normalizedDate.setUTCHours(0, 0, 0, 0);
return normalizedDate.toISOString().slice(0, 10);
}
/**
* Returns the UTC timestamp of the given date with hours, minutes, seconds, and milliseconds set to zero.
* @param date
* @returns {number} UTC timestamp
*/
function toUtcTimestamp(date) {
const internalDate = new Date(date);
internalDate.setHours(0, 0, 0, 0);
return internalDate.getTime();
}
export { addTranslation, getHolidayByDate, getHolidays, getLanguage, isHoliday, isSpecificHoliday, isSunOrHoliday, setLanguage };
//# sourceMappingURL=feiertage.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"feiertage.js","sources":["../src/german-translations.ts","../src/holiday-type.ts","../src/regions.ts","../src/feiertage.ts"],"sourcesContent":["import { TranslationTable } from './feiertage';\n\nexport const germanTranslations: TranslationTable = {\n NEUJAHRSTAG: 'Neujahrstag',\n HEILIGEDREIKOENIGE: 'Heilige Drei Könige',\n KARFREITAG: 'Karfreitag',\n OSTERSONNTAG: 'Ostersonntag',\n OSTERMONTAG: 'Ostermontag',\n TAG_DER_ARBEIT: 'Tag der Arbeit',\n CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',\n PFINGSTSONNTAG: 'Pfingstsonntag',\n PFINGSTMONTAG: 'Pfingstmontag',\n FRONLEICHNAM: 'Fronleichnam',\n MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',\n DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',\n REFORMATIONSTAG: 'Reformationstag',\n ALLERHEILIGEN: 'Allerheiligen',\n BUBETAG: 'Buß- und Bettag',\n ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',\n ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',\n WELTKINDERTAG: 'Weltkindertag',\n WELTFRAUENTAG: 'Weltfrauentag',\n AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',\n};\n","export type HolidayType =\n | 'NEUJAHRSTAG'\n | 'HEILIGEDREIKOENIGE'\n | 'KARFREITAG'\n | 'OSTERSONNTAG'\n | 'OSTERMONTAG'\n | 'TAG_DER_ARBEIT'\n | 'CHRISTIHIMMELFAHRT'\n | 'MARIAHIMMELFAHRT'\n | 'PFINGSTSONNTAG'\n | 'PFINGSTMONTAG'\n | 'FRONLEICHNAM'\n | 'DEUTSCHEEINHEIT'\n | 'REFORMATIONSTAG'\n | 'ALLERHEILIGEN'\n | 'BUBETAG'\n | 'ERSTERWEIHNACHTSFEIERTAG'\n | 'ZWEITERWEIHNACHTSFEIERTAG'\n | 'WELTKINDERTAG'\n | 'WELTFRAUENTAG'\n | 'AUGSBURGER_FRIEDENSFEST';\n\nexport const allHolidays: HolidayType[] = [\n 'NEUJAHRSTAG',\n 'HEILIGEDREIKOENIGE',\n 'KARFREITAG',\n 'OSTERSONNTAG',\n 'OSTERMONTAG',\n 'TAG_DER_ARBEIT',\n 'CHRISTIHIMMELFAHRT',\n 'MARIAHIMMELFAHRT',\n 'PFINGSTSONNTAG',\n 'PFINGSTMONTAG',\n 'FRONLEICHNAM',\n 'DEUTSCHEEINHEIT',\n 'REFORMATIONSTAG',\n 'ALLERHEILIGEN',\n 'BUBETAG',\n 'ERSTERWEIHNACHTSFEIERTAG',\n 'ZWEITERWEIHNACHTSFEIERTAG',\n 'WELTKINDERTAG',\n 'WELTFRAUENTAG',\n 'AUGSBURGER_FRIEDENSFEST',\n];\n","export type Region =\n | 'BW' // Baden-Württemberg\n | 'BY' // Bayern\n | 'BE' // Berlin\n | 'BB' // Brandenburg\n | 'HB' // Bremen\n | 'HE' // Hessen\n | 'HH' // Hamburg\n | 'MV' // Mecklenburg-Vorpommern\n | 'NI' // Niedersachsen\n | 'NW' // Nordrhein-Westfalen\n | 'RP' // Rheinland-Pfalz\n | 'SL' // Saarland\n | 'SN' // Sachsen\n | 'ST' // Sachsen-Anhalt\n | 'SH' // Schleswig-Holstein\n | 'TH' // Thüringen\n | 'BUND' // Gesamt-Deutschland\n // Custom regions with local holidays (incompelte) !\n | 'AUGSBURG'\n | 'ALL';\n\nexport const allRegions: Region[] = [\n 'BW',\n 'BY',\n 'BE',\n 'BB',\n 'HB',\n 'HE',\n 'HH',\n 'MV',\n 'NI',\n 'NW',\n 'RP',\n 'SL',\n 'SN',\n 'ST',\n 'SH',\n 'TH',\n 'BUND',\n 'AUGSBURG',\n 'ALL',\n];\n","/*!\n * feiertage.js\n * @repository https://github.com/sfakir/feiertagejs\n * @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md\n *\n * Copyright 2015-2021 Simon Fakir\n * Released under the MIT license\n */\n\n//\n// Additional readings\n// - how to format a javascript date: http://blog.stevenlevithan.com/archives/date-time-format\n// - the right javascript date: http://stackoverflow.com/questions/10286204/the-right-json-date-format\n//\n\nimport { germanTranslations } from './german-translations';\nimport { Holiday } from './holiday';\nimport { allHolidays, HolidayType } from './holiday-type';\nimport { allRegions, Region } from './regions';\n\n// translations\n\nconst defaultLanguage = 'de';\nlet currentLanguage: string = defaultLanguage;\n\n/**\n * Map of {@link HolidayType} to translation string.\n */\nexport type TranslationTable = { [key in HolidayType]?: string };\n\nconst translations: { [key: string]: TranslationTable } = {\n de: germanTranslations,\n};\n\n/**\n * adds a translation for the holidays (e.g. english).\n * This also allows to override the German names.\n * Hint: Interpolates German for missing translations\n * @param {string} isoCode of the new language\n * @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg\n */\nexport function addTranslation(\n isoCode: string,\n newTranslation: TranslationTable,\n): void {\n const code = isoCode.toLowerCase();\n const defaultTranslation = translations[defaultLanguage];\n let missingFields = false;\n\n // fill new Translation with default Language\n for (const holiday of allHolidays) {\n if (!newTranslation[holiday]) {\n missingFields = true;\n newTranslation[holiday] = defaultTranslation[holiday];\n }\n }\n if (missingFields) {\n console.warn(\n '[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback',\n );\n }\n\n translations[code] = newTranslation;\n}\n\n/**\n * Set a language to default language\n * @param {string} isoCode\n */\nexport function setLanguage(isoCode: string): void {\n const code = isoCode.toLowerCase();\n if (!translations[code]) {\nLine truncated
-496
View File
@@ -1,496 +0,0 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, (function () {
var current = global.feiertagejs;
var exports = global.feiertagejs = {};
factory(exports);
exports.noConflict = function () { global.feiertagejs = current; return exports; };
})());
})(this, (function (exports) { 'use strict';
const germanTranslations = {
NEUJAHRSTAG: 'Neujahrstag',
HEILIGEDREIKOENIGE: 'Heilige Drei Könige',
KARFREITAG: 'Karfreitag',
OSTERSONNTAG: 'Ostersonntag',
OSTERMONTAG: 'Ostermontag',
TAG_DER_ARBEIT: 'Tag der Arbeit',
CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',
PFINGSTSONNTAG: 'Pfingstsonntag',
PFINGSTMONTAG: 'Pfingstmontag',
FRONLEICHNAM: 'Fronleichnam',
MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',
DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',
REFORMATIONSTAG: 'Reformationstag',
ALLERHEILIGEN: 'Allerheiligen',
BUBETAG: 'Buß- und Bettag',
ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',
ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',
WELTKINDERTAG: 'Weltkindertag',
WELTFRAUENTAG: 'Weltfrauentag',
AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',
};
const allHolidays = [
'NEUJAHRSTAG',
'HEILIGEDREIKOENIGE',
'KARFREITAG',
'OSTERSONNTAG',
'OSTERMONTAG',
'TAG_DER_ARBEIT',
'CHRISTIHIMMELFAHRT',
'MARIAHIMMELFAHRT',
'PFINGSTSONNTAG',
'PFINGSTMONTAG',
'FRONLEICHNAM',
'DEUTSCHEEINHEIT',
'REFORMATIONSTAG',
'ALLERHEILIGEN',
'BUBETAG',
'ERSTERWEIHNACHTSFEIERTAG',
'ZWEITERWEIHNACHTSFEIERTAG',
'WELTKINDERTAG',
'WELTFRAUENTAG',
'AUGSBURGER_FRIEDENSFEST',
];
const allRegions = [
'BW',
'BY',
'BE',
'BB',
'HB',
'HE',
'HH',
'MV',
'NI',
'NW',
'RP',
'SL',
'SN',
'ST',
'SH',
'TH',
'BUND',
'AUGSBURG',
'ALL',
];
/*!
* feiertage.js
* @repository https://github.com/sfakir/feiertagejs
* @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md
*
* Copyright 2015-2021 Simon Fakir
* Released under the MIT license
*/
// translations
const defaultLanguage = 'de';
let currentLanguage = defaultLanguage;
const translations = {
de: germanTranslations,
};
/**
* adds a translation for the holidays (e.g. english).
* This also allows to override the German names.
* Hint: Interpolates German for missing translations
* @param {string} isoCode of the new language
* @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg
*/
function addTranslation(isoCode, newTranslation) {
const code = isoCode.toLowerCase();
const defaultTranslation = translations[defaultLanguage];
let missingFields = false;
// fill new Translation with default Language
for (const holiday of allHolidays) {
if (!newTranslation[holiday]) {
missingFields = true;
newTranslation[holiday] = defaultTranslation[holiday];
}
}
if (missingFields) {
console.warn('[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback');
}
translations[code] = newTranslation;
}
/**
* Set a language to default language
* @param {string} isoCode
*/
function setLanguage(isoCode) {
const code = isoCode.toLowerCase();
if (!translations[code]) {
throw new TypeError(`[feiertagejs] tried to set language to ${code} but the translation is missing. Please use addTranslation(isoCode,object) first`);
}
currentLanguage = isoCode;
}
/**
* Get currently set language
* @returns {string}
*/
function getLanguage() {
return currentLanguage;
}
// holidays api
/**
* Checks if a specific date is sunday or holiday.
* @param date
* @param region
* @returns {boolean}
*/
function isSunOrHoliday(date, region) {
checkRegion(region);
return date.getDay() === 0 || isHoliday(date, region);
}
/**
* Check is specific date is holiday.
* @param date
* @param {Region} region two character {@link Region} code
* @returns {boolean}
*/
function isHoliday(date, region) {
checkRegion(region);
const year = date.getFullYear();
const internalDate = toUtcTimestamp(date);
const holidays = getHolidaysAsUtcTimestamps(year, region);
return holidays.indexOf(internalDate) !== -1;
}
function getHolidayByDate(date, region = 'ALL') {
checkRegion(region);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
return holidays.find((holiday) => holiday.equals(date));
}
// additional runtime checks
/**
* Checks if the given region is a valid {@link Region}.
*
* @param region {@link Region} to check
* @throws {Error}
* @private
*/
function checkRegion(region) {
if (region === null || region === undefined) {
throw new Error(`Region must not be undefined or null`);
}
if (allRegions.indexOf(region) === -1) {
throw new Error(`Invalid region: ${region}! Must be one of ${allRegions.toString()}`);
}
}
/**
* Checks if the given holidayName is a valid {@link HolidayType}.
* @param holidayName {@link HolidayType} to check
* @throws {Error}
* @private
*/
function checkHolidayType(holidayName) {
if (holidayName === null || holidayName === undefined) {
throw new TypeError('holidayName must not be null or undefined');
}
if (allHolidays.indexOf(holidayName) === -1) {
throw new Error(`feiertage.js: invalid holiday type "${holidayName}"! Must be one of ${allHolidays.toString()}`);
}
}
function isSpecificHoliday(date, holidayName, region = 'ALL') {
checkRegion(region);
checkHolidayType(holidayName);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
const foundHoliday = holidays.find((holiday) => holiday.equals(date));
if (!foundHoliday) {
return false;
}
return foundHoliday.name === holidayName;
}
/**
* Returns all holidays of a year in a {@link Region}.
* @param year
* @param region
* @returns {Array.<Holiday>}
*/
function getHolidays(year, region) {
let y;
if (typeof year === 'string') {
y = parseInt(year, 10);
}
else {
y = year;
}
checkRegion(region);
return getHolidaysOfYear(y, region);
}
/**
*
* @param {number} year
* @param region
* @returns {number[]}
* @private
*/
function getHolidaysAsUtcTimestamps(year, region) {
const holidays = getHolidaysOfYear(year, region);
return holidays.map((holiday) => toUtcTimestamp(holiday.date));
}
/**
*
* @param {number} year
* @param region
* @returns {{objects: Array.<Holiday>, integers}}
* @private
*/
function getHolidaysOfYear(year, region) {
const easterDate = getEasterDate(year);
const karfreitag = addDays(new Date(easterDate.getTime()), -2);
const ostermontag = addDays(new Date(easterDate.getTime()), 1);
const christiHimmelfahrt = addDays(new Date(easterDate.getTime()), 39);
const pfingstsonntag = addDays(new Date(easterDate.getTime()), 49);
const pfingstmontag = addDays(new Date(easterDate.getTime()), 50);
const holidays = [
...getCommonHolidays(year),
newHoliday('KARFREITAG', karfreitag),
newHoliday('OSTERMONTAG', ostermontag),
newHoliday('CHRISTIHIMMELFAHRT', christiHimmelfahrt),
newHoliday('PFINGSTMONTAG', pfingstmontag),
];
addHeiligeDreiKoenige(year, region, holidays);
addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, holidays);
addFronleichnam(region, easterDate, holidays);
addMariaeHimmelfahrt(year, region, holidays);
addReformationstag(year, region, holidays);
addAllerheiligen(year, region, holidays);
addBussUndBetttag(year, region, holidays);
addWeltkindertag(year, region, holidays);
addWeltfrauenTag(year, region, holidays);
addRegionalHolidays(year, region, holidays);
return holidays.sort((a, b) => a.date.getTime() - b.date.getTime());
}
function getCommonHolidays(year) {
return [
newHoliday('NEUJAHRSTAG', makeDate(year, 1, 1)),
newHoliday('TAG_DER_ARBEIT', makeDate(year, 5, 1)),
newHoliday('DEUTSCHEEINHEIT', makeDate(year, 10, 3)),
newHoliday('ERSTERWEIHNACHTSFEIERTAG', makeDate(year, 12, 25)),
newHoliday('ZWEITERWEIHNACHTSFEIERTAG', makeDate(year, 12, 26)),
];
}
function addRegionalHolidays(year, region, feiertageObjects) {
if (region === 'AUGSBURG') {
feiertageObjects.push(newHoliday('AUGSBURGER_FRIEDENSFEST', makeDate(year, 8, 8)));
}
}
function addHeiligeDreiKoenige(year, region, feiertageObjects) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ST' ||
region === 'ALL') {
feiertageObjects.push(newHoliday('HEILIGEDREIKOENIGE', makeDate(year, 1, 6)));
}
}
function addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, feiertageObjects) {
if (region === 'BB' || region === 'ALL') {
feiertageObjects.push(newHoliday('OSTERSONNTAG', easterDate), newHoliday('PFINGSTSONNTAG', pfingstsonntag));
}
}
function addFronleichnam(region, easterDate, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'HE' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
const fronleichnam = addDays(new Date(easterDate.getTime()), 60);
holidays.push(newHoliday('FRONLEICHNAM', fronleichnam));
}
}
function addMariaeHimmelfahrt(year, region, holidays) {
if (region === 'SL' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ALL') {
holidays.push(newHoliday('MARIAHIMMELFAHRT', makeDate(year, 8, 15)));
}
}
function addReformationstag(year, region, holidays) {
if (year === 2017 ||
region === 'NI' ||
region === 'BB' ||
region === 'HB' ||
region === 'HH' ||
region === 'MV' ||
region === 'SN' ||
region === 'ST' ||
region === 'TH' ||
region === 'SH' ||
region === 'ALL') {
holidays.push(newHoliday('REFORMATIONSTAG', makeDate(year, 10, 31)));
}
}
function addAllerheiligen(year, region, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
holidays.push(newHoliday('ALLERHEILIGEN', makeDate(year, 11, 1)));
}
}
function addBussUndBetttag(year, region, holidays) {
if (region === 'SN' || region === 'ALL') {
// @todo write test
const bussbettag = getBussBettag(year);
holidays.push(newHoliday('BUBETAG', makeDate(bussbettag.getUTCFullYear(), bussbettag.getUTCMonth() + 1, bussbettag.getUTCDate())));
}
}
function addWeltkindertag(year, region, holidays) {
if (year >= 2019 && (region === 'TH' || region === 'ALL')) {
holidays.push(newHoliday('WELTKINDERTAG', makeDate(year, 9, 20)));
}
}
function addWeltfrauenTag(year, region, feiertageObjects) {
if (year <= 2018) {
return;
}
if (region === 'BE' || region === 'ALL') {
// in Berlin ist der Weltfrauentag ein Feiertag seit 2018
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
if (region === 'MV' && year >= 2023) {
// in MV wird der Weltfrauentag erst ab 2023 eingeführt
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
}
/**
* Calculates the Easter date of a given year.
* @param year {number}
* @returns {Date} Easter date
* @private
*/
function getEasterDate(year) {
const C = Math.floor(year / 100);
// tslint:disable:binary-expression-operand-order
// tslint generates false positives in the following blocks
const N = year - 19 * Math.floor(year / 19);
const K = Math.floor((C - 17) / 25);
let I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
I -= 30 * Math.floor(I / 30);
I -=
Math.floor(I / 28) *
(1 -
Math.floor(I / 28) *
Math.floor(29 / (I + 1)) *
Math.floor((21 - N) / 11));
let J = year + Math.floor(year / 4) + I + 2 - C + Math.floor(C / 4);
J -= 7 * Math.floor(J / 7);
const L = I - J;
const M = 3 + Math.floor((L + 40) / 44);
const D = L + 28 - 31 * Math.floor(M / 4);
// tslint:enable:binary-expression-operand-order
return new Date(year, M - 1, D);
}
/**
* Computes the "Buss- und Bettag"'s date.
* @param jahr {number}
* @returns {Date} the year's "Buss- und Bettag" date
* @private
*/
function getBussBettag(jahr) {
const weihnachten = new Date(jahr, 11, 25, 12, 0, 0);
const ersterAdventOffset = 32;
let wochenTagOffset = weihnachten.getDay() % 7;
if (wochenTagOffset === 0) {
wochenTagOffset = 7;
}
const tageVorWeihnachten = wochenTagOffset + ersterAdventOffset;
let bbtag = new Date(weihnachten.getTime());
bbtag = addDays(bbtag, -tageVorWeihnachten);
return bbtag;
}
/**
* Adds {@code days} days to the given {@link Date}.
* @param date
* @param days
* @returns {Date}
* @private
*/
function addDays(date, days) {
const changedDate = new Date(date);
changedDate.setDate(date.getDate() + days);
return changedDate;
}
/**
* Creates a new {@link Date}.
* @param year
* @param naturalMonth month (1-12)
* @param day
* @returns {Date}
* @private
*/
function makeDate(year, naturalMonth, day) {
return new Date(year, naturalMonth - 1, day);
}
/**
*
* @param name
* @param date
* @returns {Holiday}
* @private
*/
function newHoliday(name, date) {
return {
name,
date,
dateString: localeDateObjectToDateString(date),
trans(lang = currentLanguage) {
console.warn('FeiertageJs: You are using "Holiday.trans() method. This will be replaced in the next major version with translate()"');
return this.translate(lang);
},
translate(lang = currentLanguage) {
return lang === undefined || lang === null
? undefined
: translations[lang][this.name];
},
getNormalizedDate() {
return toUtcTimestamp(this.date);
},
equals(otherDate) {
const dateString = localeDateObjectToDateString(otherDate);
return this.dateString === dateString;
},
};
}
/**
*
* @param date
* @returns {string}
* @private
*/
function localeDateObjectToDateString(date) {
const normalizedDate = new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
normalizedDate.setUTCHours(0, 0, 0, 0);
return normalizedDate.toISOString().slice(0, 10);
}
/**
* Returns the UTC timestamp of the given date with hours, minutes, seconds, and milliseconds set to zero.
* @param date
* @returns {number} UTC timestamp
*/
function toUtcTimestamp(date) {
const internalDate = new Date(date);
internalDate.setHours(0, 0, 0, 0);
return internalDate.getTime();
}
exports.addTranslation = addTranslation;
exports.getHolidayByDate = getHolidayByDate;
exports.getHolidays = getHolidays;
exports.getLanguage = getLanguage;
exports.isHoliday = isHoliday;
exports.isSpecificHoliday = isSpecificHoliday;
exports.isSunOrHoliday = isSunOrHoliday;
exports.setLanguage = setLanguage;
}));
//# sourceMappingURL=feiertage.umd.cjs.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"feiertage.umd.cjs","sources":["../src/german-translations.ts","../src/holiday-type.ts","../src/regions.ts","../src/feiertage.ts"],"sourcesContent":["import { TranslationTable } from './feiertage';\n\nexport const germanTranslations: TranslationTable = {\n NEUJAHRSTAG: 'Neujahrstag',\n HEILIGEDREIKOENIGE: 'Heilige Drei Könige',\n KARFREITAG: 'Karfreitag',\n OSTERSONNTAG: 'Ostersonntag',\n OSTERMONTAG: 'Ostermontag',\n TAG_DER_ARBEIT: 'Tag der Arbeit',\n CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',\n PFINGSTSONNTAG: 'Pfingstsonntag',\n PFINGSTMONTAG: 'Pfingstmontag',\n FRONLEICHNAM: 'Fronleichnam',\n MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',\n DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',\n REFORMATIONSTAG: 'Reformationstag',\n ALLERHEILIGEN: 'Allerheiligen',\n BUBETAG: 'Buß- und Bettag',\n ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',\n ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',\n WELTKINDERTAG: 'Weltkindertag',\n WELTFRAUENTAG: 'Weltfrauentag',\n AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',\n};\n","export type HolidayType =\n | 'NEUJAHRSTAG'\n | 'HEILIGEDREIKOENIGE'\n | 'KARFREITAG'\n | 'OSTERSONNTAG'\n | 'OSTERMONTAG'\n | 'TAG_DER_ARBEIT'\n | 'CHRISTIHIMMELFAHRT'\n | 'MARIAHIMMELFAHRT'\n | 'PFINGSTSONNTAG'\n | 'PFINGSTMONTAG'\n | 'FRONLEICHNAM'\n | 'DEUTSCHEEINHEIT'\n | 'REFORMATIONSTAG'\n | 'ALLERHEILIGEN'\n | 'BUBETAG'\n | 'ERSTERWEIHNACHTSFEIERTAG'\n | 'ZWEITERWEIHNACHTSFEIERTAG'\n | 'WELTKINDERTAG'\n | 'WELTFRAUENTAG'\n | 'AUGSBURGER_FRIEDENSFEST';\n\nexport const allHolidays: HolidayType[] = [\n 'NEUJAHRSTAG',\n 'HEILIGEDREIKOENIGE',\n 'KARFREITAG',\n 'OSTERSONNTAG',\n 'OSTERMONTAG',\n 'TAG_DER_ARBEIT',\n 'CHRISTIHIMMELFAHRT',\n 'MARIAHIMMELFAHRT',\n 'PFINGSTSONNTAG',\n 'PFINGSTMONTAG',\n 'FRONLEICHNAM',\n 'DEUTSCHEEINHEIT',\n 'REFORMATIONSTAG',\n 'ALLERHEILIGEN',\n 'BUBETAG',\n 'ERSTERWEIHNACHTSFEIERTAG',\n 'ZWEITERWEIHNACHTSFEIERTAG',\n 'WELTKINDERTAG',\n 'WELTFRAUENTAG',\n 'AUGSBURGER_FRIEDENSFEST',\n];\n","export type Region =\n | 'BW' // Baden-Württemberg\n | 'BY' // Bayern\n | 'BE' // Berlin\n | 'BB' // Brandenburg\n | 'HB' // Bremen\n | 'HE' // Hessen\n | 'HH' // Hamburg\n | 'MV' // Mecklenburg-Vorpommern\n | 'NI' // Niedersachsen\n | 'NW' // Nordrhein-Westfalen\n | 'RP' // Rheinland-Pfalz\n | 'SL' // Saarland\n | 'SN' // Sachsen\n | 'ST' // Sachsen-Anhalt\n | 'SH' // Schleswig-Holstein\n | 'TH' // Thüringen\n | 'BUND' // Gesamt-Deutschland\n // Custom regions with local holidays (incompelte) !\n | 'AUGSBURG'\n | 'ALL';\n\nexport const allRegions: Region[] = [\n 'BW',\n 'BY',\n 'BE',\n 'BB',\n 'HB',\n 'HE',\n 'HH',\n 'MV',\n 'NI',\n 'NW',\n 'RP',\n 'SL',\n 'SN',\n 'ST',\n 'SH',\n 'TH',\n 'BUND',\n 'AUGSBURG',\n 'ALL',\n];\n","/*!\n * feiertage.js\n * @repository https://github.com/sfakir/feiertagejs\n * @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md\n *\n * Copyright 2015-2021 Simon Fakir\n * Released under the MIT license\n */\n\n//\n// Additional readings\n// - how to format a javascript date: http://blog.stevenlevithan.com/archives/date-time-format\n// - the right javascript date: http://stackoverflow.com/questions/10286204/the-right-json-date-format\n//\n\nimport { germanTranslations } from './german-translations';\nimport { Holiday } from './holiday';\nimport { allHolidays, HolidayType } from './holiday-type';\nimport { allRegions, Region } from './regions';\n\n// translations\n\nconst defaultLanguage = 'de';\nlet currentLanguage: string = defaultLanguage;\n\n/**\n * Map of {@link HolidayType} to translation string.\n */\nexport type TranslationTable = { [key in HolidayType]?: string };\n\nconst translations: { [key: string]: TranslationTable } = {\n de: germanTranslations,\n};\n\n/**\n * adds a translation for the holidays (e.g. english).\n * This also allows to override the German names.\n * Hint: Interpolates German for missing translations\n * @param {string} isoCode of the new language\n * @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg\n */\nexport function addTranslation(\n isoCode: string,\n newTranslation: TranslationTable,\n): void {\n const code = isoCode.toLowerCase();\n const defaultTranslation = translations[defaultLanguage];\n let missingFields = false;\n\n // fill new Translation with default Language\n for (const holiday of allHolidays) {\n if (!newTranslation[holiday]) {\n missingFields = true;\n newTranslation[holiday] = defaultTranslation[holiday];\n }\n }\n if (missingFields) {\n console.warn(\n '[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback',\n );\n }\n\n translations[code] = newTranslation;\n}\n\n/**\n * Set a language to default language\n * @param {string} isoCode\n */\nexport function setLanguage(isoCode: string): void {\n const code = isoCode.toLowerCase();\n if (!translations[code]Line truncated
-496
View File
@@ -1,496 +0,0 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, (function () {
var current = global.feiertagejs;
var exports = global.feiertagejs = {};
factory(exports);
exports.noConflict = function () { global.feiertagejs = current; return exports; };
})());
})(this, (function (exports) { 'use strict';
const germanTranslations = {
NEUJAHRSTAG: 'Neujahrstag',
HEILIGEDREIKOENIGE: 'Heilige Drei Könige',
KARFREITAG: 'Karfreitag',
OSTERSONNTAG: 'Ostersonntag',
OSTERMONTAG: 'Ostermontag',
TAG_DER_ARBEIT: 'Tag der Arbeit',
CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',
PFINGSTSONNTAG: 'Pfingstsonntag',
PFINGSTMONTAG: 'Pfingstmontag',
FRONLEICHNAM: 'Fronleichnam',
MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',
DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',
REFORMATIONSTAG: 'Reformationstag',
ALLERHEILIGEN: 'Allerheiligen',
BUBETAG: 'Buß- und Bettag',
ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',
ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',
WELTKINDERTAG: 'Weltkindertag',
WELTFRAUENTAG: 'Weltfrauentag',
AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',
};
const allHolidays = [
'NEUJAHRSTAG',
'HEILIGEDREIKOENIGE',
'KARFREITAG',
'OSTERSONNTAG',
'OSTERMONTAG',
'TAG_DER_ARBEIT',
'CHRISTIHIMMELFAHRT',
'MARIAHIMMELFAHRT',
'PFINGSTSONNTAG',
'PFINGSTMONTAG',
'FRONLEICHNAM',
'DEUTSCHEEINHEIT',
'REFORMATIONSTAG',
'ALLERHEILIGEN',
'BUBETAG',
'ERSTERWEIHNACHTSFEIERTAG',
'ZWEITERWEIHNACHTSFEIERTAG',
'WELTKINDERTAG',
'WELTFRAUENTAG',
'AUGSBURGER_FRIEDENSFEST',
];
const allRegions = [
'BW',
'BY',
'BE',
'BB',
'HB',
'HE',
'HH',
'MV',
'NI',
'NW',
'RP',
'SL',
'SN',
'ST',
'SH',
'TH',
'BUND',
'AUGSBURG',
'ALL',
];
/*!
* feiertage.js
* @repository https://github.com/sfakir/feiertagejs
* @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md
*
* Copyright 2015-2021 Simon Fakir
* Released under the MIT license
*/
// translations
const defaultLanguage = 'de';
let currentLanguage = defaultLanguage;
const translations = {
de: germanTranslations,
};
/**
* adds a translation for the holidays (e.g. english).
* This also allows to override the German names.
* Hint: Interpolates German for missing translations
* @param {string} isoCode of the new language
* @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg
*/
function addTranslation(isoCode, newTranslation) {
const code = isoCode.toLowerCase();
const defaultTranslation = translations[defaultLanguage];
let missingFields = false;
// fill new Translation with default Language
for (const holiday of allHolidays) {
if (!newTranslation[holiday]) {
missingFields = true;
newTranslation[holiday] = defaultTranslation[holiday];
}
}
if (missingFields) {
console.warn('[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback');
}
translations[code] = newTranslation;
}
/**
* Set a language to default language
* @param {string} isoCode
*/
function setLanguage(isoCode) {
const code = isoCode.toLowerCase();
if (!translations[code]) {
throw new TypeError(`[feiertagejs] tried to set language to ${code} but the translation is missing. Please use addTranslation(isoCode,object) first`);
}
currentLanguage = isoCode;
}
/**
* Get currently set language
* @returns {string}
*/
function getLanguage() {
return currentLanguage;
}
// holidays api
/**
* Checks if a specific date is sunday or holiday.
* @param date
* @param region
* @returns {boolean}
*/
function isSunOrHoliday(date, region) {
checkRegion(region);
return date.getDay() === 0 || isHoliday(date, region);
}
/**
* Check is specific date is holiday.
* @param date
* @param {Region} region two character {@link Region} code
* @returns {boolean}
*/
function isHoliday(date, region) {
checkRegion(region);
const year = date.getFullYear();
const internalDate = toUtcTimestamp(date);
const holidays = getHolidaysAsUtcTimestamps(year, region);
return holidays.indexOf(internalDate) !== -1;
}
function getHolidayByDate(date, region = 'ALL') {
checkRegion(region);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
return holidays.find((holiday) => holiday.equals(date));
}
// additional runtime checks
/**
* Checks if the given region is a valid {@link Region}.
*
* @param region {@link Region} to check
* @throws {Error}
* @private
*/
function checkRegion(region) {
if (region === null || region === undefined) {
throw new Error(`Region must not be undefined or null`);
}
if (allRegions.indexOf(region) === -1) {
throw new Error(`Invalid region: ${region}! Must be one of ${allRegions.toString()}`);
}
}
/**
* Checks if the given holidayName is a valid {@link HolidayType}.
* @param holidayName {@link HolidayType} to check
* @throws {Error}
* @private
*/
function checkHolidayType(holidayName) {
if (holidayName === null || holidayName === undefined) {
throw new TypeError('holidayName must not be null or undefined');
}
if (allHolidays.indexOf(holidayName) === -1) {
throw new Error(`feiertage.js: invalid holiday type "${holidayName}"! Must be one of ${allHolidays.toString()}`);
}
}
function isSpecificHoliday(date, holidayName, region = 'ALL') {
checkRegion(region);
checkHolidayType(holidayName);
const holidays = getHolidaysOfYear(date.getFullYear(), region);
const foundHoliday = holidays.find((holiday) => holiday.equals(date));
if (!foundHoliday) {
return false;
}
return foundHoliday.name === holidayName;
}
/**
* Returns all holidays of a year in a {@link Region}.
* @param year
* @param region
* @returns {Array.<Holiday>}
*/
function getHolidays(year, region) {
let y;
if (typeof year === 'string') {
y = parseInt(year, 10);
}
else {
y = year;
}
checkRegion(region);
return getHolidaysOfYear(y, region);
}
/**
*
* @param {number} year
* @param region
* @returns {number[]}
* @private
*/
function getHolidaysAsUtcTimestamps(year, region) {
const holidays = getHolidaysOfYear(year, region);
return holidays.map((holiday) => toUtcTimestamp(holiday.date));
}
/**
*
* @param {number} year
* @param region
* @returns {{objects: Array.<Holiday>, integers}}
* @private
*/
function getHolidaysOfYear(year, region) {
const easterDate = getEasterDate(year);
const karfreitag = addDays(new Date(easterDate.getTime()), -2);
const ostermontag = addDays(new Date(easterDate.getTime()), 1);
const christiHimmelfahrt = addDays(new Date(easterDate.getTime()), 39);
const pfingstsonntag = addDays(new Date(easterDate.getTime()), 49);
const pfingstmontag = addDays(new Date(easterDate.getTime()), 50);
const holidays = [
...getCommonHolidays(year),
newHoliday('KARFREITAG', karfreitag),
newHoliday('OSTERMONTAG', ostermontag),
newHoliday('CHRISTIHIMMELFAHRT', christiHimmelfahrt),
newHoliday('PFINGSTMONTAG', pfingstmontag),
];
addHeiligeDreiKoenige(year, region, holidays);
addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, holidays);
addFronleichnam(region, easterDate, holidays);
addMariaeHimmelfahrt(year, region, holidays);
addReformationstag(year, region, holidays);
addAllerheiligen(year, region, holidays);
addBussUndBetttag(year, region, holidays);
addWeltkindertag(year, region, holidays);
addWeltfrauenTag(year, region, holidays);
addRegionalHolidays(year, region, holidays);
return holidays.sort((a, b) => a.date.getTime() - b.date.getTime());
}
function getCommonHolidays(year) {
return [
newHoliday('NEUJAHRSTAG', makeDate(year, 1, 1)),
newHoliday('TAG_DER_ARBEIT', makeDate(year, 5, 1)),
newHoliday('DEUTSCHEEINHEIT', makeDate(year, 10, 3)),
newHoliday('ERSTERWEIHNACHTSFEIERTAG', makeDate(year, 12, 25)),
newHoliday('ZWEITERWEIHNACHTSFEIERTAG', makeDate(year, 12, 26)),
];
}
function addRegionalHolidays(year, region, feiertageObjects) {
if (region === 'AUGSBURG') {
feiertageObjects.push(newHoliday('AUGSBURGER_FRIEDENSFEST', makeDate(year, 8, 8)));
}
}
function addHeiligeDreiKoenige(year, region, feiertageObjects) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ST' ||
region === 'ALL') {
feiertageObjects.push(newHoliday('HEILIGEDREIKOENIGE', makeDate(year, 1, 6)));
}
}
function addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, feiertageObjects) {
if (region === 'BB' || region === 'ALL') {
feiertageObjects.push(newHoliday('OSTERSONNTAG', easterDate), newHoliday('PFINGSTSONNTAG', pfingstsonntag));
}
}
function addFronleichnam(region, easterDate, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'HE' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
const fronleichnam = addDays(new Date(easterDate.getTime()), 60);
holidays.push(newHoliday('FRONLEICHNAM', fronleichnam));
}
}
function addMariaeHimmelfahrt(year, region, holidays) {
if (region === 'SL' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'ALL') {
holidays.push(newHoliday('MARIAHIMMELFAHRT', makeDate(year, 8, 15)));
}
}
function addReformationstag(year, region, holidays) {
if (year === 2017 ||
region === 'NI' ||
region === 'BB' ||
region === 'HB' ||
region === 'HH' ||
region === 'MV' ||
region === 'SN' ||
region === 'ST' ||
region === 'TH' ||
region === 'SH' ||
region === 'ALL') {
holidays.push(newHoliday('REFORMATIONSTAG', makeDate(year, 10, 31)));
}
}
function addAllerheiligen(year, region, holidays) {
if (region === 'BW' ||
region === 'BY' ||
region === 'AUGSBURG' ||
region === 'NW' ||
region === 'RP' ||
region === 'SL' ||
region === 'ALL') {
holidays.push(newHoliday('ALLERHEILIGEN', makeDate(year, 11, 1)));
}
}
function addBussUndBetttag(year, region, holidays) {
if (region === 'SN' || region === 'ALL') {
// @todo write test
const bussbettag = getBussBettag(year);
holidays.push(newHoliday('BUBETAG', makeDate(bussbettag.getUTCFullYear(), bussbettag.getUTCMonth() + 1, bussbettag.getUTCDate())));
}
}
function addWeltkindertag(year, region, holidays) {
if (year >= 2019 && (region === 'TH' || region === 'ALL')) {
holidays.push(newHoliday('WELTKINDERTAG', makeDate(year, 9, 20)));
}
}
function addWeltfrauenTag(year, region, feiertageObjects) {
if (year <= 2018) {
return;
}
if (region === 'BE' || region === 'ALL') {
// in Berlin ist der Weltfrauentag ein Feiertag seit 2018
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
if (region === 'MV' && year >= 2023) {
// in MV wird der Weltfrauentag erst ab 2023 eingeführt
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
}
}
/**
* Calculates the Easter date of a given year.
* @param year {number}
* @returns {Date} Easter date
* @private
*/
function getEasterDate(year) {
const C = Math.floor(year / 100);
// tslint:disable:binary-expression-operand-order
// tslint generates false positives in the following blocks
const N = year - 19 * Math.floor(year / 19);
const K = Math.floor((C - 17) / 25);
let I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
I -= 30 * Math.floor(I / 30);
I -=
Math.floor(I / 28) *
(1 -
Math.floor(I / 28) *
Math.floor(29 / (I + 1)) *
Math.floor((21 - N) / 11));
let J = year + Math.floor(year / 4) + I + 2 - C + Math.floor(C / 4);
J -= 7 * Math.floor(J / 7);
const L = I - J;
const M = 3 + Math.floor((L + 40) / 44);
const D = L + 28 - 31 * Math.floor(M / 4);
// tslint:enable:binary-expression-operand-order
return new Date(year, M - 1, D);
}
/**
* Computes the "Buss- und Bettag"'s date.
* @param jahr {number}
* @returns {Date} the year's "Buss- und Bettag" date
* @private
*/
function getBussBettag(jahr) {
const weihnachten = new Date(jahr, 11, 25, 12, 0, 0);
const ersterAdventOffset = 32;
let wochenTagOffset = weihnachten.getDay() % 7;
if (wochenTagOffset === 0) {
wochenTagOffset = 7;
}
const tageVorWeihnachten = wochenTagOffset + ersterAdventOffset;
let bbtag = new Date(weihnachten.getTime());
bbtag = addDays(bbtag, -tageVorWeihnachten);
return bbtag;
}
/**
* Adds {@code days} days to the given {@link Date}.
* @param date
* @param days
* @returns {Date}
* @private
*/
function addDays(date, days) {
const changedDate = new Date(date);
changedDate.setDate(date.getDate() + days);
return changedDate;
}
/**
* Creates a new {@link Date}.
* @param year
* @param naturalMonth month (1-12)
* @param day
* @returns {Date}
* @private
*/
function makeDate(year, naturalMonth, day) {
return new Date(year, naturalMonth - 1, day);
}
/**
*
* @param name
* @param date
* @returns {Holiday}
* @private
*/
function newHoliday(name, date) {
return {
name,
date,
dateString: localeDateObjectToDateString(date),
trans(lang = currentLanguage) {
console.warn('FeiertageJs: You are using "Holiday.trans() method. This will be replaced in the next major version with translate()"');
return this.translate(lang);
},
translate(lang = currentLanguage) {
return lang === undefined || lang === null
? undefined
: translations[lang][this.name];
},
getNormalizedDate() {
return toUtcTimestamp(this.date);
},
equals(otherDate) {
const dateString = localeDateObjectToDateString(otherDate);
return this.dateString === dateString;
},
};
}
/**
*
* @param date
* @returns {string}
* @private
*/
function localeDateObjectToDateString(date) {
const normalizedDate = new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
normalizedDate.setUTCHours(0, 0, 0, 0);
return normalizedDate.toISOString().slice(0, 10);
}
/**
* Returns the UTC timestamp of the given date with hours, minutes, seconds, and milliseconds set to zero.
* @param date
* @returns {number} UTC timestamp
*/
function toUtcTimestamp(date) {
const internalDate = new Date(date);
internalDate.setHours(0, 0, 0, 0);
return internalDate.getTime();
}
exports.addTranslation = addTranslation;
exports.getHolidayByDate = getHolidayByDate;
exports.getHolidays = getHolidays;
exports.getLanguage = getLanguage;
exports.isHoliday = isHoliday;
exports.isSpecificHoliday = isSpecificHoliday;
exports.isSunOrHoliday = isSunOrHoliday;
exports.setLanguage = setLanguage;
}));
//# sourceMappingURL=feiertage.umd.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"feiertage.umd.js","sources":["../src/german-translations.ts","../src/holiday-type.ts","../src/regions.ts","../src/feiertage.ts"],"sourcesContent":["import { TranslationTable } from './feiertage';\n\nexport const germanTranslations: TranslationTable = {\n NEUJAHRSTAG: 'Neujahrstag',\n HEILIGEDREIKOENIGE: 'Heilige Drei Könige',\n KARFREITAG: 'Karfreitag',\n OSTERSONNTAG: 'Ostersonntag',\n OSTERMONTAG: 'Ostermontag',\n TAG_DER_ARBEIT: 'Tag der Arbeit',\n CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',\n PFINGSTSONNTAG: 'Pfingstsonntag',\n PFINGSTMONTAG: 'Pfingstmontag',\n FRONLEICHNAM: 'Fronleichnam',\n MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',\n DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',\n REFORMATIONSTAG: 'Reformationstag',\n ALLERHEILIGEN: 'Allerheiligen',\n BUBETAG: 'Buß- und Bettag',\n ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',\n ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',\n WELTKINDERTAG: 'Weltkindertag',\n WELTFRAUENTAG: 'Weltfrauentag',\n AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',\n};\n","export type HolidayType =\n | 'NEUJAHRSTAG'\n | 'HEILIGEDREIKOENIGE'\n | 'KARFREITAG'\n | 'OSTERSONNTAG'\n | 'OSTERMONTAG'\n | 'TAG_DER_ARBEIT'\n | 'CHRISTIHIMMELFAHRT'\n | 'MARIAHIMMELFAHRT'\n | 'PFINGSTSONNTAG'\n | 'PFINGSTMONTAG'\n | 'FRONLEICHNAM'\n | 'DEUTSCHEEINHEIT'\n | 'REFORMATIONSTAG'\n | 'ALLERHEILIGEN'\n | 'BUBETAG'\n | 'ERSTERWEIHNACHTSFEIERTAG'\n | 'ZWEITERWEIHNACHTSFEIERTAG'\n | 'WELTKINDERTAG'\n | 'WELTFRAUENTAG'\n | 'AUGSBURGER_FRIEDENSFEST';\n\nexport const allHolidays: HolidayType[] = [\n 'NEUJAHRSTAG',\n 'HEILIGEDREIKOENIGE',\n 'KARFREITAG',\n 'OSTERSONNTAG',\n 'OSTERMONTAG',\n 'TAG_DER_ARBEIT',\n 'CHRISTIHIMMELFAHRT',\n 'MARIAHIMMELFAHRT',\n 'PFINGSTSONNTAG',\n 'PFINGSTMONTAG',\n 'FRONLEICHNAM',\n 'DEUTSCHEEINHEIT',\n 'REFORMATIONSTAG',\n 'ALLERHEILIGEN',\n 'BUBETAG',\n 'ERSTERWEIHNACHTSFEIERTAG',\n 'ZWEITERWEIHNACHTSFEIERTAG',\n 'WELTKINDERTAG',\n 'WELTFRAUENTAG',\n 'AUGSBURGER_FRIEDENSFEST',\n];\n","export type Region =\n | 'BW' // Baden-Württemberg\n | 'BY' // Bayern\n | 'BE' // Berlin\n | 'BB' // Brandenburg\n | 'HB' // Bremen\n | 'HE' // Hessen\n | 'HH' // Hamburg\n | 'MV' // Mecklenburg-Vorpommern\n | 'NI' // Niedersachsen\n | 'NW' // Nordrhein-Westfalen\n | 'RP' // Rheinland-Pfalz\n | 'SL' // Saarland\n | 'SN' // Sachsen\n | 'ST' // Sachsen-Anhalt\n | 'SH' // Schleswig-Holstein\n | 'TH' // Thüringen\n | 'BUND' // Gesamt-Deutschland\n // Custom regions with local holidays (incompelte) !\n | 'AUGSBURG'\n | 'ALL';\n\nexport const allRegions: Region[] = [\n 'BW',\n 'BY',\n 'BE',\n 'BB',\n 'HB',\n 'HE',\n 'HH',\n 'MV',\n 'NI',\n 'NW',\n 'RP',\n 'SL',\n 'SN',\n 'ST',\n 'SH',\n 'TH',\n 'BUND',\n 'AUGSBURG',\n 'ALL',\n];\n","/*!\n * feiertage.js\n * @repository https://github.com/sfakir/feiertagejs\n * @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md\n *\n * Copyright 2015-2021 Simon Fakir\n * Released under the MIT license\n */\n\n//\n// Additional readings\n// - how to format a javascript date: http://blog.stevenlevithan.com/archives/date-time-format\n// - the right javascript date: http://stackoverflow.com/questions/10286204/the-right-json-date-format\n//\n\nimport { germanTranslations } from './german-translations';\nimport { Holiday } from './holiday';\nimport { allHolidays, HolidayType } from './holiday-type';\nimport { allRegions, Region } from './regions';\n\n// translations\n\nconst defaultLanguage = 'de';\nlet currentLanguage: string = defaultLanguage;\n\n/**\n * Map of {@link HolidayType} to translation string.\n */\nexport type TranslationTable = { [key in HolidayType]?: string };\n\nconst translations: { [key: string]: TranslationTable } = {\n de: germanTranslations,\n};\n\n/**\n * adds a translation for the holidays (e.g. english).\n * This also allows to override the German names.\n * Hint: Interpolates German for missing translations\n * @param {string} isoCode of the new language\n * @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg\n */\nexport function addTranslation(\n isoCode: string,\n newTranslation: TranslationTable,\n): void {\n const code = isoCode.toLowerCase();\n const defaultTranslation = translations[defaultLanguage];\n let missingFields = false;\n\n // fill new Translation with default Language\n for (const holiday of allHolidays) {\n if (!newTranslation[holiday]) {\n missingFields = true;\n newTranslation[holiday] = defaultTranslation[holiday];\n }\n }\n if (missingFields) {\n console.warn(\n '[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback',\n );\n }\n\n translations[code] = newTranslation;\n}\n\n/**\n * Set a language to default language\n * @param {string} isoCode\n */\nexport function setLanguage(isoCode: string): void {\n const code = isoCode.toLowerCase();\n if (!translations[code])Line truncated
-144
View File
@@ -1,144 +0,0 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
*Types*
- [HolidayType](#holidaytype)
- [Region](#region)
- [Holiday](#holiday)
- [allHolidays](#allholidays)
- [allRegions](#allregions)
- [TranslationTable](#translationtable)
*API*
- [isHoliday(date, region)](#isholiday)
- [getHolidayByDate(date, region)](#getholidaybydate)
- [getHolidays(year, region)](#getholidays)
- [isSunOrHoliday(date, region)](#issunorholiday)
- [isSpecificHoliday(date, name, region)](#isspecificholiday)
- [addTranslation(isoCode, translation)](#addtranslation)
- [setLanguage(lng)](#setlanguage)
- [getLanguage()](#getlanguage)
## Types
### HolidayType
Type: (`"NEUJAHRSTAG"` \| `"HEILIGEDREIKOENIGE"` \| `"KARFREITAG"` \| `"OSTERSONNTAG"` \| `"OSTERMONTAG"` \| `"TAG_DER_ARBEIT"` \| `"CHRISTIHIMMELFAHRT"` \| `"MARIAHIMMELFAHRT"` \| `"PFINGSTSONNTAG"` \| `"PFINGSTMONTAG"` \| `"FRONLEICHNAM"` \| `"DEUTSCHEEINHEIT"` \| `"REFORMATIONSTAG"` \| `"ALLERHEILIGEN"` \| `"BUBETAG"` \| `"ERSTERWEIHNACHTSFEIERTAG"` \| `"ZWEITERWEIHNACHTSFEIERTAG"` \| `"WELTKINDERTAG"` \| `"WELTFRAUENTAG"` \| `"AUGSBURGER_FRIEDENSFEST"`)
### Region
Type: (`"BW"` \| `"BY"` \| `"BE"` \| `"BB"` \| `"HB"` \| `"HE"` \| `"HH"` \| `"MV"` \| `"NI"` \| `"NW"` \| `"RP"` \| `"SL"` \| `"SN"` \| `"ST"` \| `"SH"` \| `"TH"` \| `"BUND"` \| `"ALL"`)
As defined here: https://de.wikipedia.org/wiki/Land_(Deutschland)#Amtliche_bzw._Eigenbezeichnungen
The difference between BUND and ALL is defined as follows:
* "ALL" refers to every holiday which is valid in **at least** one region. So a holiday that only applies to one state will be included.
* "BUND" refers to holidays that are valid in every region ("bundesweit"). So a holiday that only applies to one state will not be included.
### Holiday
Type: {name: [HolidayType](#holidaytype), date: [Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date), trans: function (lang: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?): [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), dateString: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), equals: function (date: [Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)}
**Properties**
- `name` **[HolidayType](#holidaytype)**
- `date` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)**
- `trans` **function (lang: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?): [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `dateString` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `equals` **function (date: [Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### allHolidays
Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[HolidayType](#holidaytype)>
### allRegions
Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Region](#region)>
### TranslationTable
Map of [HolidayType](#holidaytype) to translation string.
Type: {}
## API
### addTranslation()
Adds a translation for the holidays (e.g. English).
This also allows overriding the German names.
Hint: Interpolates German for missing translations
**Parameters**
- `isoCode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of the new language
- `newTranslation` **[TranslationTable](#translationtable)** map of {HolidayType} to translation stringg
### setLanguage()
Set a language to default language
**Parameters**
- `isoCode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
### getLanguage()
Get currently set language
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
### isSunOrHoliday()
Checks if a specific date is sunday or holiday.
**Parameters**
- `date` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)**
- `region` **[Region](#region)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### isHoliday()
Check is specific date is holiday.
**Parameters**
- `date` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)**
- `region` **[Region](#region)** two character [Region](#region) code
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### getHolidayByDate()
**Parameters**
- `date` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)**
- `region` **[Region](#region)** (optional, default `'ALL'`)
Returns **([Holiday](#holiday) | void)**
### isSpecificHoliday()
**Parameters**
- `date` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)**
- `holidayName` **[HolidayType](#holidaytype)**
- `region` **[Region](#region)** (optional, default `'ALL'`)
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### getHolidays()
Returns all holidays of a year in a [Region](#region).
**Parameters**
- `year` **([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**
- `region` **[Region](#region)**
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Holiday](#holiday)>**
-113
View File
@@ -1,113 +0,0 @@
declare type Region =
| 'BW' // Baden-Württemberg
| 'BY' // Bayern
| 'BE' // Berlin
| 'BB' // Brandenburg
| 'HB' // Bremen
| 'HE' // Hessen
| 'HH' // Hamburg
| 'MV' // Mecklenburg-Vorpommern
| 'NI' // Niedersachsen
| 'NW' // Nordrhein-Westfalen
| 'RP' // Rheinland-Pfalz
| 'SL' // Saarland
| 'SN' // Sachsen
| 'ST' // Sachsen-Anhalt
| 'SH' // Schleswig-Holstein
| 'TH' // Thüringen
| 'BUND' // Gesamt-Deutschland
| 'AUGSBURG'
| 'ALL';
declare type Holiday = {
name: HolidayType;
date: Date;
trans?: (lang: string | undefined) => string; // deprecated;
translate: (lang?: string | undefined) => string;
dateString: string;
equals: (date: Date) => boolean;
};
declare type HolidayType =
| 'NEUJAHRSTAG'
| 'HEILIGEDREIKOENIGE'
| 'KARFREITAG'
| 'OSTERSONNTAG'
| 'OSTERMONTAG'
| 'TAG_DER_ARBEIT'
| 'CHRISTIHIMMELFAHRT'
| 'MARIAHIMMELFAHRT'
| 'PFINGSTSONNTAG'
| 'PFINGSTMONTAG'
| 'FRONLEICHNAM'
| 'DEUTSCHEEINHEIT'
| 'REFORMATIONSTAG'
| 'ALLERHEILIGEN'
| 'BUBETAG'
| 'ERSTERWEIHNACHTSFEIERTAG'
| 'ZWEITERWEIHNACHTSFEIERTAG';
/**
* Map of {@link HolidayType} to translation string.
*/
export type TranslationTable = {
[key: string]: string;
};
/**
* adds a translation for the holidays (e.g. english).
* This also allows to override the German names.
* Hint: Interpolates German for missing translations
* @param {string} isoCode of the new language
* @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg
*/
declare function addTranslation(
isoCode: string,
newTranslation: TranslationTable,
): void;
/**
* Set a language to default language
* @param {string} isoCode
*/
declare function setLanguage(isoCode: string): void;
/**
* Get currently set language
* @returns {string}
*/
declare function getLanguage(): string;
// holidays api
/**
* Checks if a specific date is sunday or holiday.
* @param date
* @param region
* @returns {boolean}
*/
declare function isSunOrHoliday(date: Date, region: Region): boolean;
/**
* Check is specific date is holiday.
* @param date
* @param {Region} region two character {@link Region} code
* @returns {boolean}
*/
declare function isHoliday(date: Date, region: Region): boolean;
declare function getHolidayByDate(date: Date, region: Region): Holiday | void;
declare function isSpecificHoliday(
date: Date,
holidayName: HolidayType,
region: Region,
): boolean;
/**
* Returns all holidays of a year in a {@link Region}.
* @param year
* @param region
* @returns {Array.<Holiday>}
*/
declare function getHolidays(year: number | string, region: Region): Holiday[];
-53
View File
@@ -1,53 +0,0 @@
{
"name": "feiertagejs",
"version": "1.3.9",
"description": "A module to calculate German holidays made for node.js",
"type": "module",
"main": "build/feiertage.umd.cjs",
"module": "build/feiertage.js",
"types": "index.d.ts",
"scripts": {
"test": "vitest run --coverage",
"test:w": "vitest watch",
"format": "prettier --write \"{**/*,*}.{ts,json}\" \"!coverage/**\" \"!build/**\" \"!package.json\" \"!package-lock.json\" --cache",
"lint": "eslint \"src\" \"spec\"",
"build": "rollup -c"
},
"repository": {
"type": "git",
"url": "https://github.com/sfakir/feiertagejs"
},
"keywords": [
"node",
"holidays",
"feiertage",
"javascript"
],
"engines": {
"node": ">=8.0.0"
},
"author": "Simon Fakir",
"license": "MIT",
"bugs": {
"url": "https://github.com/sfakir/feiertagejs/issues"
},
"homepage": "https://github.com/sfakir/feiertagejs",
"devDependencies": {
"@vitest/coverage-c8": "^0.26.2",
"prettier": "^2.8.1",
"rollup": "^3.9.0",
"@rollup/plugin-typescript": "^10.0.1",
"typescript": "^4.9.4",
"vitest": "^0.26.2",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0"
},
"files": [
"build",
"docs.md",
"Readme.md",
"index.d.ts"
]
}
-20
View File
@@ -1,20 +0,0 @@
{
"name": "TIF22A_AnwProjekt_B",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"feiertagejs": "^1.3.9"
}
},
"node_modules/feiertagejs": {
"version": "1.3.9",
"resolved": "https://registry.npmjs.org/feiertagejs/-/feiertagejs-1.3.9.tgz",
"integrity": "sha512-tUP+WBv2OWBhPwe3NfqwCtjMq+ym598a42tfqmL0FySswEb9xs96p2iKwqqx+lxKieu1njJBRZKsFm92bJhxZw==",
"engines": {
"node": ">=8.0.0"
}
}
}
}
-5
View File
@@ -1,5 +0,0 @@
{
"dependencies": {
"feiertagejs": "^1.3.9"
}
}