Skip to content

Cannot parse Hungarian date format + fix #96

Description

@hawajrambo

import ssfPkg from 'ssf';
const { format } = ssfPkg;
let s= format("yyyy.mm.dd. hh:mm:ss", 45779.201898148145);

Throws an error, because it treats the "." date separator as decimal seperator

Here is a quickfix:

function eval_fmt(fmt, v, opts, flen) {
	var out = [], o = "", i = 0, c = "", lst='t', dt, j, cc;
	var hr='H';
  var dateDetected= false;      <<<<<<<<<<<<<<<<<<<<<
	/* Tokenize */
	while(i < fmt.length) {
		c = fmt.charAt(i);      <<<<<<<<<<<<<<<<<<<<<
		var cFixed= c;      <<<<<<<<<<<<<<<<<<<<<
		if ( ( c === "." ) && dateDetected ) cFixed="-"; // change date seaparator to -, to not treat as decimal separator      <<<<<<<<<<<<<<<<<<<<<
		switch((cFixed)) {      <<<<<<<<<<<<<<<<<<<<<
			case 'G': /* General */
				if(!isgeneral(fmt, i)) throw new Error('unrecognized character ' + c + ' in ' +fmt);
			case 'm': case 'd': case 'y': case 'h': case 's': case 'e': case 'g':
				dateDetected= true; // from now on treat . as date delimiter insted of decimal separator      <<<<<<<<<<<<<<<<<<<<<
				if(v < 0) return "";

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions