Comments (6)
Yeah, that's what I had done originally, but in order to use _.mixin, you can only have a single level of hierarchy of the functions you pass in.
I did notice that I had to prefix and suffix a lot of the functions, so it may make more sense to create a _.date() object that I prototype the other functions onto.
So, _.formatDate() would become _.date().format() and _.fromNow() would become _.date().fromNow().
I'll make a branch and try it out.
from moment.
Alright, here's a stab at cleaning up the _
namespace.
https://github.com/timrwood/underscore.date/blob/namespace/lib/underscore.date.js
So now, there would only be _.date()
, _.now()
, and _.isLeapYear(yearnumber)
. Everything else would be called on a _.date()
variable like
_.date([2010, 0, 31]).add({M:1}).format("MMMM Do YYYY");
or
_([2010, 0, 31]).date().add({M:1}).format("MMMM Do YYYY");
instead of
_([2010, 0, 31]).chain().date().addTime({M:1}).formatDate("MMMM Do YYYY").value()
Also, I was able to strip out all the suffixes, so the _.date()
prototype functions are now format(string)
, add(object)
, subtract(object)
, customize(object)
, from(dateInput, boolean)
, fromNow(boolean)
, isLeapYear()
, and relative(number)
.
from moment.
Neat! In addition, what if upgrade _.isLeapYear(yearnumber)
to take Date
also? This would 1) improve usability (no need to snoop explicitly for getYear) and 2) allow to move it under _.date()
;)
from moment.
There are 2 instances of isLeapYear
.
_.isLeapYear(number)
and _.date().isLeapYear()
.
_.isLeapYear(number)
takes a year number (eg. 2010) and returns true if that year is a leap year.
_.date().isLeapYear()
basically maps to _.isLeapYear(this.date.getFullYear())
, using the date's year.
I figured it might be useful to check if a year is a leap year without creating a date object.
from moment.
Pushed to master. Closing.
from moment.
Thanks! Soon will be heavily exploiting this lib ;)
from moment.
Related Issues (20)
- Add ability to specify year before parsing, or auto-guess the year HOT 3
- DST functionality in iran HOT 1
- Problem with tz methods and daylight change in America HOT 1
- [Nuxt3] moment.locale not set new locale HOT 5
- Timezones like US/Pacific, America/Los_Angeles are not switching between PST and PDT HOT 15
- Issues when parsing ISO week format (WW) - always uses current year
- Stange behaviour of datetime parsed from string HOT 2
- Moment js is not working in daylight savings and its showing the timezone as GMT instead of BST in UK HOT 1
- Inconsistent behavior when formatting 'eHHmm'
- I get different results running on Mac than running the same in Github HOT 1
- Error when simple formatting HOT 1
- formatting time in HH:mm shorts 1 hour HOT 4
- Is this project following sem versioning ?
- French (Canada) date format includes an 'e' after the number HOT 2
- Egypt has changed their daylight savings rules again, on short notice HOT 1
- 2 tests failed. diff:diff across DST (3329.17) diff:diff across DST (3329.19)
- monthsShort and format() is returning different values for month names HOT 4
- Is Diff calculation wrong every other month?
- subtract get last week is wrong HOT 3
- America/Mexico_City / DST HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moment.