Coder Social home page Coder Social logo

Comments (2)

Chriscbr avatar Chriscbr commented on July 3, 2024

A minimal example showing the current discrepancy will be helpful here (I'm unable to view the code linked in the issue)

from wing.

asterkin avatar asterkin commented on July 3, 2024

@Chriscbr added you to the endor.w GitHub Repo.
Here is the code:
//Cannot be imported from TS
pub enum DatetimeFormat {
ISO,
MMYYYY,
YYYYMMDD_HHMM
}

pub class Util {
extern "./lib.js" static pub inflight toUtcString(date: std.Datetime): str;
extern "./lib.js" static pub inflight plus(date: std.Datetime, offset: duration): std.Datetime;
extern "./lib.js" static pub inflight minus(date: std.Datetime, offset: duration): std.Datetime;
extern "./lib.js" static pub inflight format(date: std.Datetime, format: DatetimeFormat): str;
extern "./lib.js" static pub inflight parse(date: str, format: DatetimeFormat): std.Datetime;
extern "./lib.js" static pub inflight formatMMYYYY(date: std.Datetime): str;
extern "./lib.js" static pub inflight parseMMYYYY(sd: str): std.Datetime;
extern "./lib.js" static pub inflight formatYYYYMMDD_HHMM(date: std.Datetime): str;
extern "./lib.js" static pub inflight parseYYYYMMDD_HHMM(sd: str): std.Datetime;

static pub inflight gt(left: std.Datetime, right: std.Datetime): bool {
    return left.timestampMs > right.timestampMs;
}
static pub inflight gte(left: std.Datetime, right: std.Datetime): bool {
    return left.timestampMs >= right.timestampMs;
}
static pub inflight lt(left: std.Datetime, right: std.Datetime): bool {
    return left.timestampMs < right.timestampMs;
}
static pub inflight lte(left: std.Datetime, right: std.Datetime): bool {
    return left.timestampMs <= right.timestampMs;
}

}
In TypeScript, I need to do this:
//Wing passes enums as strings, hence need extra validation
export function getParser(format: DatetimeFormat | string): ParseDatetime {
const parser = _parser.get(
typeof format == 'string' ?
DatetimeFormat[format as keyof typeof DatetimeFormat]
: format
);

if (!parser) {
    throw new Error(`Parser for format ${format} not found`);
}
return parser;

}

export function parse(dateTime: string, format: DatetimeFormat): std.Datetime {
return getParser(format)(dateTime);
}

export function getFormatter(format: DatetimeFormat | string): FormatDatetime {
const formatter = _formatter.get(
typeof format == 'string' ?
DatetimeFormat[format as keyof typeof DatetimeFormat]
: format
);
if (!formatter) {
throw new Error(Formatter for format ${format} not found);
}
return formatter;
}

export function format(dateTime: std.Datetime, format: DatetimeFormat): string {
return getFormatter(format)(dateTime);
}

from wing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.