From: adrianiainlam Date: Mon, 9 May 2016 13:09:25 +0000 (+0100) Subject: Initial commit X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=c2c14655e4da36c46f245fe9ad421d3b290ae600;p=indicator-lunar-calendar.git Initial commit --- c2c14655e4da36c46f245fe9ad421d3b290ae600 diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d568a8 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# indicator-lunar-calendar + +An application indicator for Unity that displays the current date and time +in lunar calendar. + +Copyright (c) 2016 Adrian I Lam + +*Not to be confused with [indicator-lunar][1], which shows attributes and +ephemerides for astronomical objects.* + +[1]: https://launchpad.net/~thebernmeister/+archive/ubuntu/ppa + +## Dependencies + + - [Node.js][2] + + Note: node-gtk, one of this program's dependencies, requires nodejs version + 5 or above. + + [2]: https://nodejs.org/en/ + + - [node-gtk][3] (by @WebReflection) + + npm package: https://www.npmjs.com/package/node-gtk + + Dependencies: build-essential, git, nodejs (>= 5), gobject-introspection, + libgirepository1.0-dev + + Note: This package failed to build for me. I had to remove `-Werror` from + `cflags` in file "bindings.gyp" to get it to build. + + [3]: https://github.com/WebReflection/node-gtk + + - [lunar-calendar-zh][4] (by @roadmanfong) + + npm package: https://www.npmjs.com/package/lunar-calendar-zh + + Note: This package contains a bug which renders it useless if your computer + is set to a time zone which observes Daylight Saving. I have forked it and + fixed it in . + + [4]: https://github.com/roadmanfong/LunarCalendar + + - [node-cron][5] (by @ncb000gt) + + npm package: https://www.npmjs.com/package/cron + + [5]: https://github.com/ncb000gt/node-cron + +## Usage + + 1. Install the dependencies listed above. + 2. Clone this repository. + 3. Add the script as a startup application. + 4. Run the script manually for the first time. (Alternatively, log out + and log in again.) + 5. The indicator should be shown at the top right corner, having an icon + that shows the year and a label that shows the month and date. + 6. Clicking on the indicator should result in a menu with more detailed + information including the time. + +## License + +This program is released under the MIT License. For the full text of this +license, please refer to the file "indicator-lunar-calendar.js". diff --git a/indicator-lunar-calendar.js b/indicator-lunar-calendar.js new file mode 100755 index 0000000..77b778d --- /dev/null +++ b/indicator-lunar-calendar.js @@ -0,0 +1,85 @@ +#!/usr/bin/env node +/* + * indicator-lunar-calendar - shows lunar calendar information + * Copyright (c) 2016 Adrian I Lam + * + * 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 AUTHOR 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. + */ + +/* import dependencies */ +var GNode = require('node-gtk'); +var Gtk = GNode.importNS('Gtk'); +var AppIndicator3 = GNode.importNS('AppIndicator3'); +var CronJob = require('cron').CronJob; +var LunarCalendar = require('lunar-calendar-zh'); + +/* setup indicator object */ +GNode.startLoop(); +Gtk.init(null); +var indicator = AppIndicator3.Indicator.new( + "lunar-indicator", + __dirname + '/鼠.svg', + AppIndicator3.IndicatorCategory.APPLICATION_STATUS +); +indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE); +var menu = new Gtk.Menu(); +var item = new Gtk.MenuItem(); +menu.append(item); +indicator.set_menu(menu); +menu.show_all(); + +function update_indicator() { + /* get current time at UTC+8, add 1 to date if after 23:00 (子時) */ + var now = new Date(new Date().getTime() + 8 * 3600 * 1000); + var hour = now.getUTCHours(); + if(hour >= 23) { // 子時 of the next day + now = new Date(now.getTime() + 24 * 3600 * 1000); + } + var year = now.getUTCFullYear(); + var month = now.getUTCMonth() + 1; + var day = now.getUTCDate(); + + /* obtain date/time in lunar calendar */ + var lunar = LunarCalendar.solarToLunar(year, month, day); + lunar.hour = '子丑寅卯辰巳午未申酉戌亥'[Math.floor((hour + 1) % 24 / 2)]; + + /* output formatting */ + var compact_date = lunar.lunarMonthName + lunar.lunarDayName; + var long_date = lunar.GanZhiYear + '年(' + lunar.zodiac + '年)\n' + + lunar.lunarMonthName + lunar.lunarDayName; + if(lunar.term) { // add solar term (節氣) to output if at solar term + compact_date += ' ' + lunar.term; + long_date += ' ' + lunar.term; + } + long_date += '\n' + lunar.hour + '時'; + + /* output to indicator */ + indicator.set_icon(__dirname + '/' + lunar.zodiac + '.svg'); + indicator.set_label(compact_date, ''); + item.set_label(long_date); +} + +var job = new CronJob({ + cronTime: '0 * * * *', // every hour + onTick: update_indicator, + start: true +}); + +update_indicator(); +Gtk.main(); diff --git "a/\345\205\224.svg" "b/\345\205\224.svg" new file mode 100644 index 0000000..f7846d3 --- /dev/null +++ "b/\345\205\224.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\347\211\233.svg" "b/\347\211\233.svg" new file mode 100644 index 0000000..7822f51 --- /dev/null +++ "b/\347\211\233.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\347\213\227.svg" "b/\347\213\227.svg" new file mode 100644 index 0000000..4d15922 --- /dev/null +++ "b/\347\213\227.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\347\214\264.svg" "b/\347\214\264.svg" new file mode 100644 index 0000000..02f1e81 --- /dev/null +++ "b/\347\214\264.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\347\276\212.svg" "b/\347\276\212.svg" new file mode 100644 index 0000000..8741358 --- /dev/null +++ "b/\347\276\212.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\350\231\216.svg" "b/\350\231\216.svg" new file mode 100644 index 0000000..c6ec261 --- /dev/null +++ "b/\350\231\216.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\350\233\207.svg" "b/\350\233\207.svg" new file mode 100644 index 0000000..b676422 --- /dev/null +++ "b/\350\233\207.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\350\261\254.svg" "b/\350\261\254.svg" new file mode 100644 index 0000000..b6394f1 --- /dev/null +++ "b/\350\261\254.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\351\233\236.svg" "b/\351\233\236.svg" new file mode 100644 index 0000000..d624b52 --- /dev/null +++ "b/\351\233\236.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\351\246\254.svg" "b/\351\246\254.svg" new file mode 100644 index 0000000..7afa950 --- /dev/null +++ "b/\351\246\254.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\351\274\240.svg" "b/\351\274\240.svg" new file mode 100644 index 0000000..0cbab49 --- /dev/null +++ "b/\351\274\240.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git "a/\351\276\215.svg" "b/\351\276\215.svg" new file mode 100644 index 0000000..2f9614e --- /dev/null +++ "b/\351\276\215.svg" @@ -0,0 +1,57 @@ + + + + + + image/svg+xml + + + + + + + + + +