Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set time by default #4

Open
andreyRybchuk opened this issue Jun 19, 2019 · 4 comments
Open

Set time by default #4

andreyRybchuk opened this issue Jun 19, 2019 · 4 comments

Comments

@andreyRybchuk
Copy link

Is it possible to set time by default, not 0? For example 2h23m.

@andreyRybchuk andreyRybchuk changed the title Set values by default Set time by default Jun 19, 2019
@AmmoTrio
Copy link

Any updates on this matter?
This is a great and easy to use component.
But, this issue is the only thing preventing me from using this component.

@stnor
Copy link

stnor commented Jul 6, 2020

Nice job with this library. It's unfortunately unusable for many/most applications if you cannot use this component with an initial value. Edit mode exists in forms you know... CRUD. You support only C (and D).

setValue methods on the parent and the children please.

@stnor
Copy link

stnor commented Jul 6, 2020

I copied the project and adopted it to my needs . Thanks.
I use moment.js, so adding that dep is not an issue for me.

  @Input('value')
  set _value(val: number) {
    this.setValue(val);
  }

  public setValue(value: number): void {
    setTimeout(() => {
      // @ts-ignore
      let duration = moment.duration(value, this.unit + 's');
      this.units.toArray().forEach(element => {
        switch (element.name.toLocaleLowerCase()) {
          case "year":
            element.setValue(duration.years())
            break;
          case "month":
            element.setValue(duration.months())
            break;
          case "week":
            element.setValue(duration.weeks())
            break;
          case "day":
            element.setValue(duration.days())
            break;
          case "hour":
            element.setValue(duration.hours())
            break;
          case "minute":
            element.setValue(duration.minutes())
            break;
          case "second":
            element.setValue(duration.seconds())
            break;
          case "millisecond":
            element.setValue(duration.milliseconds())
            break;
        }
      });
    })

@MHzarini
Copy link
Owner

MHzarini commented Jul 6, 2020

@stnor if using moment is solving this issue. please open a PR and i will add that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants