BadiDateToday script

Purpose

To show the current date from the Badí' calendar.

  • Designed as a single file to be incorporated into any website.

  • The date shown is calculated in the browser, using the browser's current date and location.

  • Please note, this does not calculate or show Holy Days for the Baha'i Faith.

  • For more advanced scripts and tools, see https://sites.google.com/site/badicalendartools/

  • This is free to use on any website.

Sample

Here is a sample from Susan Gammage's (old) website, showing the date in two formats:

Sample showing display of Badí' date on website

Usage

Minimum Requirements

1. Identify an element where the Badí' date will be displayed

    1. <span class=BadiDate></span>

  • Add the class "BadiDate" to any element where the date should be displayed.

2. Include this script element in your web page

    1. <script type="text/javascript" src="https://wondrous-badi.today/scripts/BadiDateToday.v1.js"></script>

  • The JS script file can be used from this location.

  • Or, you may copy it to your own server, and use it from there. If you do, please email Glen Little at glen.little@gmail.com so that you can be informed if the script is updated.

    • JQuery is not required for the script to run but is required to do the automatic display with the "BadiDate" class.

Customizing the Badí' date display

The above steps will display today's date in the Badí' calendar using a default format and content.

This display can be customized in many ways.

Make a function to receive the date information

  • When the page loads, the script can be told to run a JavaScript function to show the date.

        1. <script>

        2. BadiDateToday({ onReady: showInfo });

        3. </script>

  • This script element must come after the one that loads the "js" file.

  • The "showInfo" function that you write will be given an object with details about today's date in the Badí' calendar.

  • A simple formatting method is included with the script, called "filledWith". Here is an example of how it can be used:

        1. function showInfo(dayInfo){

        2. console.log('{bDay} {bMonthMeaning} ({bMonthNameAr}) {bYear}'.filledWith(dayInfo));

        3. }

  • This would result in something like "7 Words (Kalimát) 172" being shown in the browser's console.

  • In this function, you can do anything with the date information. If you use jQuery, you could display date information in various locations on your page, like these examples:

        1. function showInfo(di){

        2. $('#badiDayMonth').text(di.bDay + ' ' + di.bMonthMeaning);

        3. $('#badiYear').text(di.bYear);

        4. $('.DayInfo').html('{bYear}-{bMonth}-{bDay} {nearestSunset}'.filledWith(di));

        5. }

Optional Settings

        1. var myVariable = BadiDateToday({

        2. language: 'fr',

        3. onReady: showInfo

        4. });

The Settings object passed to BadiDateToday can include:

onReady - a function that is called when the date is determined. One parameter is passed.

language - 'en' or one of the languages defined in _messages (see Translation below)

locationIdentification - one of these options

1 == don't try to customize sunset times, just use 6:30pm

2 == (default) guess the user's location based on how they are connected to the Internet

3 == prompt the user to allow your site to know their location. (This is only supported in Chrome on sites that use https://)

use24HourClock - true or false - used when displaying sunset time

currentTime - used to get the date for a different time or day - if not supplied, the computer's current time is used

If BadiDateToday() is assigned to a variable (above it is to "myVariable"), that variable provides two methods:

getDateInfo() - get the information for today.

refresh() - refresh the BadiDateToday object. The original Settings will be used unless a new one is supplied now. The onReady function is invoked again.

        1. var dayInfo = myVariable.getDateInfo();

        2. myVariable.refresh();

        3. myVariable.refresh({ currentTime: new Date('Jan 1, 1985') });

Help

To see all available tags that can be used in your "onReady" code, temporarily add this to your script:

        1. function showInfo(dayInfo){

        2. console.log(dayInfo);

        3. }

Or, use the getDateInfo() function:

        1. console.log(myVariable.getDateInfo())

Tags

List of "tags" that can be accessed for the current time/date (this sample captured on the day shown):

bDay: 8

bDay00: "08"

bDayMeaning: "Perfection"

bDayNameAr: "Kamál"

bDayOrdinal: "8th"

bDayOrdinalName: "eighth"

bEraAbbrev: "B.E."

bEraLong: "Bahá'í Era"

bEraShort: "BE"

bKullishay: 1

bKullishayOrdinal: "1st"

bKullishayOrdinalName: "first"

bMonth: 7

bMonth00: "07"

bMonthDayYear: "Kalimát 8, 172"

bMonthMeaning: "Words"

bMonthNameAr: "Kalimát"

bNow: Object

bVahid: 10

bVahid00: "10"

bVahidOrdinal: "10th"

bVahidOrdinalName: "tenth"

bWeekday: 3

bWeekdayMeaning: "Perfection"

bWeekdayNameAr: "Kamál"

bYear: 172

bYearInVahid: 1

bYearInVahid00: "01"

bYearInVahidMeaning: "A"

bYearInVahidNameAr: "Alif"

currentDay: 20

currentDay00: "20"

currentMonth: 6

currentMonth01: "07"

currentMonth1: 7

currentMonthLong: "July"

currentMonthShort: "Jul"

currentRelationToSunset: "day - before sunset"

currentTime: Mon Jul 20 2015 09:39:41 GMT-0600 (Mountain Daylight Time)

currentWeekday: 1

currentWeekdayLong: "Monday"

currentWeekdayShort: "Mon"

currentYear: 2015

dayEnded: "Ends"

dayEndedLower: "ends"

dayStarted: "Started"

dayStartedLower: "started"

endingSunsetDesc: "9:41 pm"

endingSunsetDesc12: "9:41 pm"

endingSunsetDesc24: "21:41"

frag1: Sun Jul 19 2015 12:00:00 GMT-0600 (Mountain Daylight Time)

frag1Day: 19

frag1Day00: "19"

frag1Month: 6

frag1MonthLong: "July"

frag1MonthShort: "Jul"

frag1SunTimes: Object

frag1Weekday: 0

frag1WeekdayLong: "Sunday"

frag1WeekdayShort: "Sun"

frag1Year: 2015

frag2: Mon Jul 20 2015 12:00:00 GMT-0600 (Mountain Daylight Time)

frag2Day: 20

frag2Day00: "20"

frag2Month: 6

frag2MonthLong: "July"

frag2MonthShort: "Jul"

frag2SunTimes: Object

frag2Weekday: 1

frag2WeekdayLong: "Monday"

frag2WeekdayShort: "Mon"

frag2Year: 2015

gCombined: "Jul 19/20"

gCombinedY: "Jul 19/20, 2015"

nearestSunset: "Ends with sunset at 9:41 pm"

startingSunsetDesc: "9:42 pm"

startingSunsetDesc12: "9:42 pm"

startingSunsetDesc24: "21:42"


Tips on tag names:

"____Ar" means the Arabic name

"____Meaning" is the English or other local language translation/meaning of the name

"g_____" means the Gregorian calendar

"current______" is this moment in the Gregorian calendar

"frag1____" is that part of the Badí' day before midnight, and "frag2" is the part of the day after midnight

Translation

Languages currently embedded:

  • 'en' (English)

  • 'fr' (French)

  • 'pt_PT' (Portuguese)

To translate to another language, copy the script file to your own computer, duplicate the "fr" section of _messages, and supply your language's words. If any particular message is not translated, English will be used. Also set the Setting's "language" to the language code you have defined.

If you would like to share your translation with others, please contact Glen Little!

Script File

The script file can be directly referenced from your website at:

This is the currently supported "official" location for the script.

You can also download a copy of the script and put it on your own server.

To contribute to the code, please see this github repository: https://github.com/glittle/BadiDateToday