Giter Site home page Giter Site logo

Comments (17)

mattjohnsonpint avatar mattjohnsonpint commented on August 20, 2024 3

Because then it would be possible to write something like:

let t = new CivilTime({ minute:30 });  // which hour?
let d = new CivilDate({ day: 31 });    // which year? which month?

The only way to deal with this would be to assume some default values - which IMHO wouldn't be obvious or intuitive.

from proposal-temporal.

domenic avatar domenic commented on August 20, 2024 3

I think normal arguments make more sense when the arguments are not optional.

from proposal-temporal.

littledan avatar littledan commented on August 20, 2024 1

@mj1856 Well, what about throwing an exception for cases like that?

from proposal-temporal.

maggiepint avatar maggiepint commented on August 20, 2024 1

I tend to agree that options doesn't make sense when fields are required.

from proposal-temporal.

gibson042 avatar gibson042 commented on August 20, 2024 1

I like that the constructors define scalar parameters of decreasing resolution, but we could consider (re)introducing static fromObject methods that define a single parameter and read fields from the corresponding argument, giving equal treatment to Temporal type instances and plain objects.

from proposal-temporal.

mattjohnsonpint avatar mattjohnsonpint commented on August 20, 2024

As to the options bag for the math functions, #23 has the discussion where we agreed on that approach. Thanks.

from proposal-temporal.

mattjohnsonpint avatar mattjohnsonpint commented on August 20, 2024

I suppose that would be possible, though I'm not sure it is necessary. There is case to be made for user familiarity with the Date object constructor. Ours would be similar, except for the months field switching from being 0-based to 1-based. Would that be reason enough to switch?

Each approach has its pros and cons. I'm curious what others think. Do you prefer:

var dt = new CivilDateTime(2017, 12, 31, 23, 59, 59, 999, 999999);

or

var dt = new CivilDateTime({
    year: 2017,
    month: 12,
    day: 31,
    hour: 23,
    minute: 59,
    second: 59,
    millisecond: 999,
    nanosecond: 999999
});

from proposal-temporal.

littledan avatar littledan commented on August 20, 2024

(I raised the issue out of an aesthetic preference for the second one, though I'm happy to defer to others here)

from proposal-temporal.

jamiewinder avatar jamiewinder commented on August 20, 2024

I certainly prefer the normal arguments rather than an options bag. The example above shows how verbose this can be. You'll also always be omitting from one units and lesser if you see what I mean; there is never a situation where someone would want to specify hours and seconds but not minutes, and if you did I'd say it's bad practice to do so.

from proposal-temporal.

ljharb avatar ljharb commented on August 20, 2024

+1 - options objects are great for non-required args, but for required args, there's not really much of a benefit in using options objects imo.

from proposal-temporal.

icambron avatar icambron commented on August 20, 2024

I tend to agree with positional here, but a small counterpoint is that it's a bit worse for programmatic use. If you're like me, you end up doing stuff like this a lot:

// This is the most naturally way to keep this data around
// or of pulling off a wire
var someTimeData = {
    year: 2017,
    month: 12,
    day: 31,
    hour: 23,
    minute: 59,
    second: 59,
    millisecond: 999,
    nanosecond: 999999
};

// grr, ok, at least I have ES6, imagine this without it
{year, month, day, hour, minute, second, millisecond, nanosecond} = someTimeData;

// now I can do the thing
new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond);

// So it more naturally takes an array, which seems definitely worse
someTimeData = [
   2017,
    12,
    31,
    23,
    59,
    59,
    999,
    999999
];

// And then you figure out how to apply() but with a constructor, 
// which is something weird like
new (Function.prototype.bind.apply(CivilDateTime, someTimeData));

Anyway, I don't think that trumps how positional parameters naturally enforce requiredness, but it's a thought.

from proposal-temporal.

Yogu avatar Yogu commented on August 20, 2024

@icambron Would you really store/transfer instants as an object like this? I'd use an ISO-8601 serialization.

from proposal-temporal.

hollowdoor avatar hollowdoor commented on August 20, 2024

A static .from() operator might be a good compromise.

const likeADate = {
    year: 2017,
    month: 12,
    day: 31,
    hour: 23,
    minute: 59,
    second: 59,
    millisecond: 999,
    nanosecond: 999999
};

const dt = CivilDateTime.from(likeADate);

Something to think about in the future. Similar to Promise.resolve(), or Array.from().

Would you really store/transfer instants as an object like this?

I wouldn't personally, but there could be situations where an object might have some parts of a time.

class Something {
    constructor(){
         this.year = 2017;
         this.month = 11;
    }
    get dateTime(){
        return CivilDateTime.from(this);
        //return new CivilDateTime(this);
    }
}

from proposal-temporal.

littledan avatar littledan commented on August 20, 2024

Seems like we've settled on positional arguments. Do we want to add this fromObject method (which sounds like a good idea to me) or not?

from proposal-temporal.

obedm503 avatar obedm503 commented on August 20, 2024

fromObject seem redundant. just from would be better.

from proposal-temporal.

felixfbecker avatar felixfbecker commented on August 20, 2024

Imo any function taking more than a certain amount of parameters of the same type becomes hard to read and error-prone if it takes those as positional parameters instead of an options bag. Especially in the case of Duration, it makes it unneccessarily hard to create durations of milliseconds, seconds, minutes, hours, days etc because you always need to specify everything starting with years, and what semantic the last passed parameter has is hard to infer when reading the code:

new Temporal.Duration(0,0,0,0,10) // how long is this?
// vs
new Temporal.Duration({ minutes: 10 })

And this is only minutes, now imagine this when working with mili- or nanoseconds. See also @mj1856's example.

Imo this is something that is bad about the current Date API (old and Java-like, not JS-idiomatic). The new Intl, DateTimeFormat and Temporal methods APIs are all way more ergonomic to use and read. Please consider using options objects for the constructors too.

from proposal-temporal.

pipobscure avatar pipobscure commented on August 20, 2024

This is obsolete. Conclusion:

  • constructors has positional arguments only
  • static .from methods take property bags to create objects

from proposal-temporal.

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.