Skip to content

Instantly share code, notes, and snippets.

@behnammodi
Last active November 12, 2020 10:55
Show Gist options
  • Save behnammodi/dc1db42fff9c263060f6c4cd7d205d56 to your computer and use it in GitHub Desktop.
Save behnammodi/dc1db42fff9c263060f6c4cd7d205d56 to your computer and use it in GitHub Desktop.

Revisions

  1. behnammodi revised this gist Nov 12, 2020. 1 changed file with 1 addition and 63 deletions.
    64 changes: 1 addition & 63 deletions ios-widget-global-calendar.js
    Original file line number Diff line number Diff line change
    @@ -1,63 +1 @@
    const LOCALE = args.widgetParameter || "fa-ir";

    const COLOR_BACKGROUND = Color.dynamic(
    new Color("ffffff", 1),
    new Color("222222", 1)
    );
    const COLOR_TEXT = Color.dynamic(
    new Color("222222", 1),
    new Color("ffffff", 1)
    );
    const COLOR_BODY = Color.dynamic(
    new Color("666666", 1),
    new Color("cccccc", 1)
    );
    const TYPOGRAPHY_TITLE = Font.boldSystemFont(40);
    const TYPOGRAPHY_HEADER = Font.systemFont(30);
    const TYPOGRAPHY_BODY = Font.systemFont(15);

    function renderYearAndMonth(widget, { year, month }) {
    const text = widget.addText(`${month} ${year}`);
    text.centerAlignText();
    text.textColor = COLOR_BODY;
    text.font = TYPOGRAPHY_BODY;
    }

    function renderDay(widget, { day }) {
    const text = widget.addText("🗓" + day);
    text.centerAlignText();
    text.textColor = COLOR_TEXT;
    text.font = TYPOGRAPHY_TITLE;
    }

    function renderWeekday(widget, { weekday }) {
    const text = widget.addText(weekday);
    text.centerAlignText();
    text.textColor = COLOR_TEXT;
    text.font = TYPOGRAPHY_HEADER;
    }

    function render() {
    const date = new Date();

    const year = date.toLocaleDateString(LOCALE, { year: "numeric" });
    const month = date.toLocaleDateString(LOCALE, { month: "long" });
    const day = date.toLocaleDateString(LOCALE, { day: "numeric" });
    const weekday = date.toLocaleDateString(LOCALE, { weekday: "long" });

    const widget = new ListWidget();

    widget.backgroundColor = COLOR_BACKGROUND;

    renderDay(widget, { day });

    renderWeekday(widget, { weekday });

    renderYearAndMonth(widget, { year, month });

    return widget;
    }

    Script.name("Global Calendar");
    Script.setWidget(render());
    Script.complete();
    // goto https://github.com/behnammodi/ios-widget-global-calendar
  2. behnammodi revised this gist Nov 12, 2020. No changes.
  3. behnammodi revised this gist Nov 12, 2020. No changes.
  4. behnammodi revised this gist Nov 12, 2020. No changes.
  5. behnammodi renamed this gist Nov 12, 2020. 1 changed file with 21 additions and 23 deletions.
    44 changes: 21 additions & 23 deletions ios-widget-hijri-calendar.js → ios-widget-global-calendar.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    const LOCALE = args.widgetParameter || "fa-ir";

    const COLOR_BACKGROUND = Color.dynamic(
    new Color("ffffff", 1),
    new Color("222222", 1)
    @@ -10,56 +12,52 @@ const COLOR_BODY = Color.dynamic(
    new Color("666666", 1),
    new Color("cccccc", 1)
    );
    const TYPOGRAPHY_TITLE = Font.boldSystemFont(60);
    const TYPOGRAPHY_BODY = Font.boldSystemFont(20);

    const getMonthName = (month) =>
    ({
    "۱": "فروردین",
    "۲": "اردیبهشت",
    "۳": "خرداد",
    "۴": "تیر",
    "۵": "مرداد",
    "۶": "شهریور",
    "۷": "مهر",
    "۸": "آبان",
    "۹": "آذر",
    "۱۰": "دی",
    "۱۱": "بهمن",
    "۱۲": "اسفند",
    }[month]);
    const TYPOGRAPHY_TITLE = Font.boldSystemFont(40);
    const TYPOGRAPHY_HEADER = Font.systemFont(30);
    const TYPOGRAPHY_BODY = Font.systemFont(15);

    function renderYearAndMonth(widget, { year, month }) {
    const text = widget.addText(`${getMonthName(month)} 🗓 ${year}`);
    const text = widget.addText(`${month} ${year}`);
    text.centerAlignText();
    text.textColor = COLOR_BODY;
    text.font = TYPOGRAPHY_BODY;
    }

    function renderDay(widget, { day }) {
    const text = widget.addText(day);
    const text = widget.addText("🗓" + day);
    text.centerAlignText();
    text.textColor = COLOR_TEXT;
    text.font = TYPOGRAPHY_TITLE;
    }

    function renderWeekday(widget, { weekday }) {
    const text = widget.addText(weekday);
    text.centerAlignText();
    text.textColor = COLOR_TEXT;
    text.font = TYPOGRAPHY_HEADER;
    }

    function render() {
    const date = new Date();

    const [year, month, day] = date.toLocaleDateString("fa-ir").split("/");
    const year = date.toLocaleDateString(LOCALE, { year: "numeric" });
    const month = date.toLocaleDateString(LOCALE, { month: "long" });
    const day = date.toLocaleDateString(LOCALE, { day: "numeric" });
    const weekday = date.toLocaleDateString(LOCALE, { weekday: "long" });

    const widget = new ListWidget();

    widget.setPadding(8, 8, 8, 8);
    widget.backgroundColor = COLOR_BACKGROUND;

    renderDay(widget, { day });

    renderWeekday(widget, { weekday });

    renderYearAndMonth(widget, { year, month });

    return widget;
    }

    Script.name("Global Calendar");
    Script.setWidget(render());
    Script.complete();
    Script.name("تقویم شمسی");
  6. behnammodi revised this gist Nov 11, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ios-widget-hijri-calendar.js
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ const getMonthName = (month) =>
    }[month]);

    function renderYearAndMonth(widget, { year, month }) {
    const text = widget.addText(`${getMonthName(month)} ${year}`);
    const text = widget.addText(`${getMonthName(month)} 🗓 ${year}`);
    text.centerAlignText();
    text.textColor = COLOR_BODY;
    text.font = TYPOGRAPHY_BODY;
  7. behnammodi revised this gist Nov 11, 2020. No changes.
  8. behnammodi revised this gist Nov 11, 2020. No changes.
  9. behnammodi renamed this gist Nov 11, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. behnammodi created this gist Nov 11, 2020.
    65 changes: 65 additions & 0 deletions ios-widget-hijri.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    const COLOR_BACKGROUND = Color.dynamic(
    new Color("ffffff", 1),
    new Color("222222", 1)
    );
    const COLOR_TEXT = Color.dynamic(
    new Color("222222", 1),
    new Color("ffffff", 1)
    );
    const COLOR_BODY = Color.dynamic(
    new Color("666666", 1),
    new Color("cccccc", 1)
    );
    const TYPOGRAPHY_TITLE = Font.boldSystemFont(60);
    const TYPOGRAPHY_BODY = Font.boldSystemFont(20);

    const getMonthName = (month) =>
    ({
    "۱": "فروردین",
    "۲": "اردیبهشت",
    "۳": "خرداد",
    "۴": "تیر",
    "۵": "مرداد",
    "۶": "شهریور",
    "۷": "مهر",
    "۸": "آبان",
    "۹": "آذر",
    "۱۰": "دی",
    "۱۱": "بهمن",
    "۱۲": "اسفند",
    }[month]);

    function renderYearAndMonth(widget, { year, month }) {
    const text = widget.addText(`${getMonthName(month)}${year}`);
    text.centerAlignText();
    text.textColor = COLOR_BODY;
    text.font = TYPOGRAPHY_BODY;
    }

    function renderDay(widget, { day }) {
    const text = widget.addText(day);
    text.centerAlignText();
    text.textColor = COLOR_TEXT;
    text.font = TYPOGRAPHY_TITLE;
    }

    function render() {
    const date = new Date();

    const [year, month, day] = date.toLocaleDateString("fa-ir").split("/");

    const widget = new ListWidget();

    widget.setPadding(8, 8, 8, 8);
    widget.backgroundColor = COLOR_BACKGROUND;

    renderDay(widget, { day });

    renderYearAndMonth(widget, { year, month });

    return widget;
    }

    Script.setWidget(render());
    Script.complete();
    Script.name("تقویم شمسی");