Skip to content

change string functions #68

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ Number. The month passed to the constructor, possibly fixed up. It is preferred

Number. The day passed to the constructor, possibly fixed up. It is preferred to get this value with `Hebcal.HDate.prototype.getDate()`. (Not actually a prototype value.)


### `Hebcal.HDate.prototype.lat`
### `Hebcal.HDate.prototype.long`

Expand Down Expand Up @@ -745,6 +746,9 @@ Number. The day of the month of the date.

Number. The day of the week of the date. 0 is Sunday, as with `Date.prototype.getDay()`.

### `Hebcal.HDate.prototype.getWeekDayName()`
string. get the name of week day.

### `Hebcal.HDate.prototype.setFullYear(year)`

Sets the year of the date. Returns the object it was called upon.
Expand Down Expand Up @@ -777,6 +781,22 @@ Return a number representing the number of days since December 31, 1 BCE, an "ab

Return a string with the current day, month, and year. Takes a standard language options string.

### `Hebcal.HDate.prototype.getDayName(o)`

Return a string with the current day. Takes a standard language options string.

### `Hebcal.HDate.prototype.getMonthName(o)`

Return a string with the current month. Takes a standard language options string.

### `Hebcal.HDate.prototype.getYearName(o)`

Return a string with the current year. Takes a standard language options string.

### `Hebcal.HDate.prototype.dateFormat(format,o)`

Return a string with the current year. ,the first args the format string ('D' - for day, 'M' - month,'Y' - for year'), the second arg takes a standard language options string.

```js
new Hebcal.HDate().toString() // 16 Adar I 5774
new Hebcal.HDate(1,7,5769).toString() // 1 Tishrei 5769
Expand Down
23 changes: 15 additions & 8 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,22 @@ exports.monthNames = [
monthNames.concat([["Adar 1", 0, "אדר א'"],["Adar 2", 0, "אדר ב'"],["Nisan", 0, "ניסן"]])
];

exports.days = {
SUN: 0,
MON: 1,
TUE: 2,
WED: 3,
THU: 4,
FRI: 5,
SAT: 6

exports.daysNames = {
0 : {'h' : 'ראשון','eng' : 'Sunday','varName' : 'SUN'} ,
1 : {'h' : 'שני','eng' : 'Monday','varName' : 'MON'} ,
2 : {'h' : 'שלישי','eng' : 'Tuesday','varName' : 'TUE'} ,
3 : {'h' : 'רביעי','eng' : 'Wednesday','varName' : 'WED'} ,
4 : {'h' : 'חמישי','eng' : 'Thursday','varName' : 'THU'} ,
5 : {'h' : 'שישי','eng' : 'Friday','varName' : 'FRI'} ,
6 : {'h' : 'שבת','eng' : 'Saturday','varName' : 'SAT'} ,
};
var daysVars = {};
for(var i in this.daysNames){
daysVars[this.daysNames.varName] = i;
}
exports.days = daysVars;


exports.LANG = function(str, opts){
return opts == 'h' && str[2] || (opts == 'a' && str[1] || str[0]);
Expand Down
25 changes: 22 additions & 3 deletions src/hdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,37 @@ prototype[abs] = function() {
};

prototype.toString = function(o) {
return c.LANG([this[getDate](), null, gematriya(this[getDate]())], o) + ' ' +
return this.getDayName(o) + ' ' +
this.getMonthName(o) + ' ' +
c.LANG([this[getFullYear](), null, gematriya(this[getFullYear]())], o);
this.getYearName(o);
};

prototype.getWeekDayName = function(o) {
let dayObj = c.daysNames[this.getDay()];
if (dayObj){
return c.daysNames[this.getDay()][o] ? c.daysNames[this.getDay()][o] : c.daysNames[this.getDay()]['eng'];
}
return "";
};

prototype.getMonthName = function(o) {
return c.LANG(c.monthNames[+this.isLeapYear()][this[getMonth]()], o);
};

prototype.getDayName = function(o) {
return c.LANG([this[getDate](), null, gematriya(this[getDate]())], o);
};
prototype.getYearName = function(o) {
return c.LANG([this[getFullYear](), null, gematriya(this[getFullYear]())], o);
};
prototype.setCity = function(city) {
return this.setLocation(cities.getCity(city));
};
prototype.dateFormat = function(format, o){
let dayMask = "D";
let monthMask = "M";
let yearMask = "Y";
return format.replace(dayMask, this.getDayName(o)).replace(monthMask, this.getMonthName(o)).replace(yearMask, this.getYearName(o));
};

prototype.setLocation = function(lat, lon) {
if (typeof lat == 'object' && !Array.isArray(lat)) {
Expand Down