1-
21/*
32 * TypeScript implementation of Bikram calendar conversion
43 * Copyright (c) 2024 onwards - khumnath cg, [email protected] @@ -43,8 +42,9 @@ export class BikramDate {
4342 const { gYear, gMonth, gDay } = this . toGregorian ( year , month , day ) ;
4443 this . englishDate = new Date ( gYear , gMonth - 1 , gDay ) ;
4544 } else {
46- // Default to current date
47- this . englishDate = new Date ( ) ;
45+ const now = new Date ( ) ;
46+ now . setHours ( 0 , 0 , 0 , 0 ) ;
47+ this . englishDate = now ;
4848 const { bsYear, bsMonth, bsDay } = this . fromGregorian (
4949 this . englishDate . getFullYear ( ) ,
5050 this . englishDate . getMonth ( ) + 1 ,
@@ -58,16 +58,14 @@ export class BikramDate {
5858
5959 // Create a new BikramDate from a JavaScript Date
6060 static fromDate ( date : Date ) : BikramDate {
61- const bikramDate = new BikramDate ( ) ;
62- const { bsYear, bsMonth, bsDay } = bikramDate . fromGregorian (
63- date . getFullYear ( ) ,
64- date . getMonth ( ) + 1 ,
65- date . getDate ( )
61+ const d = new Date ( date ) ;
62+ d . setHours ( 0 , 0 , 0 , 0 ) ;
63+ const { bsYear, bsMonth, bsDay } = new BikramDate ( ) . fromGregorian (
64+ d . getFullYear ( ) ,
65+ d . getMonth ( ) + 1 ,
66+ d . getDate ( )
6667 ) ;
67- bikramDate . year = bsYear ;
68- bikramDate . month = bsMonth ;
69- bikramDate . day = bsDay ;
70- return bikramDate ;
68+ return new BikramDate ( bsYear , bsMonth , bsDay ) ;
7169 }
7270
7371 // Convert to JavaScript Date
@@ -109,8 +107,8 @@ export class BikramDate {
109107 // Convert AD (Gregorian) date to BS (Bikram Sambat)
110108 fromGregorian ( gYear : number , gMonth : number , gDay : number ) : { bsYear : number ; bsMonth : number ; bsDay : number } {
111109 // Reference date: 1 Baisakh 2000 BS = 14 April 1943 AD
112- const refDate = new Date ( 1943 , 3 , 14 ) ; // Month is 0-indexed in JS Date
113- const targetDate = new Date ( gYear , gMonth - 1 , gDay ) ;
110+ const refDate = new Date ( Date . UTC ( 1943 , 3 , 14 ) ) ; // Month is 0-indexed in JS Date
111+ const targetDate = new Date ( Date . UTC ( gYear , gMonth - 1 , gDay ) ) ;
114112
115113 // Calculate difference in days
116114 const timeDiff = targetDate . getTime ( ) - refDate . getTime ( ) ;
0 commit comments