mycal
v2.2.0
Published
Myanmar Calendar - Zero dependency TypeScript rewrite with Bun
Downloads
192
Maintainers
Readme
MYCAL
Myanmar Calendar - Zero dependency TypeScript library
Algorithm
Algorithm, Program and Calculation of Myanmar Calendar
v2.0 - What's New?
MyCal v2.0 is 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 mycalbun
bun add mycalyarn
yarn add mycalweb (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 dateoptions(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 moonFull Moon(လပြည့်) - Full moonWaning(လပြည့်ကျော်) - Shrinking moonNew 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'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
} from 'mycal';Migration from v1.x to v2.0
Good news! The API is 100% backward compatible. The only changes are internal:
Before (v1.x)
const mycal = require('mycal');
const date = new mycal('2000-01-01');
console.log(date.year); // { en: '1361', my: '၁၃၆၁' }After (v2.0) - Same API!
const { Mycal } = require('mycal');
const date = new Mycal('2000-01-01');
console.log(date.year); // { en: '1361', my: '၁၃၆၁' }Or use TypeScript:
import { Mycal } from 'mycal';
const date = new Mycal('2000-01-01');
console.log(date.year); // { en: '1361', my: '၁၃၆၁' }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 installCommands
# 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 devBuild Outputs
The build process creates three outputs:
- Node.js:
dist/node/index.js- CommonJS build for Node.js - Browser:
dist/browser/index.js- ESM build for browsers - Types:
dist/types/- TypeScript declaration files
Test
npm test
# or
bun testBuild
npm run build
# or
bun run buildLicense
MIT © Aung Myo Kyaw
Algorithm
Based on Algorithm, Program and Calculation of Myanmar Calendar by Coolemerald.
