Project

General

Profile

Remove Dependency on ad-bs-converter Library.

Technical documentation
05/20/2024

  • Add following code-block in the end of nepali.datepicker.3.5.min.js
function bs2ad(date, format) {
    if(!format)
        format = "YYYY-MM-DD";
    var d = NepaliFunctions.ConvertToDateObject(date, format);
    return NepaliFunctions.BS2AD(d);
} 
function ad2bs(date, format) {
    if(!format)
        format = "YYYY-MM-DD";
    var d = NepaliFunctions.ConvertToDateObject(date, format);
    return NepaliFunctions.AD2BS(d);
} 

exports.bs2ad = bs2ad; 
exports.ad2bs = ad2bs;

Add following methods in a service that is widely used across application. Eg. MasterService

public toBSDate(adDate:string):string{
    var nepFunction = require('../../../assets/nepali-date-picker/nepali.datepicker.v3.5.min.js')
    var bsDate = nepFunction.ad2bs(adDate, "MM/DD/YYYY"); //Use appropriate date format in CAPS
    return bsDate.year + '-' + bsDate.month.toString().padStart(2,'0') + '-' + bsDate.day.toString().padStart(2,'0');
}

public toADDate(bsDate):string{
    var nepFunction = require('../../../assets/nepali-date-picker/nepali.datepicker.v3.5.min.js')
    var adDate = nepFunction.bs2ad(bsDate, "DD/MM/YYYY");
    return adDate.year + '-' + adDate.month.toString().padStart(2,'0') + '-' + adDate.day.toString().padStart(2,'0');
}

Make following changes where ad-bs-converter library is being used

changeOnDate(value, format: string) {

    //var adbs = require("ad-bs-converter");

    if (format == "AD") {
        //var adDate = (value.replace("-", "/")).replace("-", "/");
        //var bsDate = adbs.ad2bs(adDate);
        //this.ScheduleDateBS = bsDate.en.year + '-' + bsDate.en.month + '-' + (bsDate.en.day == '1' || bsDate.en.day == '2' || bsDate.en.day == '3' || bsDate.en.day == '4' || bsDate.en.day == '5' || bsDate.en.day == '6' || bsDate.en.day == '7' || bsDate.en.day == '8' || bsDate.en.day == '9' ? '0' + bsDate.en.day : bsDate.en.day);

        this.ScheduleDateBS = this.masterRepo.toBSDate(value);
    }
    else {
        //var bsDate = (value.replace("-", "/")).replace("-", "/");
        //var adDate = adbs.bs2ad(bsDate);
        //this.ScheduleDateAD = (adDate.year + '-' + ((adDate.month).toString().length == 1 ? '0' + adDate.month : adDate.month) + '-' + ((adDate.day).toString().length == 1 ? '0' + adDate.day : adDate.day));

        this.ScheduleDateAD = this.masterRepo.toADDate(value);
    }
}

Files