Skip to content

Zero dependency Myanmar Calendar library for TypeScript. Convert Gregorian dates to Myanmar calendar with Thingyan, Watat years, and Buddhist Era.

License

Notifications You must be signed in to change notification settings

AungMyoKyaw/mycal

Repository files navigation

MYCAL

Myanmar Calendar - Zero dependency TypeScript library

code style: prettier npm contributions welcome License: MIT TypeScript

Algorithm

Algorithm, Program and Calculation of Myanmar Calendar

v2.2 - What's New?

MyCal v2.2 adds complete astrology support:

  • Maharbote - Birth sign calculation based on weekday
  • Numerology - Digital root calculation for any number
  • Chinese Zodiac - Chinese zodiac with Burmese translations
  • Western Zodiac - Zodiac sign from day/month
  • Number Formatting - Convert numbers to Burmese words
  • Validation Tools - Calendar consistency validation framework

v2.0 - Major Rewrite

MyCal v2.0 was a complete rewrite with:

  • Zero Dependencies - No external packages required
  • TypeScript - Full type safety and better IDE support
  • Bun Runtime - Faster performance and modern tooling
  • Smaller Bundle - No dependency bloat
  • 100% Backward Compatible - Same API as v1.x

Installation

npm

npm install --save mycal

bun

bun add mycal

yarn

yarn add mycal

web (Browser)

<script type="module">
  import { Mycal } from 'https://unpkg.com/mycal@latest/dist/browser/index.js';
  // or use the IIFE build
  // <script src="https://unpkg.com/mycal@latest/dist/browser/index.js"></script>
</script>

Usage

JavaScript (CommonJS)

const { Mycal } = require('mycal');

// Myanmar Independence Day
const myanmarDate = new Mycal('1/4/1948');

console.log(myanmarDate.year); // { en: '1309', my: '၁၃၀၉' }
console.log(myanmarDate.month); // { en: 'Pyatho', my: 'ပြာသို' }
console.log(myanmarDate.day); // { fd: { en: '9', my: '၉' }, mp: { en: 'Waning', my: 'လပြည့်ကျော်' } }
console.log(myanmarDate.weekday); // { en: 'Sunday', my: 'တနင်္ဂနွေ' }
console.log(myanmarDate.buddhistEraYear); // { en: '2491', my: '၂၄၉၁' }

TypeScript (ESM)

import { Mycal, type LocalizedString } from 'mycal';

// Type-safe usage
const myanmarDate: Mycal = new Mycal('2000-01-01');

const year: LocalizedString = myanmarDate.year;
console.log(year); // { en: '1361', my: '၁၃၆၁' }

// For today's date (no parameters)
const today = new Mycal();
console.log(today.month);

Browser

<!DOCTYPE html>
<html>
  <head>
    <script type="module">
      import { Mycal } from 'https://unpkg.com/mycal@latest/dist/browser/index.js';

      const date = new Mycal('2000-01-01');
      document.body.textContent = `${date.month.en} ${date.year.en}`;
    </script>
  </head>
  <body></body>
</html>

API Reference

new Mycal(dateString?, options?)

Creates a new Mycal instance.

Parameters:

  • dateString (optional): Date string in formats like '2000-01-01', '1/1/2000', or undefined for current date
  • options (optional): Configuration options (reserved for future use)

Returns: Mycal instance

Properties

All properties are read-only and computed lazily.

year

Returns the Myanmar year (English and Myanmar numerals).

const cal = new Mycal('2000-01-01');
console.log(cal.year);
// { en: '1361', my: '၁၃၆၁' }

month

Returns the Myanmar month name.

const cal = new Mycal('2012-07-01'); // First Waso
console.log(cal.month);
// { en: 'First Waso', my: 'ပဝါဆို' }

day

Returns the fortnight day and moon phase.

