HijrahDate hd=HijrahChronology.INSTANCE.date(LocalDate.of(2014,11, 25));
If we have HijrahDate Instance , it is expected to have a method in UmalquraCalendar API that shows the name of month :
i inspect properties of this instance using groovy API :
['era':AH,
'class':class java.time.chrono.HijrahDate,
'prolepticMonth':17233,
'eraValue':1,
'dayOfWeek':2,
'leapYear':false,
'chronology':Hijrah-umalqura,
'dayOfYear':32]
However we don't find the month name which must be one of the following list items :
Muḥarram (محرم meaning "forbidden"), so called because battle was
forbidden (haram) during this month. Muharram includes the Day of
Ashura.
Ṣafar (صفر meaning "void"), supposedly named thus because
pagan Arab houses were empty this time of year while their occupants
gathered food.
Rabīʿ I (Rabīʿ al-Awwal, ربيع الأوّل) meaning "the
first spring".
Rabīʿ II (Rabīʿ ath-Thānī ربيع الثاني or Rabīʿ al-Ākhir
ربيع الآخ
.....................
............ so on SEE
Thus , since there is no attribute save month's name , it is expwcted to have a method retrieve this info ?
What's this method?
The date does not contain information about the names of the months or days. To get that you need a formatter:
System.out.println(DateTimeFormatter.ofPattern("MMMM").format(hd));
prints Safar.
Since the main language of UmalQura is the arabic langugage, Developers & programmers who uses UmalQuraCalender want to display the month in arabic. Thus , we base on #assylias answer we can add the Locale object to print صفر instead of Safar
System.out.println(DateTimeFormatter.ofPattern("MMMM").format(hd,new Locale("ar")));
public String getIslamicDate(){
return DateTimeFormatter.ofPattern("MMMM",new Locale("ar")).format(HijrahDate.now());
}
I think this should work just fine and return the month in arabic language
Related
I am trying to implement an if statement on my Thymeleaf template that will change the colour of a value based on the current time (minus a specific amount of days).
Now from my understanding there are three ways to declare a date in Thymeleaf:
//For the new LocalDateTime, LocalDate classes
#temporals.createNow()
//For an instance of java.util.Date
#dates.createNow()
//For an instance of java.util.Calendars
#calendars.createNow()
Now my model uses instances of java.util.LocalDate so I tried tackling the problems in two different ways (unsuccessfully).
The first thing that come into my mind was to implement the following:
td th:if="${user.expiry_date.isBefore(#temporals.createNow().minus(7, ChronoUnit.DAYS))}"
th:text="${#dates.format(user.expiry_date, 'dd-MM-yyyy')}"style="color: red"/>
But I get the following SpelEvaluationException:
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'DAYS' cannot be found on null
The other approach would be to subtract the date on the server and pass the value through a variable:
//method in the #Controller class
model.addAttribute("userList", organisationService.getAllOrganisations());
**model.addAttribute("localDateNow", LocalDate.now().minusDays(7));**
But even then, accessing another variable inside the same spel expression seems impossible, or at least all my attempts failed:
<td th:if="${user.expiry_date.isBefore(localDateNow)}"
th:text="${#dates.format(user.expiry_date, 'dd-MM-yyyy')}"style="color: orange"/>
and:
<td th:if="${user.expiry_date.isBefore(${localDateNow})}"
th:text="${#dates.format(user.expiry_date, 'dd-MM-yyyy')}"style="color: orange"/>
For the first case, you can't directly call classes by name I believe. you'd have to do "${user.expiry_date.isBefore(#temporals.createNow().minus(7, T(java.time.temporal.ChronoUnit).DAYS))}"
And for the second I think you should be using ${#temporals.format()} as you'r using LocalDateTime not the clasic Date object but as theres no stacktrace given this is just a guess
I'm trying to run a meta-regression with MD's as dependent variable. I want to add a numeric moderator (year published) to the rma.uni function.
Formula so far:
metafor::rma.uni(yi=MCID12, sei=SE12, method="FE", data=Pain, slab=paste(Pain$Author, Pain$Year), weighted=TRUE, subset=(Pain$outcomegruppe=="9"), mods =("Pain$Year") )
I always get the error message:
Error in metafor::rma.uni(yi = MCID12, sei = SE12, method = "FE", data = Pain, :
Model matrix contains character variables.
My "Year" veriable is definetly numeric. As soon as I don't use the "mods" argument, everything works normal.
Could anyone help me with this problem?
Thanks in advance!
Don't put Year in quotes. Also, you don't need the Pain$ parts and weighted=TRUE is the default. This should do it:
metafor::rma.uni(yi=MCID12, sei=SE12, method="FE", data=Pain, slab=paste(Author, Year),
subset=(outcomegruppe=="9"), mods=~Year)
Its possible to book appointments in my app and I get the queue line value from this code to display for the users in the app:
Text = $"Spot {_Class.Slots.WaitList}";
What im trying to get here is to show the queue that person has. The issue is that the value im getting from that line is the value that says how many people there are in the line. So if a person books an appointment the value has to increase from e.g 2 to 3.
EDIT:
The value im getting from this code I get from the database:
Text = $"Spot {_Class.Slots.WaitList}";
The value is 1 (just an example) but i need the value to be +1 every time.
I tried to do this:
Text = $"Spot {_Class.Slots.WaitList + "1"}";
But it added 10 instead of 1.
What's the type of WaitList field/property?
I don't see a reason why this wouldn't work:
Text = $"Spot {_Class.Slots.WaitList + 1}";
I have this in my controller
public function editProfile(Request $request){
$question1 = Question::where('group',1)->lists('question', 'id');
$question2 = Question::where('group',2)->lists('question', 'id');
return view('user', compact(''question1', 'question2'));
}
$question = {\"1\":\"What is the first name of your best friend in high school?\",\"2\":\"What was the name of your first pet?\",\"3\":\"What was the first thing you learned to cook?\",\"4\":\"What was the first film you saw in the theater?\"}
$question2 = {\"5\":\"Where did you go the first time you flew on a plane?\",\"6\":\"What is the last name of your favorite elementary school teacher?\",\"7\":\"In What city or town does your nearest sibling live?\"}
I would like to translate the value in both question 1 and question 2 and pass it to user blade without changing the key, Any suggestions?
As specified at the localization doc, you need to populate a lang file with translation strings. So, let's say you want to show both Spanish and English strings. In this case you'd need to create two files: /resources/lang/en/messages.php and /resources/lang/es/messages.php. The content of one of those files would be somewhat like this:
<?php
// resources/lang/es/messages.php
return [
'welcome' => 'Bienvenido'
];
This way, you could access the strings in there with the following method: __('messages.welcome'), which would return the string for the language set on your config/app.php -- the default entry is en, by the way, but you can set it to whatever you want. The value in there will define which language will be chosen when selecting strings.
Another method to create translation strings is using the string itself as key, storing them in a JSON file instead of PHP. For example, the following translation string:
{
"I love programming.": "Me encanta programar."
}
would be accessible through this: __('I love programming.').
Having said that, you may solve your problem through the two methods presented above. You could store in your DB keywords for the questions instead of the whole text, and create translation for as many languages as you want. Also, you could keep the questions in your database and create translation strings for those questions. Finally, you'd need to iterate over the fetched entries and translate each one of them, or use some Collection helper to do the hard work for you, like transform or map.
Why does this test pass, while the month value is obviously invalid (13)?
#Test
public void test() {
String format = "uuuuMM";
String value = "201713";
DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT)
.parse(value);
}
When using a temporal query, the expected DateTimeParseException is thrown:
DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT)
.parse(value, YearMonth::from);
What happens when no TemporalQuery is specified?
EDIT: the 13 value seems to be a special one, as I learned thanks to the answer of ΦXocę 웃 Пepeúpa ツ (see Undecimber).
But the exception is not thrown even with another value, like 50:
#Test
public void test() {
String format = "uuuuMM";
String value = "201750";
DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT)
.parse(value);
}
I've made some debugging here and found that part of the parsing process is to check the fields against the formatter's chronology.
When you create a DateTimeFormatter, by default it uses an IsoChronology, which is used to resolve the date fields. During this resolving phase, the method java.time.chrono.AbstractChronology::resolveDate is called.
If you look at the source, you'll see the following logic:
if (fieldValues.containsKey(YEAR)) {
if (fieldValues.containsKey(MONTH_OF_YEAR)) {
if (fieldValues.containsKey(DAY_OF_MONTH)) {
return resolveYMD(fieldValues, resolverStyle);
}
....
return null;
As the input has only the year and month fields, fieldValues.containsKey(DAY_OF_MONTH) returns false, the method returns null and no other check is made as you can see in the Parsed class.
So, when parsing 201750 or 201713 without a TemporalQuery, no additional check is made because of the logic above, and the parse method returns a java.time.format.Parsed object, as you can see by the following code:
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("uuuuMM").withResolverStyle(ResolverStyle.STRICT);
TemporalAccessor parsed = fmt.parse("201750");
System.out.println(parsed.getClass());
System.out.println(parsed);
The output is:
class java.time.format.Parsed
{Year=2017, MonthOfYear=50},ISO
Note that the type of the returned object is java.time.format.Parsed and printing it shows the fields that were parsed (year and month).
When you call parse with a TemporalQuery, though, the Parsed object is passed to the query and its fields are validated (of course it depends on the query, but the API built-in ones always validate).
In the case of YearMonth::from, it checks if the year and month are valid using the respective ChronoField's (MONTH_OF_YEAR and YEAR) and the month field accepts only values from 1 to 12.
That's why just calling parse(value) doesn't throw an exception, but calling with a TemporalQuery does.
Just to check the logic above when all the date fields (year, month and day) are present:
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("uuuuMMdd").withResolverStyle(ResolverStyle.STRICT);
fmt.parse("20175010");
This throws:
Exception in thread "main" java.time.format.DateTimeParseException: Text '20175010' could not be parsed: Invalid value for MonthOfYear (valid values 1 - 12): 50
As all the date fields are present, fieldValues.containsKey(DAY_OF_MONTH) returns true and now it checks if it's a valid date (using the resolveYMD method).
The month 13 is called : Undecimber
The gregorian calendar that many of us use allows 12 months only but java includes support for calendars which permit thirteen months so it depends on what calendar system you are talking about
For example, the actual maximum value of the MONTH field is 12 in some years, and 13 in other years in the Hebrew calendar system. So the month 13 is valid
It is a little odd that an exception is not thrown when parse is called without a given TemporalQuery. Some of the documentation for the single argument parse method:
This parses the entire text producing a temporal object. It is typically more useful to use parse(CharSequence, TemporalQuery). The result of this method is TemporalAccessor which has been resolved, applying basic validation checks to help ensure a valid date-time.
Note that it says it is "typically more useful to use parse(CharSequence, TemporalQuery)". In your examples, parse is returning a java.time.format.Parsed object, which is not really used for anything other than creating a different TemporalAccessor.
Note that if you try to create a YearMonth from the returned value, an exception is thrown:
YearMonth.from(DateTimeFormatter.ofPattern(format)
.withResolverStyle(ResolverStyle.STRICT).parse(value));
throws
Exception in thread "main" java.time.DateTimeException: Unable to obtain YearMonth from TemporalAccessor: {Year=2017, MonthOfYear=50},ISO of type java.time.format.Parsed
at java.time.YearMonth.from(YearMonth.java:263)
at anl.nfolds.Test.main(Test.java:21)
Caused by: java.time.DateTimeException: Invalid value for MonthOfYear (valid values 1 - 12): 50
at java.time.temporal.TemporalAccessor.get(TemporalAccessor.java:224)
at java.time.YearMonth.from(YearMonth.java:260)
... 1 more
Documentation for Parsed:
A store of parsed data.
This class is used during parsing to collect the data. Part of the parsing process involves handling optional blocks and multiple copies of the data get created to support the necessary backtracking.
Once parsing is completed, this class can be used as the resultant TemporalAccessor. In most cases, it is only exposed once the fields have been resolved.
Since:1.8
#implSpecThis class is a mutable context intended for use from a single thread. Usage of the class is thread-safe within standard parsing as a new instance of this class is automatically created for each parse and parsing is single-threaded