MomentSharp icon indicating copy to clipboard operation
MomentSharp copied to clipboard

Would be great per moments.js if one could provide a .Format string like "LTS" directly...

Open Simonl9l opened this issue 3 years ago • 5 comments

please see docs here

Simonl9l avatar Apr 22 '21 06:04 Simonl9l

there's this: https://github.com/Eonasdan/MomentSharp/blob/a2b632d8b78ce0886513068369b109a2f5b6fcf5/MomentSharp/Globalization/Languages/EnUs.cs#L15

Eonasdan avatar Apr 23 '21 15:04 Eonasdan

Yes found that in the code, but how does one selectively invoke it...docs are not clear.

Simonl9l avatar Apr 23 '21 16:04 Simonl9l

It's been 6 years since I wrote this and I'm surprised people are actually using it lol. I'm looking at the code again and I think the reason I didn't include a "format" function is because the native DateTime object already provides this. That said I think you could do this: m.DateTime().ToString(m.Language.LongDateFormat.Lts) where m = new Moment().

Let me know if that helps.

Eonasdan avatar Apr 24 '21 16:04 Eonasdan

CurrentlyI've taken a private fork and made it DotNet Standard. (that Framework 3.5). The JS original would just take format strings (like TLS) so if you have a use case where users profile the frame for their data the .Format("LTS") etc. method is useful.

The logic as basically good and reusable, and save reinventing, the JS original is widely popular, and is Numerals.js and Humaize.js. the latter DotNet port is great, and have also privately forked the Numerals port out there and added the "bytes" formatter.

Having at least at latest DotNet versions might encourage more users if that is what you want to do...

If I get the time at some point I can look to push my fork back as a pull request...

Simonl9l avatar Apr 24 '21 16:04 Simonl9l

Yeah if I had time, I'd rewrite it to use .net 5 and probably provide extensions to DateTime instead of creating a new object. I'm currently putting in a lot of overtime in my regular job and I'm working on a new version of my date picker. If there's interest, I could add a rewrite of this to my long term side project planning

Eonasdan avatar Apr 24 '21 17:04 Eonasdan