-
Notifications
You must be signed in to change notification settings - Fork 176
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
Supporting Duration for Datetime attributes #650
base: main
Are you sure you want to change the base?
Changes from all commits
6f0962b
6faaa2f
297249c
cf2c191
07fb78b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,8 +488,14 @@ _.register({ | |
"time": /^[H\d]{2}:[M\d]{2}/i, | ||
"datetime-local": /^[Y\d]{4}-[M\d]{2}-[D\d]{2} [H\d]{2}:[Mi\d]{2}/i, | ||
"date": /^[Y\d]{4}-[M\d]{2}-[D\d]{2}$/i, | ||
"duration": /^P/, | ||
"duration-normal": /(day[s]?|hour[s]?|minute[s]?|second[s]?)$/, | ||
"duration-abbreviation": /(d|h|m|s)$/, | ||
}, | ||
defaultFormats: { | ||
"duration": name => "[getduration(".concat(name,"\"officialDurationString\")]"), | ||
"duration-abbreviation": name => "[getduration(".concat(name,"\"abbreviatedDurationString\")]"), | ||
"duration-normal": name => "[getduration(".concat(name,"\"normalDurationString\")]"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use template strings for concatenation, which are more readable than |
||
"date": name => `[day(${name})] [month(${name}, 'shortname')] [year(${name})]`, | ||
"month": name => `[month(${name}, 'name')] [year(${name})]`, | ||
"time": name => `[hour(${name}, '00')]:[minute(${name}, '00')]`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,20 @@ $.extend(_, { | |
}, {multiValued: true}), | ||
|
||
localTimezone: -(new Date()).getTimezoneOffset(), | ||
getduration: $.extend(function (dur, format) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear what the purpose of A few more minor things:
|
||
if(format === "officialDurationString") {durationRegEx = /P(?:([.,\d]+)D)?(?:T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?)?/;} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please install ESLint + an ESLint plugin for your editor so you can get inline warnings when the coding style of the project is not followed. |
||
if(format === "abbreviatedDurationString") {durationRegEx = /[\s]*(?:([.,\d]+)d)?[\s]*(?:([.,\d]+)h)?[\s]*(?:([.,\d]+)m)?[\s]*(?:([.,\d]+)s)?[\s]*/;} | ||
if(format === "normalDurationString") {durationRegEx = /[\s]*(?:([.,\d]+)[ ]?day[s]?)?[\s]*(?:([.,\d]+)[ ]?hour[s]?)?[\s]*(?:([.,\d]+)[ ]?minute[s]?)?[\s]*(?:([.,\d]+)[ ]?second[s]?)?[\s]*/;} | ||
var matches = dur.match(durationRegEx); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is an interesting violation of DRY. Interesting because it's less obvious than simply duplicated code, but there is still more than one sources of truth. The |
||
var dur_days = matches[1] === undefined ? 0 : matches[1]; | ||
var dur_hours = matches[2] === undefined ? 0 : matches[2]; | ||
var dur_minutes = matches[3] === undefined ? 0 : matches[3]; | ||
var dur_seconds = matches[4] === undefined ? 0 : matches[4]; | ||
|
||
var dur_num = dur_days*24*60*60*1000+dur_hours*60*60*1000+dur_minutes*60*1000+dur_seconds*1000; | ||
|
||
return this.duration(dur_num); | ||
}), | ||
}); | ||
|
||
_.msTo = (what, ms) => Math.floor(Math.abs(ms) / (s[what] * 1000)) || 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see what you meant now. Yes, we'd need to add ms, weeks, months, years too.
One direction to explore: can we make this work for other languages beyond English? (look at the
Intl
object)