Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
katemihalikova committed Mar 14, 2017
0 parents commit 13dce7b
Show file tree
Hide file tree
Showing 17 changed files with 730 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
out/
tmp/
debug.log
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- lts/*
script: bash ./.travis/deploy.sh
env:
global:
- ENCRYPTION_LABEL: 85b4c7448974
2 changes: 2 additions & 0 deletions .travis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
repo.key
repo.key.pub
64 changes: 64 additions & 0 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
set -e # Exit with nonzero exit code if anything fails

SOURCE_BRANCH="develop"
TARGET_BRANCH="gh-pages"

# Run build and test scripts
npm run build
npm test

# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
echo "Skipping deploy; just doing a build."
exit 0
fi

# Save some useful information
REPO=`git config remote.origin.url`
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
SHA=`git rev-parse --verify HEAD`

# Clone the existing gh-pages for this repo into out/
# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deploy)
git clone $REPO out
cd out
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH

# Clean out existing contents
ls -A | grep -vx .git | xargs rm -rf || exit 0
cd ..

# Run deploy scripts
npm run build-demo

# Now let's go have some fun with the cloned repo
cd out
git config user.name "Katebot"
git config user.email "[email protected]"

# If there are no changes to the compiled out (e.g. this is a README update) then just bail.
if git diff --exit-code > /dev/null; then
echo "No changes to the output on this push; exiting."
exit 0
fi

# Commit the "changes", i.e. the new version.
# The delta will show diffs between new and old versions.
git add --all .
git commit -m "Deploy to GitHub Pages ${SHA}"
cd ..

# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in .travis/repo.key.enc -out .travis/repo.key -d
chmod 600 .travis/repo.key
eval `ssh-agent -s`
ssh-add .travis/repo.key

# Now that we're all set up, we can push.
cd out
git push $SSH_REPO $TARGET_BRANCH
Binary file added .travis/repo.key.enc
Binary file not shown.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Kate Miháliková

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.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# asgardia-calendar-converter

@TODO documentation
133 changes: 133 additions & 0 deletions demo/demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import {Datum, isAsgardianYearLeap, isGregorianYearLeap, toAsgardian, toGregorian} from "../src/index";

let el = {
gre_d: document.getElementById("gre_d") as HTMLSelectElement,
gre_m: document.getElementById("gre_m") as HTMLSelectElement,
gre_y: document.getElementById("gre_y") as HTMLInputElement,
gre_w: document.getElementById("gre_w") as HTMLTableCellElement,
gre_29: document.getElementById("gre_29") as HTMLOptionElement,
gre_30: document.getElementById("gre_30") as HTMLOptionElement,
gre_31: document.getElementById("gre_31") as HTMLOptionElement,
feb_d: document.getElementById("feb_d") as HTMLSelectElement,
feb_m: document.getElementById("feb_m") as HTMLSelectElement,
feb_y: document.getElementById("feb_y") as HTMLInputElement,
feb_w: document.getElementById("feb_w") as HTMLTableCellElement,
feb_l: document.getElementById("feb_l") as HTMLOptionElement,
feb_13: document.getElementById("feb_13") as HTMLOptionElement,
jun_d: document.getElementById("jun_d") as HTMLSelectElement,
jun_m: document.getElementById("jun_m") as HTMLSelectElement,
jun_y: document.getElementById("jun_y") as HTMLInputElement,
jun_w: document.getElementById("jun_w") as HTMLTableCellElement,
jun_l: document.getElementById("jun_l") as HTMLOptionElement,
jun_13: document.getElementById("jun_13") as HTMLOptionElement,
non_d: document.getElementById("non_d") as HTMLSelectElement,
non_m: document.getElementById("non_m") as HTMLSelectElement,
non_y: document.getElementById("non_y") as HTMLInputElement,
non_w: document.getElementById("non_w") as HTMLTableCellElement,
non_13: document.getElementById("non_13") as HTMLOptionElement,
};

function changed(gre: Datum) {
let greDaysInMonths = [, 31, isGregorianYearLeap(gre.year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
let feb = toAsgardian(gre, "feb");
let jun = toAsgardian(gre, "jun");
let non = toAsgardian(gre, "non");

el.gre_y.value = String(gre.year);
el.gre_m.value = String(gre.month);
el.gre_d.value = String(gre.day);
el.gre_29.style.display = greDaysInMonths[gre.month] >= 29 ? "" : "none";
el.gre_30.style.display = greDaysInMonths[gre.month] >= 30 ? "" : "none";
el.gre_31.style.display = greDaysInMonths[gre.month] >= 31 ? "" : "none";
el.feb_y.value = String(feb.year);
el.feb_m.value = String(feb.month);
el.feb_d.value = feb.day === 29 ? feb.day + "-" + feb.month : String(feb.day);
el.feb_l.style.display = isAsgardianYearLeap(feb.year) && feb.month === 2 ? "" : "none";
el.feb_13.style.display = feb.month === 13 ? "" : "none";
el.jun_y.value = String(jun.year);
el.jun_m.value = String(jun.month);
el.jun_d.value = jun.day === 29 ? jun.day + "-" + jun.month : String(jun.day);
el.jun_l.style.display = isAsgardianYearLeap(jun.year) && jun.month === 6 ? "" : "none";
el.jun_13.style.display = jun.month === 13 ? "" : "none";
el.non_y.value = String(non.year);
el.non_m.value = String(non.month);
el.non_d.value = String(non.day);
el.non_13.style.display = non.month === 13 ? "" : "none";

let daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let greDate = new Date(2000, gre.month - 1, gre.day);
greDate.setFullYear(gre.year);
el.gre_w.innerText = daysOfWeek[greDate.getDay()];

el.feb_w.innerText = daysOfWeek[(feb.day - 1) % 7];
el.jun_w.innerText = daysOfWeek[(jun.day - 1) % 7];
el.non_w.innerText = daysOfWeek[(non.day - 1) % 7];

if (feb.month === 2 && feb.day === 29) {
el.feb_w.innerText = "Leap Day";
}
if (feb.month === 13 && feb.day === 29) {
el.feb_w.innerText = "Year Day";
}
if (jun.month === 6 && jun.day === 29) {
el.jun_w.innerText = "Leap Day";
}
if (jun.month === 13 && jun.day === 29) {
el.jun_w.innerText = "Year Day";
}
if (non.month === 13 && non.day === 29) {
el.non_w.innerText = "Year Day";
}
}

function greChanged(): void {
let gre = {day: Number(el.gre_d.value), month: Number(el.gre_m.value), year: Number(el.gre_y.value)};
let greDaysInMonths = [, 31, isGregorianYearLeap(gre.year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if (gre.day > greDaysInMonths[gre.month]) {
gre.day = greDaysInMonths[gre.month];
}
changed(gre);
}

function febChanged(): void {
let feb = {day: Number(el.feb_d.value.split("-")[0]), month: Number(el.feb_m.value), year: Number(el.feb_y.value)};
let febDaysInMonths = [, 28, isAsgardianYearLeap(feb.year) ? 29 : 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29];
if (feb.day > febDaysInMonths[feb.month]) {
feb.day = febDaysInMonths[feb.month];
}
changed(toGregorian(feb, "feb"));
}

function junChanged(): void {
let jun = {day: Number(el.jun_d.value.split("-")[0]), month: Number(el.jun_m.value), year: Number(el.jun_y.value)};
let junDaysInMonths = [, 28, 28, 28, 28, 28, isAsgardianYearLeap(jun.year) ? 29 : 28, 28, 28, 28, 28, 28, 28, 29];
if (jun.day > junDaysInMonths[jun.month]) {
jun.day = junDaysInMonths[jun.month];
}
changed(toGregorian(jun, "jun"));
}

function nonChanged(): void {
let non = {day: Number(el.non_d.value), month: Number(el.non_m.value), year: Number(el.non_y.value)};
let nonDaysInMonths = [, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29];
if (non.day > nonDaysInMonths[non.month]) {
non.day = nonDaysInMonths[non.month];
}
changed(toGregorian(non, "non"));
}

el.gre_y.addEventListener("change", greChanged, false);
el.gre_m.addEventListener("change", greChanged, false);
el.gre_d.addEventListener("change", greChanged, false);
el.feb_y.addEventListener("change", febChanged, false);
el.feb_m.addEventListener("change", febChanged, false);
el.feb_d.addEventListener("change", febChanged, false);
el.jun_y.addEventListener("change", junChanged, false);
el.jun_m.addEventListener("change", junChanged, false);
el.jun_d.addEventListener("change", junChanged, false);
el.non_y.addEventListener("change", nonChanged, false);
el.non_m.addEventListener("change", nonChanged, false);
el.non_d.addEventListener("change", nonChanged, false);

let now = new Date();
changed({day: now.getDate(), month: now.getMonth(), year: now.getFullYear()});
Loading

0 comments on commit 13dce7b

Please sign in to comment.