const cal = new Mycal('2012-05-23');
console.log(cal.day);
// {
//   fd: { en: '4', my: '၄' },    // Fortnight day
//   mp: { en: 'Waxing', my: 'လဆန်း' }  // Moon phase
// }

Moon phases:

  • Waxing (လဆန်း) - Growing moon
  • Full Moon (လပြည့်) - Full moon
  • Waning (လပြည့်ကျော်) - Shrinking moon
  • New Moon (လကွယ်) - New moon

weekday

Returns the Myanmar weekday.

const cal = new Mycal('1948-01-04'); // Myanmar Independence Day
console.log(cal.weekday);
// { en: 'Sunday', my: 'တနင်္ဂနွေ' }

buddhistEraYear

Returns the Buddhist Era year.

const cal = new Mycal('2000-01-01');
console.log(cal.buddhistEraYear);
// { en: '2543', my: '၂၅၄၃' }

thingyan

Returns Thingyan (Water Festival) information for the Myanmar year.

const cal = new Mycal('2000-01-01');
console.log(cal.thingyan);
// {
//   akyo: '4/13/1999',              // Akyo day
//   akya: '4/14/1999',              // Akya day
//   akyat: ['4/15/1999'],           // Akyat days
//   atat: '4/16/1999',              // Atat day
//   new_year_day: '4/17/1999',      // New Year day
//   akyaTime: '1999-04-14T...',     // Akya exact time (ISO 8601)
//   atatTime: '1999-04-16T...'      // Atat exact time (ISO 8601)
// }

watatYear

Returns information about intercalary (leap) months/days.

const cal = new Mycal('2013-01-01');
console.log(cal.watatYear);
// {
//   watat: true,       // Has extra month (35-day month)
//   isBigWatat: false  // Has extra day (30-day intercalary month)
// }

waso

Returns the full moon day of Waso.

const cal = new Mycal('2013-01-01');
console.log(cal.waso);
// '8/2/2012'

firstDayOfTagu

Returns the first day of Tagu (Myanmar New Year).

const cal = new Mycal('2013-01-01');
console.log(cal.firstDayOfTagu);
// '3/23/2012'

maharbote

Returns the birth sign (Maharbote) based on the day of the week.

const cal = new Mycal('2000-01-01');
console.log(cal.maharbote);
// 'အထွန်း' (Binga)

Birth signs:

  • ဘင်္ဂ (Binga) - Saturday
  • မရဏ (Marana) - Sunday
  • အထွန်း (Ahtone) - Monday
  • သိုက် (Thike) - Tuesday
  • ရာဇာ (Yaza) - Wednesday
  • ပုတိ (Puti) - Thursday
  • အဓိပတိ (Adipati) - Friday

numerology

Returns the numerology number (digital root) of the day of the month (1-9).

const cal = new Mycal('2000-01-15');
console.log(cal.numerology);
// 6

chineseZodiac

Returns the Chinese zodiac sign with Burmese translation.

const cal = new Mycal('2000-01-01');
console.log(cal.chineseZodiac);
// { en: 'Dragon', my: 'မြွေ' }

Static Methods

Mycal.zodiac(day, month)

Returns the Western zodiac sign for a given day and month.

const zodiac = Mycal.zodiac(15, 1); // January 15
console.log(zodiac);
// { en: 'Capricorn', my: 'ဆင်သည်' }

Instance Methods

numFormat(num)

Formats a number to Burmese words.

const cal = new Mycal('2000-01-01');
console.log(cal.numFormat(1234));
// 'တစ်ထောင်နှစ်ရာသုံးဆယ့်လေး'

Standalone Functions

You can also import functions directly without creating a Mycal instance:

BayDin (Astrology) Functions

import {
  maharbote,
  numerology,
  numFormat,
  chineseZodiac,
  zodiac,
  toBurmeseNumerals,
  fromBurmeseNumerals,
} from 'mycal';

// Birth sign from weekday (0=Saturday, 6=Friday)
const sign = maharbote(0); // Saturday -> 'ဘင်္ဂ'

