Sunday | 一个界面很炫的天气类应用,当中用到了大量的Android控件以及第三方类库等。

 by   ljtyzhr Java Updated: 2 years ago - Current License: No License

Download this library from

Build Applications

kandi X-RAY | Sunday REVIEW AND RATINGS

一个界面很炫的天气类应用,当中用到了大量的Android控件以及第三方类库等。

kandi-support
Support

  • Sunday has a low active ecosystem.
  • It has 25 star(s) with 26 fork(s).
  • It had no major release in the last 12 months.
  • On average issues are closed in 2162 days.
  • It has a neutral sentiment in the developer community.

quality kandi
Quality

  • Sunday has no issues reported.

security
Security

  • Sunday has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

license
License

  • Sunday does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.

build
Reuse

  • Sunday releases are not available. You will need to build from source code and install.
  • Sunday has no build file. You will be need to create the build yourself to build the component from source.
Top functions reviewed by kandi - BETA

kandi has reviewed Sunday and discovered the below as its top functions. This is intended to give you an instant insight into Sunday implemented functionality, and help decide if they suit your requirements.

  • Calculate the transformation matrices .
  • touch the list view
  • Process a touch event .
  • Called when a page is scrolled .
  • Adds a crouton to the view .
  • Called when views are changed .
  • Initializes the view .
  • Initialize the crouton view group .
  • Read objects from a file .
  • get a weather icon

Sunday Key Features

一个界面很炫的天气类应用,当中用到了大量的Android控件以及第三方类库等。

Sunday examples and code snippets

  • How to generate random names on particular days in Java?
  • Pandas Filter dataframe according to working days
  • Move 2nd level sub-array to the top of the 1st level multidimentional array based on value of the sub-array
  • How to select records from January 1, 2021 to last week
  • Get the number of the current weekday in ASP.NET Core
  • Split days of the week string MTWTHFSSU using PREG_SPLIT
  • Use an integer field to store the selectged days with bitwise op
  • Can anyone explain to me this line of code in JavaScript?
  • How to get current date and time in swift?
  • Is there an efficient way to store Firebase data in an arraylist and then read it?

How to generate random names on particular days in Java?

String[] names = new String[]{"one", "two", "three", "four", "five"};
String[] lastWeekend = new String[]{"one", "three"}; // you should get these from somewhere else

Random rd = new Random();

int x = rd.nextInt(names.length);

// using a list for convenience
while(Arrays.asList(lastWeekend).contains(names[x]))
{
    x = rd.nextInt(names.length);
}

// names[x] will now be "two", "four" or "five"
-----------------------
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class WeekEndCheck {
    
    List<String> lastWeekendNames = new ArrayList<>();
    List<String> availableNames = new LinkedList<>(
        Arrays.asList("one", "two", "three", "four", "five"));
    
    public static void main(String[] args) {
        new WeekEndCheck().start();
    }
    
    public void start() {
        // do it for 10 weekends, not two names should
        // appear adjacent to each other
        for (int i = 0; i < 10; i++) {
            setWeekEndNames();
            System.out.println("Weekend " + (i+1) + " " + lastWeekendNames);
        }
    }
    
    Random r = new Random();
    
    public void setWeekEndNames() {
        List<String> temp = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            int indx = r.nextInt(availableNames.size());
            temp.add(availableNames.remove(indx));
        }
        availableNames.addAll(lastWeekendNames);
        lastWeekendNames.clear();
        lastWeekendNames.addAll(temp);
    }
}
Weekend 1 [three, one]
Weekend 2 [two, four]
Weekend 3 [five, one]
Weekend 4 [two, four]
Weekend 5 [one, three]
Weekend 6 [five, four]
Weekend 7 [three, two]
Weekend 8 [one, four]
Weekend 9 [two, five]
Weekend 10 [one, three]
public void setWeekEndNames() {
    List<String> temp = new ArrayList<>();
    int[] indices = new int[2];
    for (int i = 0; i < 2; i++) {
        indices[i] = r.nextInt(availableNames.size());
        temp.add(availableNames.get(indices[i]));
    }
    if (indices[0] == indices[1]) {
        availableNames.remove(indices[0]);
    } else {
        availableNames.remove(Math.max(indices[0], indices[1]));
        availableNames.remove(Math.min(indices[0], indices[1]));
    }
    availableNames.addAll(lastWeekendNames);
    lastWeekendNames.clear();
    lastWeekendNames.addAll(temp);
}
-----------------------
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class WeekEndCheck {
    
    List<String> lastWeekendNames = new ArrayList<>();
    List<String> availableNames = new LinkedList<>(
        Arrays.asList("one", "two", "three", "four", "five"));
    
    public static void main(String[] args) {
        new WeekEndCheck().start();
    }
    
    public void start() {
        // do it for 10 weekends, not two names should
        // appear adjacent to each other
        for (int i = 0; i < 10; i++) {
            setWeekEndNames();
            System.out.println("Weekend " + (i+1) + " " + lastWeekendNames);
        }
    }
    
    Random r = new Random();
    
    public void setWeekEndNames() {
        List<String> temp = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            int indx = r.nextInt(availableNames.size());
            temp.add(availableNames.remove(indx));
        }
        availableNames.addAll(lastWeekendNames);
        lastWeekendNames.clear();
        lastWeekendNames.addAll(temp);
    }
}
Weekend 1 [three, one]
Weekend 2 [two, four]
Weekend 3 [five, one]
Weekend 4 [two, four]
Weekend 5 [one, three]
Weekend 6 [five, four]
Weekend 7 [three, two]
Weekend 8 [one, four]
Weekend 9 [two, five]
Weekend 10 [one, three]
public void setWeekEndNames() {
    List<String> temp = new ArrayList<>();
    int[] indices = new int[2];
    for (int i = 0; i < 2; i++) {
        indices[i] = r.nextInt(availableNames.size());
        temp.add(availableNames.get(indices[i]));
    }
    if (indices[0] == indices[1]) {
        availableNames.remove(indices[0]);
    } else {
        availableNames.remove(Math.max(indices[0], indices[1]));
        availableNames.remove(Math.min(indices[0], indices[1]));
    }
    availableNames.addAll(lastWeekendNames);
    lastWeekendNames.clear();
    lastWeekendNames.addAll(temp);
}
-----------------------
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class WeekEndCheck {
    
    List<String> lastWeekendNames = new ArrayList<>();
    List<String> availableNames = new LinkedList<>(
        Arrays.asList("one", "two", "three", "four", "five"));
    
    public static void main(String[] args) {
        new WeekEndCheck().start();
    }
    
    public void start() {
        // do it for 10 weekends, not two names should
        // appear adjacent to each other
        for (int i = 0; i < 10; i++) {
            setWeekEndNames();
            System.out.println("Weekend " + (i+1) + " " + lastWeekendNames);
        }
    }
    
    Random r = new Random();
    
    public void setWeekEndNames() {
        List<String> temp = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            int indx = r.nextInt(availableNames.size());
            temp.add(availableNames.remove(indx));
        }
        availableNames.addAll(lastWeekendNames);
        lastWeekendNames.clear();
        lastWeekendNames.addAll(temp);
    }
}
Weekend 1 [three, one]
Weekend 2 [two, four]
Weekend 3 [five, one]
Weekend 4 [two, four]
Weekend 5 [one, three]
Weekend 6 [five, four]
Weekend 7 [three, two]
Weekend 8 [one, four]
Weekend 9 [two, five]
Weekend 10 [one, three]
public void setWeekEndNames() {
    List<String> temp = new ArrayList<>();
    int[] indices = new int[2];
    for (int i = 0; i < 2; i++) {
        indices[i] = r.nextInt(availableNames.size());
        temp.add(availableNames.get(indices[i]));
    }
    if (indices[0] == indices[1]) {
        availableNames.remove(indices[0]);
    } else {
        availableNames.remove(Math.max(indices[0], indices[1]));
        availableNames.remove(Math.min(indices[0], indices[1]));
    }
    availableNames.addAll(lastWeekendNames);
    lastWeekendNames.clear();
    lastWeekendNames.addAll(temp);
}

Pandas Filter dataframe according to working days

df['date'] = pd.to_datetime(df['date'], dayfirst=True)

offset = pd.offsets.CustomBusinessDay(2, weekmask='Mon Tue Wed Thu Fri Sat')
new_date = pd.to_datetime('today').normalize() - offset
print (new_date)
2021-06-12 00:00:00

new_df = df[df['date'] <= new_date]
print (new_df)
  name       date
0  aaa 2021-06-12
1  bbb 2021-06-11
2  ccc 2021-06-10
5  eee 2021-05-10
6  fff 2021-06-01
7  ggg 2021-05-10

Move 2nd level sub-array to the top of the 1st level multidimentional array based on value of the sub-array

<?php 
$array1 = array( 0 => array ( ),
        1 => array ( ),
        2 => array ( ),
        3 => array ( ),
        4 => array ( 0 => 'Aaron Summers', ),
        5 => array ( 0 => 'Taz Patel', ),
        6 => array ( 0 => 'Sonia Tam', ),
        7 => array ( 0 => 'Adam Smart', ),
        8 => array ( 0 => 'Andrew Montgomery', ),
    ) ;
    
    $people = [];
    foreach ($array1 as $a) { 
        if(count($a)>0 && $person = $a[0]) {
            $people[]= $person;
        }
    }

$array2 =array ( 0 => array ( 0 => 'Aaron Summers', 1 => 'Aaron Summers', 2 => 'Aaron Summers', ),
        1 => array ( 0 => 'Adam Smart', 1 => 'Adam Smart', 2 => 'Adam Smart', ),
        2 => array ( 0 => 'Andrew Montgomery', 1 => 'Andrew Montgomery', 2 => 'Andrew Montgomery', ),
        3 => array ( 0 => 'Dave Robertson', 1 => 'Dave Robertson', 2 => 'Dave Robertson', ),
        4 => array ( 0 => 'Holly Colby', 1 => 'Holly Colby', ),
        5 => array ( 0 => 'Karen Fok', 1 => 'Karen Fok', 2 => 'Karen Fok', ),
        6 => array ( 0 => 'Kieran Lintott', 1 => 'Kieran Lintott', 2 => 'Kieran Lintott', ),
        7 => array ( 0 => 'Rebecca Roffey', 1 => 'Rebecca Roffey', 2 => 'Rebecca Roffey', ),
        8 => array ( 0 => 'Sonia Tam', 1 => 'Sonia Tam', 2 => 'Sonia Tam', ),
        9 => array ( 0 => 'Steffi Wallace', 1 => 'Steffi Wallace', 2 => 'Steffi Wallace', ),
        10 => array ( 0 => 'Taz Patel', 1 => 'Taz Patel', 2 => 'Taz Patel', ),
    );
   $final=[];
    foreach($array2 as $a) {
       if (in_array($a[0], $people) !==false) array_unshift($final, $a);
       else $final[]=$a;
    }
    

print_r($final);
?>
Array
(
    [0] => Array
        (
            [0] => Taz Patel
            [1] => Taz Patel
            [2] => Taz Patel
        )

    [1] => Array
        (
            [0] => Sonia Tam
            [1] => Sonia Tam
            [2] => Sonia Tam
        )

    [2] => Array
        (
            [0] => Andrew Montgomery
            [1] => Andrew Montgomery
            [2] => Andrew Montgomery
        )

    [3] => Array
        (
            [0] => Adam Smart
            [1] => Adam Smart
            [2] => Adam Smart
        )

    [4] => Array
        (
            [0] => Aaron Summers
            [1] => Aaron Summers
            [2] => Aaron Summers
        )

    [5] => Array
        (
            [0] => Dave Robertson
            [1] => Dave Robertson
            [2] => Dave Robertson
        )

    [6] => Array
        (
            [0] => Holly Colby
            [1] => Holly Colby
        )

    [7] => Array
        (
            [0] => Karen Fok
            [1] => Karen Fok
            [2] => Karen Fok
        )

    [8] => Array
        (
            [0] => Kieran Lintott
            [1] => Kieran Lintott
            [2] => Kieran Lintott
        )

    [9] => Array
        (
            [0] => Rebecca Roffey
            [1] => Rebecca Roffey
            [2] => Rebecca Roffey
        )

    [10] => Array
        (
            [0] => Steffi Wallace
            [1] => Steffi Wallace
            [2] => Steffi Wallace
        )

)
-----------------------
<?php 
$array1 = array( 0 => array ( ),
        1 => array ( ),
        2 => array ( ),
        3 => array ( ),
        4 => array ( 0 => 'Aaron Summers', ),
        5 => array ( 0 => 'Taz Patel', ),
        6 => array ( 0 => 'Sonia Tam', ),
        7 => array ( 0 => 'Adam Smart', ),
        8 => array ( 0 => 'Andrew Montgomery', ),
    ) ;
    
    $people = [];
    foreach ($array1 as $a) { 
        if(count($a)>0 && $person = $a[0]) {
            $people[]= $person;
        }
    }

$array2 =array ( 0 => array ( 0 => 'Aaron Summers', 1 => 'Aaron Summers', 2 => 'Aaron Summers', ),
        1 => array ( 0 => 'Adam Smart', 1 => 'Adam Smart', 2 => 'Adam Smart', ),
        2 => array ( 0 => 'Andrew Montgomery', 1 => 'Andrew Montgomery', 2 => 'Andrew Montgomery', ),
        3 => array ( 0 => 'Dave Robertson', 1 => 'Dave Robertson', 2 => 'Dave Robertson', ),
        4 => array ( 0 => 'Holly Colby', 1 => 'Holly Colby', ),
        5 => array ( 0 => 'Karen Fok', 1 => 'Karen Fok', 2 => 'Karen Fok', ),
        6 => array ( 0 => 'Kieran Lintott', 1 => 'Kieran Lintott', 2 => 'Kieran Lintott', ),
        7 => array ( 0 => 'Rebecca Roffey', 1 => 'Rebecca Roffey', 2 => 'Rebecca Roffey', ),
        8 => array ( 0 => 'Sonia Tam', 1 => 'Sonia Tam', 2 => 'Sonia Tam', ),
        9 => array ( 0 => 'Steffi Wallace', 1 => 'Steffi Wallace', 2 => 'Steffi Wallace', ),
        10 => array ( 0 => 'Taz Patel', 1 => 'Taz Patel', 2 => 'Taz Patel', ),
    );
   $final=[];
    foreach($array2 as $a) {
       if (in_array($a[0], $people) !==false) array_unshift($final, $a);
       else $final[]=$a;
    }
    

print_r($final);
?>
Array
(
    [0] => Array
        (
            [0] => Taz Patel
            [1] => Taz Patel
            [2] => Taz Patel
        )

    [1] => Array
        (
            [0] => Sonia Tam
            [1] => Sonia Tam
            [2] => Sonia Tam
        )

    [2] => Array
        (
            [0] => Andrew Montgomery
            [1] => Andrew Montgomery
            [2] => Andrew Montgomery
        )

    [3] => Array
        (
            [0] => Adam Smart
            [1] => Adam Smart
            [2] => Adam Smart
        )

    [4] => Array
        (
            [0] => Aaron Summers
            [1] => Aaron Summers
            [2] => Aaron Summers
        )

    [5] => Array
        (
            [0] => Dave Robertson
            [1] => Dave Robertson
            [2] => Dave Robertson
        )

    [6] => Array
        (
            [0] => Holly Colby
            [1] => Holly Colby
        )

    [7] => Array
        (
            [0] => Karen Fok
            [1] => Karen Fok
            [2] => Karen Fok
        )

    [8] => Array
        (
            [0] => Kieran Lintott
            [1] => Kieran Lintott
            [2] => Kieran Lintott
        )

    [9] => Array
        (
            [0] => Rebecca Roffey
            [1] => Rebecca Roffey
            [2] => Rebecca Roffey
        )

    [10] => Array
        (
            [0] => Steffi Wallace
            [1] => Steffi Wallace
            [2] => Steffi Wallace
        )

)
-----------------------
$array2 = array_merge(array_column(array_filter($array1), null, 0), 
                      array_column($array2, null, 0));
$array2 = array_values(array_filter(array_merge(array_column($array1, null, 0),
                                                array_column($array2, null, 0)));
-----------------------
$array2 = array_merge(array_column(array_filter($array1), null, 0), 
                      array_column($array2, null, 0));
$array2 = array_values(array_filter(array_merge(array_column($array1, null, 0),
                                                array_column($array2, null, 0)));

How to select records from January 1, 2021 to last week

WHERE start_date BETWEEN TO_DATE('2021-01-01', 'yyyy-mm-dd') AND (TRUNC(SYSDATE) - TO_CHAR(SYSDATE, 'd'));
-----------------------
select trunc(sysdate, 'year') first_day_of_year, next_day(sysdate - 7, 'sun') last_sunday from dual;
-----------------------
SELECT *
FROM   table_name
WHERE  start_date >= DATE '2021-01-01'
AND    start_date <  TRUNC( SYSDATE, 'IW' )
SELECT *
FROM   table_name
WHERE  start_date >= TRUNC( SYSDATE, 'YYYY' )
AND    start_date <  TRUNC( SYSDATE, 'IW' )
-----------------------
SELECT *
FROM   table_name
WHERE  start_date >= DATE '2021-01-01'
AND    start_date <  TRUNC( SYSDATE, 'IW' )
SELECT *
FROM   table_name
WHERE  start_date >= TRUNC( SYSDATE, 'YYYY' )
AND    start_date <  TRUNC( SYSDATE, 'IW' )
-----------------------
SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> alter session set nls_date_language = 'english';

Session altered.
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
05.01.2021, tuesday
06.01.2021, wednesday
07.01.2021, thursday
08.01.2021, friday
<snip>
09.06.2021, wednesday
10.06.2021, thursday
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>
SQL> alter system set fixed_date = '16.06.2021';

System altered.

SQL> alter session set nls_date_language = 'english';

Session altered.

SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> select sysdate from dual;

SYSDATE
---------------------
16.06.2021, wednesday
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
<snip>
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>
-----------------------
SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> alter session set nls_date_language = 'english';

Session altered.
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
05.01.2021, tuesday
06.01.2021, wednesday
07.01.2021, thursday
08.01.2021, friday
<snip>
09.06.2021, wednesday
10.06.2021, thursday
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>
SQL> alter system set fixed_date = '16.06.2021';

System altered.

SQL> alter session set nls_date_language = 'english';

Session altered.

SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> select sysdate from dual;

SYSDATE
---------------------
16.06.2021, wednesday
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
<snip>
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>
-----------------------
SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> alter session set nls_date_language = 'english';

Session altered.
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
05.01.2021, tuesday
06.01.2021, wednesday
07.01.2021, thursday
08.01.2021, friday
<snip>
09.06.2021, wednesday
10.06.2021, thursday
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>
SQL> alter system set fixed_date = '16.06.2021';

System altered.

SQL> alter session set nls_date_language = 'english';

Session altered.

SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> select sysdate from dual;

SYSDATE
---------------------
16.06.2021, wednesday
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
<snip>
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>
-----------------------
SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> alter session set nls_date_language = 'english';

Session altered.
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
05.01.2021, tuesday
06.01.2021, wednesday
07.01.2021, thursday
08.01.2021, friday
<snip>
09.06.2021, wednesday
10.06.2021, thursday
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>
SQL> alter system set fixed_date = '16.06.2021';

System altered.

SQL> alter session set nls_date_language = 'english';

Session altered.

SQL> alter session set nls_date_format = 'dd.mm.yyyy, day';

Session altered.

SQL> select sysdate from dual;

SYSDATE
---------------------
16.06.2021, wednesday
SQL> select trunc(sysdate, 'yyyy') + level - 1 as datum
  2  from dual
  3  connect by level <= next_day(trunc(sysdate) - 7, 'sunday') - trunc(sysdate, 'yyyy') + 1
  4  order by datum;

DATUM
---------------------
01.01.2021, friday
02.01.2021, saturday
03.01.2021, sunday
04.01.2021, monday
<snip>
11.06.2021, friday
12.06.2021, saturday
13.06.2021, sunday

164 rows selected.

SQL>

Get the number of the current weekday in ASP.NET Core

day1 = (int)DateTime.Now.DayOfWeek;
-----------------------
public static class EnumExtensions
{
    public static int ToInt<T>(this T source) where T : Enum
    {
        return (int) (IConvertible) source;
    }
}
DateTime.Now.DayOfWeek.ToInt();
Console.WriteLine(DayOfWeek.Monday.ToInt()); // outputs 1
-----------------------
public static class EnumExtensions
{
    public static int ToInt<T>(this T source) where T : Enum
    {
        return (int) (IConvertible) source;
    }
}
DateTime.Now.DayOfWeek.ToInt();
Console.WriteLine(DayOfWeek.Monday.ToInt()); // outputs 1
-----------------------
public static class EnumExtensions
{
    public static int ToInt<T>(this T source) where T : Enum
    {
        return (int) (IConvertible) source;
    }
}
DateTime.Now.DayOfWeek.ToInt();
Console.WriteLine(DayOfWeek.Monday.ToInt()); // outputs 1
-----------------------
DayOfWeek dayOfWeek = DateTime.Now.DayOfWeek;
object val = Convert.ChangeType(dayOfWeek, dayOfWeek.GetTypeCode());

Split days of the week string MTWTHFSSU using PREG_SPLIT

$days='MTWTHFSSU';
$splitdays = preg_split('/(.H|.U?)/',$days,null,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
print_r($splitdays);
preg_split('/(.[HU]?)/',$days,null,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE)
-----------------------
$days='MTWTHFSSU';
$splitdays = preg_split('/(.H|.U?)/',$days,null,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
print_r($splitdays);
preg_split('/(.[HU]?)/',$days,null,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE)
-----------------------
TH|SU|[MTWFS]
$days = "MTWTHFSSU";
$pattern = "/TH|SU|[MTWFS]/";
preg_match_all($pattern, $days, $matches);
print_r($matches[0]);
Array
(
    [0] => M
    [1] => T
    [2] => W
    [3] => TH
    [4] => F
    [5] => S
    [6] => SU
)
-----------------------
TH|SU|[MTWFS]
$days = "MTWTHFSSU";
$pattern = "/TH|SU|[MTWFS]/";
preg_match_all($pattern, $days, $matches);
print_r($matches[0]);
Array
(
    [0] => M
    [1] => T
    [2] => W
    [3] => TH
    [4] => F
    [5] => S
    [6] => SU
)
-----------------------
TH|SU|[MTWFS]
$days = "MTWTHFSSU";
$pattern = "/TH|SU|[MTWFS]/";
preg_match_all($pattern, $days, $matches);
print_r($matches[0]);
Array
(
    [0] => M
    [1] => T
    [2] => W
    [3] => TH
    [4] => F
    [5] => S
    [6] => SU
)

Use an integer field to store the selectged days with bitwise op

class DaysOfWeekType extends AbstractType
{
    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'choices' => [
                'Monday' => 1,
                'Tuesday' => 2,
                ...
            ],
        ]);
    }

    public function getParent(): string
    {
        return ChoiceType::class;
    }
}

Can anyone explain to me this line of code in JavaScript?

console.log(returnDay(2)); //gives Tuesday
console.log(returnDay(7)); //gives Sunday
console.log(returnDay(0)); //gives null

How to get current date and time in swift?

let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day
let date = Date()
print(Calendar.current.isDateInToday(date))
let date = Date()
print(Calendar.current.isDateInTomorrow(date))
let date = Date()
print(Calendar.current.isDateInYesterday(date))
let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)
-----------------------
let date = Date()
let calendar = Calendar.current
let dateComponents = calendar.dateComponents(in: calendar.timeZone from: date)
let year = dateComponents.year
-----------------------
let date = Date()
let calendar = Calendar.current
let dateComponents = calendar.dateComponents(in: calendar.timeZone from: date)
let year = dateComponents.year
-----------------------
let date = Date()
let calendar = Calendar.current
let dateComponents = calendar.dateComponents(in: calendar.timeZone from: date)
let year = dateComponents.year

Is there an efficient way to store Firebase data in an arraylist and then read it?

valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        listData.clear();
        for (DataSnapshot childSnapshot dataSnapshot.getChildren()) {
            Data data = childSnapshot.getValue(Data.class);
            listData.add(data);
        }
        buildRecycler();
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
        throw databaseError.toException(); // never ignore errors
    }
};

mDbRef.addValueEventListener(valueEventListener);

COMMUNITY DISCUSSIONS

Top Trending Discussions on Sunday
  • How to generate random names on particular days in Java?
  • Pandas Filter dataframe according to working days
  • Move 2nd level sub-array to the top of the 1st level multidimentional array based on value of the sub-array
  • How to select records from January 1, 2021 to last week
  • Get the number of the current weekday in ASP.NET Core
  • Split days of the week string MTWTHFSSU using PREG_SPLIT
  • Use an integer field to store the selectged days with bitwise op
  • Can anyone explain to me this line of code in JavaScript?
  • How to get last closing price of a stock in google finance (In a non-trading day)
  • How to get current date and time in swift?
Top Trending Discussions on Sunday

QUESTION

How to generate random names on particular days in Java?

Asked 2021-Jun-15 at 12:49

Here is my program which generates random name:

 String[] names = new String[]{"one","two","three","four","five"};
 Random rd = new Random();
 int x = rd.nextInt(names.length);

I need it to generate the names based on last weekend check, if the generated name matches with last weekend's generated name then the program to run again to generate different name. Ex: If "one" is generated on Saturday and "two" is generated on Sunday, then next week these two should be excluded from generation. How can i make that check in Java?

ANSWER

Answered 2021-Jun-10 at 14:04

You could do this by running a while loop until the generated string does not match your unwanted strings.

For example:

String[] names = new String[]{"one", "two", "three", "four", "five"};
String[] lastWeekend = new String[]{"one", "three"}; // you should get these from somewhere else

Random rd = new Random();

int x = rd.nextInt(names.length);

// using a list for convenience
while(Arrays.asList(lastWeekend).contains(names[x]))
{
    x = rd.nextInt(names.length);
}

// names[x] will now be "two", "four" or "five"

Source https://stackoverflow.com/questions/67922460

QUESTION

Pandas Filter dataframe according to working days

Asked 2021-Jun-15 at 05:26

I want to filter a df with respect to working days.The df is:

name     date
aaa    12/06/2021
bbb    11/06/2021
ccc    10/06/2021
zzz    15/06/2021
ddd    13/06/2021
eee    10/05/2021
fff    01/06/2021
ggg    10/05/2021
hhh    13/06/2021
iii    14/06/2021
nnn    15/06/2021
jjj    15/06/2021

Now for everday process i want all the rows before two working days that means 13/06/2021 will not be included as it was a Sunday.I used

new_date = dt.date.today()-pd.Timedelta(2, unit='d')
new_date = pd.to_datetime(new_date)
new_df = df[df['date'] < new_date]

Output should be

name     date
aaa    12/06/2021
bbb    11/06/2021
ccc    10/06/2021
eee    10/05/2021
fff    01/06/2021
ggg    10/05/2021

but it is giving me sunday also ie 13/06/2021.Can anyone help me out here please

ANSWER

Answered 2021-Jun-15 at 05:26

If need exlude only Sundays use offsets.CustomBusinessDay:

df['date'] = pd.to_datetime(df['date'], dayfirst=True)

offset = pd.offsets.CustomBusinessDay(2, weekmask='Mon Tue Wed Thu Fri Sat')
new_date = pd.to_datetime('today').normalize() - offset
print (new_date)
2021-06-12 00:00:00

new_df = df[df['date'] <= new_date]
print (new_df)
  name       date
0  aaa 2021-06-12
1  bbb 2021-06-11
2  ccc 2021-06-10
5  eee 2021-05-10
6  fff 2021-06-01
7  ggg 2021-05-10

Source https://stackoverflow.com/questions/67980115

QUESTION

Move 2nd level sub-array to the top of the 1st level multidimentional array based on value of the sub-array

Asked 2021-Jun-14 at 21:35

I'm looping through a multidimensional array and am left with some values.

This is the complete PHP code.


<?php 
/**
 * Each designer is required 3x per week, 
 * add their name 3 times to allow for the count.
 * 
 * [array_pop]  removes the designer from the sub-array
 * u[sort($designers, "sortByTotalItems")] then moves the designers with more names remaining to the top of the list
 *
 * @var [type]
 */
$designers = array(
    [ "Aaron Summers", "Aaron Summers", "Aaron Summers" ],
    [ "Adam Smart", "Adam Smart", "Adam Smart" ],
    [ "Andrew Montgomery", "Andrew Montgomery", "Andrew Montgomery" ],
    [ "Dave Robertson", "Dave Robertson", "Dave Robertson" ],
    [ "Holly Colby", "Holly Colby", "Holly Colby" ],
    [ "Karen Fok", "Karen Fok", "Karen Fok" ],
    [ "Kieran Lintott", "Kieran Lintott", "Kieran Lintott" ],
    [ "Rebecca Roffey", "Rebecca Roffey", "Rebecca Roffey" ],
    [ "Sonia Tam", "Sonia Tam", "Sonia Tam" ],
    [ "Steffi Wallace", "Steffi Wallace", "Steffi Wallace" ],
    [ "Taz Patel", "Taz Patel", "Taz Patel" ]
);
/**
 * Store the original designers to reset them once empty
 *
 * @var [type]
 */
$designers_bak = $designers;
/**
 * Generate an array of string dates between 2 dates
 *
 * @param string $start Start date
 * @param string $end End date
 * @param string $format Output format (Default: Y-m-d)
 *
 * @return array
 */
function getDatesFromRange( $start, $end ) {
    $array = array();
    $interval = new DateInterval('P1D');

    $realEnd = new DateTime($end);
    $realEnd->add($interval);

    $period = new DatePeriod(new DateTime($start), $interval, $realEnd);
    
    foreach($period as $date) { 
        $dayOfWeek = $date->format('l');
        if ( $dayOfWeek != 'Saturday' && $dayOfWeek != 'Sunday' ) {
            $array[] = $date->format('Y-m-d'); 
        }
    }

    return $array;
}
/**
 * Sort the array into sub-arrays that contain the most values
 * array(
 *     array('name', 'name', 'name')
 *     array('name', 'name')
 *     array('name')
 * )
 * https://stackoverflow.com/questions/7433569/php-sort-a-multidimensional-array-by-number-of-items#answer-7433753
 */
function sortByTotalItems($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return (count($a) > count($b)) ? -1 : 1;
}
/**
 * Get the total amount of days in this week 1-5
 *
 * @var [type]
 */
$days_at_work = 3;
$total_days_in_week = 5;
$assigned_total = floor(count( $designers ) * $days_at_work / $total_days_in_week);    

/**
 * Each day
 *
 * @var [type]
 */
$working_weeks = array_chunk(getDatesFromRange('09-06-2021', '09-06-2022'), $total_days_in_week);
$given_designer = array();
foreach ( $working_weeks as $working_days ) {
    /**
     * Reset the designers
     *
     * @var [type]
     */
    foreach ( $working_days as $working_day ) {

        /**
         * Randomise the designers
         *
         * @var [type]
         */
        shuffle( $designers ); 
        /**
         * Sort the shuffle, so the sub-arrays count is descending
         * array(
         *     array('name', 'name', 'name')
         *     array('name', 'name')
         *     array('name')
         * )
         *
         * @var [$designers]
         */
        $designers = array_filter(array_map('array_filter', $designers));
        usort($designers, "sortByTotalItems");



        /**
         * Add designer to the working day
         *
         * @var [type]
         */

        $forcount = ( count($designers) < $assigned_total ) ? count($designers) : $assigned_total;



        for ($d=0; $d < $forcount; $d++) {
            /**
             * Add designer to the days visit
             *
             * @var [type]
             */

            $given_designer[] = array( 
                                    "title"=> $designers[$d][0],
                                    "start"=> $working_day
                                );
            /**
             * Remove the name from the names array -1 each loop
             *
             * @var [type]
             */
            array_pop($designers[$d]);
            /**
             * remove empty arrays so we can count the remaining designers
             * If there are less than 1 weeks worth of designers, reset the variable
             */
            $current_designers = array_filter(array_map('array_filter', $designers));
            if (  count($current_designers) < $assigned_total ) {
                $designers = $designers_bak;
            }
        }

        
    }  
}
?>

Below is what I'm left with after the loops and array_pop.

Let's call this array1

<?php 
array ( 0 => array ( ),
        1 => array ( ),
        2 => array ( ),
        3 => array ( ),
        4 => array ( 0 => 'Aaron Summers', ),
        5 => array ( 0 => 'Taz Patel', ),
        6 => array ( 0 => 'Sonia Tam', ),
        7 => array ( 0 => 'Adam Smart', ),
        8 => array ( 0 => 'Andrew Montgomery', ),
    ) 
?>

I then reset the array with the original values:

Let's call this array2

<?php
array ( 0 => array ( 0 => 'Aaron Summers', 1 => 'Aaron Summers', 2 => 'Aaron Summers', ),
        1 => array ( 0 => 'Adam Smart', 1 => 'Adam Smart', 2 => 'Adam Smart', ),
        2 => array ( 0 => 'Andrew Montgomery', 1 => 'Andrew Montgomery', 2 => 'Andrew Montgomery', ),
        3 => array ( 0 => 'Dave Robertson', 1 => 'Dave Robertson', 2 => 'Dave Robertson', ),
        4 => array ( 0 => 'Holly Colby', 1 => 'Holly Colby', ),
        5 => array ( 0 => 'Karen Fok', 1 => 'Karen Fok', 2 => 'Karen Fok', ),
        6 => array ( 0 => 'Kieran Lintott', 1 => 'Kieran Lintott', 2 => 'Kieran Lintott', ),
        7 => array ( 0 => 'Rebecca Roffey', 1 => 'Rebecca Roffey', 2 => 'Rebecca Roffey', ),
        8 => array ( 0 => 'Sonia Tam', 1 => 'Sonia Tam', 2 => 'Sonia Tam', ),
        9 => array ( 0 => 'Steffi Wallace', 1 => 'Steffi Wallace', 2 => 'Steffi Wallace', ),
        10 => array ( 0 => 'Taz Patel', 1 => 'Taz Patel', 2 => 'Taz Patel', ),
    )
?>

How would I be able to re-order the items in array2 based on the people left in array1 ?

array2 is the total size of the array and the array in its original form, before I have looped through and used array_pop() to remove the name.

ANSWER

Answered 2021-Jun-09 at 18:41

This will reorder $array2 (into a new variable $final). First it assembles a simple array $people of the names, then it reassembles $array2 by prioritizing based on the $people array. Was this what you wanted to accomplish?

<?php 
$array1 = array( 0 => array ( ),
        1 => array ( ),
        2 => array ( ),
        3 => array ( ),
        4 => array ( 0 => 'Aaron Summers', ),
        5 => array ( 0 => 'Taz Patel', ),
        6 => array ( 0 => 'Sonia Tam', ),
        7 => array ( 0 => 'Adam Smart', ),
        8 => array ( 0 => 'Andrew Montgomery', ),
    ) ;
    
    $people = [];
    foreach ($array1 as $a) { 
        if(count($a)>0 && $person = $a[0]) {
            $people[]= $person;
        }
    }

$array2 =array ( 0 => array ( 0 => 'Aaron Summers', 1 => 'Aaron Summers', 2 => 'Aaron Summers', ),
        1 => array ( 0 => 'Adam Smart', 1 => 'Adam Smart', 2 => 'Adam Smart', ),
        2 => array ( 0 => 'Andrew Montgomery', 1 => 'Andrew Montgomery', 2 => 'Andrew Montgomery', ),
        3 => array ( 0 => 'Dave Robertson', 1 => 'Dave Robertson', 2 => 'Dave Robertson', ),
        4 => array ( 0 => 'Holly Colby', 1 => 'Holly Colby', ),
        5 => array ( 0 => 'Karen Fok', 1 => 'Karen Fok', 2 => 'Karen Fok', ),
        6 => array ( 0 => 'Kieran Lintott', 1 => 'Kieran Lintott', 2 => 'Kieran Lintott', ),
        7 => array ( 0 => 'Rebecca Roffey', 1 => 'Rebecca Roffey', 2 => 'Rebecca Roffey', ),
        8 => array ( 0 => 'Sonia Tam', 1 => 'Sonia Tam', 2 => 'Sonia Tam', ),
        9 => array ( 0 => 'Steffi Wallace', 1 => 'Steffi Wallace', 2 => 'Steffi Wallace', ),
        10 => array ( 0 => 'Taz Patel', 1 => 'Taz Patel', 2 => 'Taz Patel', ),
    );
   $final=[];
    foreach($array2 as $a) {
       if (in_array($a[0], $people) !==false) array_unshift($final, $a);
       else $final[]=$a;
    }
    

print_r($final);
?>

Output:

Array
(
    [0] => Array
        (
            [0] => Taz Patel
            [1] => Taz Patel
            [2] => Taz Patel
        )

    [1] => Array
        (
            [0] => Sonia Tam
            [1] => Sonia Tam
            [2] => Sonia Tam
        )

    [2] => Array
        (
            [0] => Andrew Montgomery
            [1] => Andrew Montgomery
            [2] => Andrew Montgomery
        )

    [3] => Array
        (
            [0] => Adam Smart
            [1] => Adam Smart
            [2] => Adam Smart
        )

    [4] => Array
        (
            [0] => Aaron Summers
            [1] => Aaron Summers
            [2] => Aaron Summers
        )

    [5] => Array
        (
            [0] => Dave Robertson
            [1] => Dave Robertson
            [2] => Dave Robertson
        )

    [6] => Array
        (
            [0] => Holly Colby
            [1] => Holly Colby
        )

    [7] => Array
        (
            [0] => Karen Fok
            [1] => Karen Fok
            [2] => Karen Fok
        )

    [8] => Array
        (
            [0] => Kieran Lintott
            [1] => Kieran Lintott
            [2] => Kieran Lintott
        )

    [9] => Array
        (
            [0] => Rebecca Roffey
            [1] => Rebecca Roffey
            [2] => Rebecca Roffey
        )

    [10] => Array
        (
            [0] => Steffi Wallace
            [1] => Steffi Wallace
            [2] => Steffi Wallace
        )

)

https://www.tehplayground.com/zkrdHhL52a1ihqMY

Source https://stackoverflow.com/questions/67909656

QUESTION

How to select records from January 1, 2021 to last week

Asked 2021-Jun-14 at 20:03

I was wondering how to make a query where I can select data from Jan 1, 21 to last week. I tried to put it in the date filter like this:

where start_date between TO_DATE('2021-01-01', 'yyyy-mm-dd') 
                     and TO_DATE('2021-06-13', 'yyyy-mm-dd')

but I would have to manually go in every week to change the end date, I was wondering if there is a more efficient way to select for data up until last week (meaning data until Sunday) from today's week, so that even if I run the query two days from today, I only get data from Jan 1 to this past Sunday?

ANSWER

Answered 2021-Jun-14 at 19:35

You can use below where clause -

WHERE start_date BETWEEN TO_DATE('2021-01-01', 'yyyy-mm-dd') AND (TRUNC(SYSDATE) - TO_CHAR(SYSDATE, 'd'));

Source https://stackoverflow.com/questions/67976090

QUESTION

Get the number of the current weekday in ASP.NET Core

Asked 2021-Jun-14 at 15:26

I need to get the current weekday number of the current week.

If I use DateTime.Now.DayOfWeek I get Monday, but it would be much easier to work with if I get 1 for Monday, 7 for Sunday etc. Thanks beforehand!

ANSWER

Answered 2021-Jun-14 at 15:22

You can use this:

day1 = (int)DateTime.Now.DayOfWeek;

Source https://stackoverflow.com/questions/67971460

QUESTION

Split days of the week string MTWTHFSSU using PREG_SPLIT

Asked 2021-Jun-14 at 10:15

I want to split the text 'MTWTHFSSU' days of the week and store it in an array.

So far I am using this code using preg_split and REGEX.

$splitdays = preg_split('/(.H?)/',$days,null,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
print_r($splitdays);

array[0=>M, 1 => T, 2 => W, 3 => TH, 4 => F, 5 => S, 6 => S, 7 => U]
//this is my output
//if i change (.U) i will get correct SUNDAY = 'SU' but TH will be  => T, => H

ANSWER

Answered 2021-Jun-14 at 07:56

This should do the trick

$days='MTWTHFSSU';
$splitdays = preg_split('/(.H|.U?)/',$days,null,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
print_r($splitdays);

@anubhava's more concise comment works as well

preg_split('/(.[HU]?)/',$days,null,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE)

Source https://stackoverflow.com/questions/67966581

QUESTION

Use an integer field to store the selectged days with bitwise op

Asked 2021-Jun-14 at 08:52

I'm writing a form which contains all days of the week, but theses days are save in an int field $days. I'm using bitwise-op to display the selected days.

{% if (day.days b-and 1) == 1 %}
    {{ "sunday" |trans }}
{% endif %}
{% if (day.days b-and 2) == 2 %}
    {{ "monday" |trans }}
{% endif %}
....

I don't know how to do to display the checkbox array and convert it into an int and the opposite.

Here is a part of the formtype

    $informations = $builder->create('information', FormType::class, [
        'label'=>'Information',
        'inherit_data' => true,
        'label_attr' => ['class'=>'catlabel']])
        ->add('categoryQualityView', ChoiceType::class, [
            'required' => true,
            'label' => 'viewQuality',
            'choices' => PlaceRepository::$categoriesRates,
            'attr' => [
                'class' => 'selectpicker',
            ],
        ])
        ->add('categoryGastronomy', ChoiceType::class, [
            'label' => 'Gastronomy',
            'required' => true,
            'choices' => PlaceRepository::$categoriesGastronomy,
            'attr' => [
                'class' => 'selectpicker',
            ],
        ])
        ->add('price', MoneyType::class, [
            'required' => false,
            'label' => 'Price',
        ])
        ->add('days', IntegerType::class, [
            'required' => false,
            'label' => 'Days',
        ])
        ->add('description', TextType::class, [
            'required' => false,
            'label' => 'Description',
        ])
        ;

ANSWER

Answered 2021-Jun-14 at 08:52

For your case you can create a custom "Form Field Type" (and maybe if needed a custom Data Transformer) and customize also the form template as described in the docs.

For example:

class DaysOfWeekType extends AbstractType
{
    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'choices' => [
                'Monday' => 1,
                'Tuesday' => 2,
                ...
            ],
        ]);
    }

    public function getParent(): string
    {
        return ChoiceType::class;
    }
}

Source https://stackoverflow.com/questions/67967217

QUESTION

Can anyone explain to me this line of code in JavaScript?

Asked 2021-Jun-14 at 07:09
let days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];

function returnDay(num) {
  if (num < 1 || num > 7) {
    return null;
  } else {
    return days[num - 1];
  }
}

Could anybody explain to me the line of code:

return days[num - 1];

ANSWER

Answered 2021-Jun-14 at 06:46

Well it's a function that returns the name of day when you pass the number. So if you pass 1 as parameter to your function returnDay, it will return Monday, if 2 it will give you Tuesday.

console.log(returnDay(2)); //gives Tuesday
console.log(returnDay(7)); //gives Sunday
console.log(returnDay(0)); //gives null

Source https://stackoverflow.com/questions/67965820

QUESTION

How to get last closing price of a stock in google finance (In a non-trading day)

Asked 2021-Jun-14 at 06:33

I tried using

=INDEX(GOOGLEFINANCE("NASDAQ:MSFT","price",TODAY(), 2),2,2)

And saw that on some days (e.g. 12/6/2021, a Saturday) the function failed to return value. I assume that it is because there was no trading on that day.

Is there a way for me to pick the last value of a stock prior to that day? (e.g. If I calculate on a Saturday or on a Sunday with an American stock I would get Friday's value, Thursday for an Israeli stock etc.)

ANSWER

Answered 2021-Jun-14 at 06:33

I am not aware of a way for GOOGLEFINANCE to automatically adjust for no trading days.

One way to do it is to get the "price" data for the last 7 days (to be safe) and then query that data to get the "price" value next to the max date.

This formula works for me: =INDEX(QUERY(GOOGLEFINANCE("NASDAQ:MSFT","price", TODAY()-7, TODAY()),"select Col1, Col2 order by Col2 desc",1), 2, 2)

Source https://stackoverflow.com/questions/67965460

QUESTION

How to get current date and time in swift?

Asked 2021-Jun-13 at 15:58

i want to this type result..

Example ->

Current -> 07 June 2019, Monday

Current Day of Weak -> Sunday

Current Today's Date -> 26

Current Month of year -> June

Current Year -> 2021

ANSWER

Answered 2021-Jun-13 at 15:48

I Hope This Article Will Help you. And other people.

Get Year From Date In Swift

let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"
let yearString = dateFormatter.string(from: date)

This will print a 4 digit year.

If you just want two digits, use yy instead of yyyy.

To get the year as an Int from a date, use calendar.dateComponents:

let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let year = components.year

Get Month From Date In Swift

To get the name of the month, use DateFormatter:

let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"
let monthString = dateFormatter.string(from: date)

This will give you a string with the full month name.

To get the month as an Int, use calendar.dateComponents:

let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
let month = components.month

Get Day Of The Week From Date In Swift

To get the day of the week from a date in Swift, use DateFormatter:

let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayOfTheWeekString = dateFormatter.string(from: date)

This will give you the full name of the day of the week, such as “Monday”.

If you want to get the number 1-7, with 1 representing Sunday and 7 representing Saturday, use dateComponents:

let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: date)
let dayOfWeek = components.weekday

Get Day Of The Month

To get the day of the month, you can use dateComponents:

let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: date)
let dayOfMonth = components.day

Check If From Today

Calendar has the method func isDateInToday(_ date: Date) -> Bool we can utilize.

let date = Date()
print(Calendar.current.isDateInToday(date))

Check If From Tomorrow

Calendar has the method func isDateInTomorrow(_ date: Date) -> Bool we can utilize.

let date = Date()
print(Calendar.current.isDateInTomorrow(date))

This will print false, since Date() creates a date that is in this instant and therefore today.


Check If From Yesterday

Calendar has the method func isDateInYesterday(_ date: Date) -> Bool we can utilize.

let date = Date()
print(Calendar.current.isDateInYesterday(date))

Change Year, Month or Day

You can use DateComponents to change the year, month or day of any Date object. Here’s an example where we change all three:

let date = Date()
var dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: date)

dateComponents.day = 1
dateComponents.month = 2
dateComponents.year = 2000

let newDate = Calendar.current.date(from: dateComponents)

Thank you

Credits of this article... -> @Eddy_Chung

Source https://stackoverflow.com/questions/67959903

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

VULNERABILITIES

No vulnerabilities reported

INSTALL Sunday

You can use Sunday like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Sunday component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

SUPPORT

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Implement Sunday faster with kandi.

  • Use the support, quality, security, license, reuse scores and reviewed functions to confirm the fit for your project.
  • Use the, Q & A, Installation and Support guides to implement faster.

Discover Millions of Libraries and
Pre-built Use Cases on kandi