// Numerology from day of month
const num = numerology(15); // 6

// Format number to Burmese words
const words = numFormat(1234); // 'တစ်ထောင်နှစ်ရာသုံးဆယ့်လေး'

// Chinese zodiac from year
const cz = chineseZodiac(2000); // { en: 'Dragon', my: 'မြွေ' }

// Western zodiac from day and month
const wz = zodiac(15, 1); // { en: 'Capricorn', my: 'ဆင်သည်' }

// Number to Burmese numerals
const burmeseNum = toBurmeseNumerals(1234); // '၁၂၃၄'

// Burmese numerals to number
const normalNum = fromBurmeseNumerals('၁၂၃၄'); // 1234

Validation Functions

import {
  validateMyanmarYear,
  validateWatatYear,
  validateFullMoonDay,
  validateThingyan,
  validateCalendarConsistency,
  isValidYear,
  getValidationSummary,
} from 'mycal';

// Validate a Myanmar year
const result = validateMyanmarYear(1361);
console.log(result.valid); // true/false
console.log(result.issues); // Array of issues if any

// Get validation summary for a range
const summary = getValidationSummary(1300, 1400);

TypeScript Types

All types are exported for TypeScript users:

import type {
  LocalizedString, // { en: string, my: string }
  ThingyanResult, // Thingyan information
  WatatYearResult, // Watat year information
  MyanmarDayResult, // Day and moon phase
  MoonPhase, // 'waxing' | 'full' | 'waning' | 'new'
  MonthType, // 'hma' | 'hgu'
  MyanmarMonth, // 0 | 1 | 2 | ... | 12
  ChineseZodiacResult, // { en: string, my: string }
  ZodiacResult, // { en: string, my: string }
  ValidationResult, // { valid: boolean, issues: ValidationIssue[] }
  ValidationIssue, // { type: string, message: string, ... }
} from 'mycal';

Migration from v1.x to v2.x

Good news! The API is 100% backward compatible. All your existing code will continue to work:

Before (v1.x)

const mycal = require('mycal');
const date = new mycal('2000-01-01');
console.log(date.year); // { en: '1361', my: '၁၃၆၁' }

After (v2.x) - Same API!

const { Mycal } = require('mycal');
const date = new Mycal('2000-01-01');
console.log(date.year); // { en: '1361', my: '၁၃၆၁' }

Plus new features in v2.2:

import { Mycal } from 'mycal';
const date = new Mycal('2000-01-01');

// New astrology features
console.log(date.maharbote); // Birth sign
console.log(date.numerology); // Numerology number
console.log(date.chineseZodiac); // Chinese zodiac
console.log(Mycal.zodiac(15, 1)); // Western zodiac

Development

Setup

# Clone the repo
git clone https://github.com/AungMyoKyaw/mycal.git
cd mycal

# Install dependencies (with Bun)
bun install

# Or with npm
npm install

Commands

# Run tests
bun test
# or
npm test

# Type checking
bun run typecheck
# or
npm run typecheck

# Build
bun run build
# or
npm run build

# Development mode (with watch)
bun run dev

# Linting
bun run lint
bun run lint:fix

# Formatting
bun run format
bun run format:check

# Full validation
bun run validate  # Type check + lint + format check
bun run ci        # Full CI pipeline

Build Outputs

The build process creates three outputs:

  1. Node.js: dist/node/index.js - CommonJS build for Node.js
  2. Browser: dist/browser/index.js - ESM build for browsers
  3. Types: dist/types/ - TypeScript declaration files

Test

npm test
# or
bun test

Build

npm run build
# or
bun run build

License

MIT © Aung Myo Kyaw

Algorithm

Based on Algorithm, Program and Calculation of Myanmar Calendar by Coolemerald.


About

Zero dependency Myanmar Calendar library for TypeScript. Convert Gregorian dates to Myanmar calendar with Thingyan, Watat years, and Buddhist Era.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •